diff --git a/src/db/parser/grammar_ra.d.ts b/src/db/parser/grammar_ra.d.ts index e0bb5b61..b83a6f7d 100644 --- a/src/db/parser/grammar_ra.d.ts +++ b/src/db/parser/grammar_ra.d.ts @@ -79,6 +79,12 @@ declare module relalgAst { relAlias: string | null, } + interface columnAsterisk { + type: 'column', + name: '*', + relAlias: string | null + } + interface namedColumnExpr { type: 'namedColumnExpr', name: string, @@ -139,7 +145,7 @@ declare module relalgAst { child: relalgOperation, child2?: undefined, assignments?: undefined, - arg: (namedColumnExpr | columnName)[], + arg: (namedColumnExpr | columnName | columnAsterisk)[], wrappedInParentheses?: boolean, metaData?: { [key: string]: any }, diff --git a/src/db/parser/grammar_ra.pegjs b/src/db/parser/grammar_ra.pegjs index 4df081b3..67e830cf 100644 --- a/src/db/parser/grammar_ra.pegjs +++ b/src/db/parser/grammar_ra.pegjs @@ -254,6 +254,17 @@ columnName relAlias: relAlias }; } + +columnAsterisk += relAlias:(relationName '.')? '*' + { + return { + type: 'column', + name: '*', + relAlias: relAlias ? relAlias[0] : null + }; + } + / relAlias:(relationName '.')? '[' index:$[0-9]+ ']' { if(relAlias != null) @@ -442,6 +453,11 @@ namedColumnExpr { return a; } +/ col:columnAsterisk + { + col.alias = null; + return col; + } // list of columns (kd.id, kd.name, test) e.g. for the projection listOfNamedColumnExpressions diff --git a/src/db/tests/translate_tests_ra.ts b/src/db/tests/translate_tests_ra.ts index 38aca02a..a7ddc96c 100644 --- a/src/db/tests/translate_tests_ra.ts +++ b/src/db/tests/translate_tests_ra.ts @@ -254,6 +254,24 @@ QUnit.test('test selection with xor', function (assert) { assert.deepEqual(root.getResult(), ref.getResult()); }); +QUnit.test('test projection[*](R)', function (assert) { + const relations = getTestRelations(); + const query = 'pi * (R)'; + const root = exec_ra(query, relations); + + const ref = exec_ra(`{ + R.a, R.b, R.c + + 1, 'a', 'd' + 3, 'c', 'c' + 4, 'd', 'f' + 5, 'd', 'b' + 6, 'e', 'f' + }`, relations); + + assert.deepEqual(root.getResult(), ref.getResult()); +}); + QUnit.test('test projection[a, b](R)', function (assert) { const relations = getTestRelations(); const query = 'pi a, b (R)'; @@ -301,6 +319,22 @@ QUnit.test('test projection[b, a, a, b](R)', function (assert) { } }); +QUnit.test('test (pi * (R)) inner join [R.b = S.b] (pi * (S))', function (assert) { + const relations = getTestRelations(); + const root = exec_ra('(R) inner join R.b = S.b (S)', relations); + const ref = exec_ra(`{ + R.a:number, R.b:string, R.c:string, S.b:string, S.d:number + + 1, 'a', 'd', 'a', 100 + 3, 'c', 'c', 'c', 400 + 4, 'd', 'f', 'd', 200 + 5, 'd', 'b', 'd', 200 + 6, 'e', 'f', 'e', 150 + }`, relations); + + assert.deepEqual(root.getResult(), ref.getResult()); +}); + QUnit.test('test (R) inner join [R.b = S.b] join (S)', function (assert) { const relations = getTestRelations(); const root = exec_ra('(R) inner join R.b = S.b (S)', relations); diff --git a/src/db/translate/relalgFromAst.ts b/src/db/translate/relalgFromAst.ts index a9c412ad..d5315eec 100644 --- a/src/db/translate/relalgFromAst.ts +++ b/src/db/translate/relalgFromAst.ts @@ -526,7 +526,17 @@ export function relalgFromRelalgAstNode(astNode: relalgAst.relalgOperation, rela for (let i = 0; i < n.arg.length; i++) { const el = n.arg[i]; - if (el.type === 'columnName') { + if (el.type === 'column' && + el.name === '*' && + el.relAlias === null) { + // project all columns + let cols = child.getSchema(); + for (let i = 0; i < cols.getSize(); i++) { + // normal columns + projections.push(cols.getColumn(i)); + } + } + else if (el.type === 'columnName') { const e = el as relalgAst.columnName; projections.push(new Column(e.name, e.relAlias)); }