Skip to content

Commit

Permalink
Merge branch 'dbis-uibk:development' into development
Browse files Browse the repository at this point in the history
  • Loading branch information
rlaiola authored Jul 5, 2022
2 parents cdc17f5 + f73f3ed commit 70f85c0
Show file tree
Hide file tree
Showing 22 changed files with 87 additions and 32 deletions.
32 changes: 21 additions & 11 deletions src/calc2/components/editorBase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import classNames from 'classnames';
import * as CodeMirror from 'codemirror';
import 'codemirror/addon/hint/show-hint';
import { RANode, RANodeBinary, RANodeUnary } from 'db/exec/RANode';
import { parseRelalg, textFromRelalgAstRoot } from 'db/relalg';
import { executeRelalg, parseRelalg, textFromRelalgAstRoot } from 'db/relalg';
import { forEachPreOrder } from 'db/translate/utils';
import * as React from 'react';
import { findDOMNode } from 'react-dom';
Expand Down Expand Up @@ -293,6 +293,7 @@ type State = {
replSelStart: any,
replSelEnd: any,
queryResult: any,
execTime: any,
};


Expand Down Expand Up @@ -387,19 +388,22 @@ class Relation {
}

fromData(data: string[][]): void {
for (let col = 0; col < data[0].length; col++) {
if (data[0][col]) {
const attribute = new Attribute();
attribute.name = data[0][col];
attribute.type = data[1][col];
for (let row = 2; row < data.length; row++) {
if (data[row][col]) {
attribute.data.push(data[row][col]);
if(data.length > 0) {
for (let col = 0; col < data[0].length; col++) {
if (data[0][col]) {
const attribute = new Attribute();
attribute.name = data[0][col];
attribute.type = data[1][col];
for (let row = 2; row < data.length; row++) {
if (data[row][col]) {
attribute.data.push(data[row][col]);
}
}
this.attributes.push(attribute);
}
this.attributes.push(attribute);
}
}

}

fromCSV(csv: string, delimiter = ';') {
Expand Down Expand Up @@ -543,6 +547,7 @@ export class EditorBase extends React.Component<Props, State> {
replSelStart: null,
replSelEnd: null,
queryResult: null,
execTime: null,
};
this.toggle = this.toggle.bind(this);
this.inlineRelationEditorOk = this.inlineRelationEditorOk.bind(this);
Expand All @@ -568,6 +573,7 @@ export class EditorBase extends React.Component<Props, State> {


private getInlineRelationData(): string[][] {
if(this.hotTableSettings.datta) { return this.hotTableSettings.datta; }
return this.hotTableSettings.data;
}

Expand Down Expand Up @@ -691,6 +697,7 @@ export class EditorBase extends React.Component<Props, State> {
execSuccessful,
isExecutionDisabled,
execResult,
execTime,
queryResult,
} = this.state;
const {
Expand Down Expand Up @@ -802,6 +809,7 @@ export class EditorBase extends React.Component<Props, State> {
</div>
</div>
<div className="exec-result">{execResult}</div>
<div>{execTime}</div>
<Modal isOpen={this.state.modal} toggle={this.toggle} className="showOnSM">
<ModalHeader toggle={this.toggle}>{t('calc.result.modal.title')}</ModalHeader>
<ModalBody>
Expand Down Expand Up @@ -1289,11 +1297,13 @@ export class EditorBase extends React.Component<Props, State> {
}
this.clearExecutionAlerts();
try {
const start = Date.now();
const { result } = this.props.execFunction(this, query, offset);
const end = Date.now() - start;
this.getResultForCsv(result.props.root);

this.setState({
execResult: result,
execTime: end,
});
const event = new CustomEvent(eventExecSuccessfulName, {
'detail': {
Expand Down
3 changes: 1 addition & 2 deletions src/calc2/components/editorRelalg.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export class EditorRelalg extends React.Component<Props, State> {
<Result
root={root}
numTreeLabelColors={NUM_TREE_LABEL_COLORS}
execTime={self.state.execTime == null ? 0 : self.state.execTime}
/>
),
};
Expand Down Expand Up @@ -127,9 +128,7 @@ export class EditorRelalg extends React.Component<Props, State> {
// replace text (text-magic)
if (editor.getDoc().somethingSelected() === false) {
const cursorOld: { line: number, ch: number } = editor.getDoc().getCursor();

const { query, cursor } = queryWithReplacedOperatorsFromAst(text, ast.operatorPositions, { line: cursorOld.line + 1, column: cursorOld.ch + 1 }, autoreplaceOperatorsMode);

if (query !== text) {
editor.setValue(query);
editor.getDoc().setCursor({ line: cursor.line - 1, ch: cursor.column - 1 });
Expand Down
4 changes: 2 additions & 2 deletions src/calc2/components/editorSql.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class EditorSql extends React.Component<Props> {
render() {
const autoreplaceOperatorsMode: 'none' | 'header' | 'plain2math' | 'math2plain' = 'none';
const { group } = this.props;

// TODO: move to state
const relations: { [name: string]: Relation } = {};
group.tables.forEach(table => {
Expand Down Expand Up @@ -77,7 +77,6 @@ export class EditorSql extends React.Component<Props> {

const root = relalgFromSQLAstRoot(ast, relations);
if (root) {
//console.log('Time: ' + (d2.getMilliseconds() - d.getMilliseconds()));
root.check();

self.historyAddEntry(text);
Expand All @@ -88,6 +87,7 @@ export class EditorSql extends React.Component<Props> {
<Result
root={root}
numTreeLabelColors={NUM_TREE_LABEL_COLORS}
execTime={self.state.execTime == null ? 0 : self.state.execTime}
/>
),
};
Expand Down
1 change: 1 addition & 0 deletions src/calc2/components/raTree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export class RaTree extends React.Component<Props> {
? <pre>{n.getMetaData('inlineRelationDefinition')}</pre>
: null
}

</div>
);
};
Expand Down
9 changes: 8 additions & 1 deletion src/calc2/components/result.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { RANode } from 'db/exec/RANode';
import { Table } from 'db/exec/Table';
import memoize from 'memoize-one';
import * as React from 'react';
import {t} from "calc2/i18n";

require('./result.scss');

Expand All @@ -18,11 +19,13 @@ const maxLinesPerPage = 10;
type Props = {
root: RANode,
numTreeLabelColors: number,
execTime?: any
};

type State = {
result: null | Table,
activeNode: RANode,
execTime: any
};

export class Result extends React.Component<Props, State> {
Expand All @@ -45,6 +48,7 @@ export class Result extends React.Component<Props, State> {
this.state = {
activeNode: props.root,
result: null,
execTime: null
};

this.setActiveNode = this.setActiveNode.bind(this);
Expand All @@ -57,7 +61,7 @@ export class Result extends React.Component<Props, State> {
}

render() {
const { root, numTreeLabelColors } = this.props;
const { root, numTreeLabelColors, execTime } = this.props;
const { activeNode } = this.state;

const result = this.result(activeNode);
Expand All @@ -81,6 +85,9 @@ export class Result extends React.Component<Props, State> {
__html: activeNode.getFormulaHtml(true, false),
}}
/>
<div>
{t('calc.result.exec.time')} {execTime} ms
</div>
<div className="result-table">
{result
? (
Expand Down
11 changes: 11 additions & 0 deletions src/calc2/store/groups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,17 @@ export function loadStaticGroups() {
source: 'gist',
id: 'c306ecf21c6e6d175508d3ac6b4355e7',
},
{
maintainerGroup: 'OTH Regensburg',
maintainer: '<a href="https://gist.github.com/jschildgen">Johannes Schildgen</a>',

source: 'gist',
id: 'd67f16874b528abc6e6c88d07a50b2dc',
},




];

let first: boolean = true;
Expand Down
18 changes: 18 additions & 0 deletions src/calc2/views/landing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,24 @@ export class Landing extends React.Component {

<h2 id="changelog">Changelog</h2>
<ul>
<li>0.24 - Released 17.06.2022
<ul>
<li>Fixed problem when replacing multiple operators | #174</li>
</ul>
</li>
<li>0.23 - Released 16.06.2022
<ul>
<li>Added dataset from OTH Regensburg - Webshop</li>
<li>Fixed problem with inline relation editor | #173</li>
</ul>
</li>
<li>0.22 - Released 01.06.2022
<ul>
<li>execution time has been added</li>
</ul>
</li>


<li>0.21 - Released 26.05.2022
<ul>
<li>added option of downloading the result (jpg or csv)</li>
Expand Down
3 changes: 0 additions & 3 deletions src/db/exec/RANode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@ export abstract class RANode {
_resultNumRows: number = -1;
_wrappedInParentheses: boolean = false;
_warnings: Warning[] = [];
_executionTime: any;

// TODO: add execution time!

constructor(functionName = '') {
this._functionName = functionName;
Expand Down
1 change: 0 additions & 1 deletion src/db/exec/Selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ export class Selection extends RANodeUnary {

getResult(session?: Session) {
session = this._returnOrCreateSession(session);

const res = new Table();
const org = this.getChild().getResult(session);
res.setSchema(org.getSchema());
Expand Down
6 changes: 6 additions & 0 deletions src/db/exec/joins/Join.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { Data, Schema } from '../Schema';
import { Table } from '../Table';
import * as ValueExpr from '../ValueExpr';
import { bool } from 'prop-types';
import Handsontable from "handsontable";
//import Date = Handsontable._editors.Date;


export type JoinCondition = {
Expand Down Expand Up @@ -44,6 +46,8 @@ export abstract class Join extends RANodeBinary {
_schema: Schema | null = null;
_rowCreatorMatched: null | ((rowA: Data[], rowB: Data[]) => Data[]) = null;
_rowCreatorNotMatched: null | ((rowA: Data[], rowB: Data[]) => Data[]) = null; // used for outer joins
_executionStart: any;
_executedEnd: any;

constructor(
child: RANode,
Expand Down Expand Up @@ -134,6 +138,7 @@ export abstract class Join extends RANodeBinary {

const resultTable = new Table();
resultTable.setSchema(this.getSchema());
this._executionStart = Date.now();

Join.calcNestedLoopJoin(
session,
Expand All @@ -153,6 +158,7 @@ export abstract class Join extends RANodeBinary {
}

this.setResultNumRows(resultTable.getNumRows());
this._executedEnd = Date.now() - this._executionStart;
return resultTable;
}

Expand Down
4 changes: 1 addition & 3 deletions src/db/relalg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,10 @@ export function queryWithReplacedOperatorsFromAst(
'fullOuterJoinOperator': '⟗',
},
};

for (let i = operatorPositions.length - 1; i >= 0; i--) {
const op = operatorPositions[i];
const location = op.location; // = location without surrounding whitespace
const left = query.substr(0, location.start.offset);
const left = query.substr(0, location.start.offset - 1); // fixed offset | #174
const right = query.substring(location.end.offset);
const newOperator = (newOperators[mode] as any)[op.name]; // TODO: fix typings
const oldOperator = query.substring(location.start.offset, location.end.offset);
Expand Down Expand Up @@ -121,7 +120,6 @@ export function queryWithReplacedOperatorsFromAst(
cursor.line -= location.end.line - location.start.line;
}
}

// update query
query = left + newOperator + right;
}
Expand Down
1 change: 0 additions & 1 deletion src/db/tests/var_replacer_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,6 @@ QUnit.test('extract operators with the tracer', function (assert) {
const ast = relalgjs.parseRelalg(query);

assert.equal(ast.operatorPositions.length, 2);
console.log(ast.operatorPositions);
assert.deepEqual(ast.operatorPositions, [
{
type: 'nodeInfo',
Expand Down
1 change: 1 addition & 0 deletions src/db/translate/relalgFromAst.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export function relalgFromSQLAstRoot(astRoot: sqlAst.rootSql | any, relations: {

function rec(nRaw: sqlAst.astNode | any): RANode {
let node: RANode | null = null;

switch (nRaw.type) {
case 'relation':
{
Expand Down
5 changes: 3 additions & 2 deletions src/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -215,5 +215,6 @@
"calc.editors.ra.inline-editor.row-name": "Name",
"calc.editors.ra.inline-editor.row-type": "Typ",
"calc.editors.ra.inline-editor.input-relation-name": "Relations Name",
"calc.navigation.imprint": "Impressum"
}
"calc.navigation.imprint": "Impressum",
"calc.result.exec.time": "Ausführungszeit: "
}
1 change: 1 addition & 0 deletions src/locales/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,4 +217,5 @@ export const langDE: Partial<typeof langEN> = {
'calc.editors.ra.inline-editor.row-name': 'Name',
'calc.editors.ra.inline-editor.row-type': 'Typ',
'calc.editors.ra.inline-editor.input-relation-name': 'Relations Name',
'calc.result.exec.time': 'Ausführungszeit: ',
};
5 changes: 3 additions & 2 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -214,5 +214,6 @@
"calc.editors.ra.inline-editor.row-name": "Name",
"calc.editors.ra.inline-editor.row-type": "Type",
"calc.editors.ra.inline-editor.input-relation-name": "Relation Name",
"calc.navigation.imprint": "Imprint"
}
"calc.navigation.imprint": "Imprint",
"calc.result.exec.time": "Execution time: "
}
1 change: 1 addition & 0 deletions src/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,4 +288,5 @@ export const langEN = {
'calc.editors.ra.inline-editor.row-name': 'Name',
'calc.editors.ra.inline-editor.row-type': 'Type',
'calc.editors.ra.inline-editor.input-relation-name': 'Relation Name',
'calc.result.exec.time': 'Execution Time: ',
};
3 changes: 2 additions & 1 deletion src/locales/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -214,5 +214,6 @@
"calc.editors.ra.inline-editor.row-name": "Nombre",
"calc.editors.ra.inline-editor.row-type": "Escriba",
"calc.editors.ra.inline-editor.input-relation-name": "Nombre de la relación",
"calc.navigation.imprint": "Imprimir"
"calc.navigation.imprint": "Imprimir",
"calc.result.exec.time": "Tiempo de consulta"
}
1 change: 1 addition & 0 deletions src/locales/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,4 +294,5 @@ export const langES: Partial<typeof langEN> = {
'calc.editors.ra.inline-editor.row-name': 'Nombre',
'calc.editors.ra.inline-editor.row-type': 'Escriba',
'calc.editors.ra.inline-editor.input-relation-name': 'Nombre de la relación',
'calc.result.exec.time': 'Tiempo de consulta',
};
5 changes: 3 additions & 2 deletions src/locales/kr.json
Original file line number Diff line number Diff line change
Expand Up @@ -213,5 +213,6 @@
"calc.editors.ra.inline-editor.row-name": "Name",
"calc.editors.ra.inline-editor.row-type": "Type",
"calc.editors.ra.inline-editor.input-relation-name": "Relation Name",
"calc.navigation.imprint": "Imprint"
}
"calc.navigation.imprint": "Imprint",
"calc.result.exec.time": "Execution time:"
}
1 change: 1 addition & 0 deletions src/locales/kr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,4 +240,5 @@ export const langKR = {
'calc.editors.ra.inline-editor.row-type': 'Type',
'calc.editors.ra.inline-editor.button-ok': 'Ok',
'calc.editors.ra.inline-editor.input-relation-name': 'Relation Name',
'calc.result.exec.time': 'Execution time:'
};
Loading

0 comments on commit 70f85c0

Please sign in to comment.