From 8a5a5f21c1d23c1476a91467af16a2371db88e55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodrigo=20Laiola=20Guimar=C3=A3es?= Date: Thu, 11 Apr 2024 11:15:35 -0300 Subject: [PATCH 1/2] Add pi * --- src/db/parser/grammar_ra.d.ts | 8 +++++++- src/db/parser/grammar_ra.pegjs | 16 ++++++++++++++++ src/db/translate/relalgFromAst.ts | 12 +++++++++++- 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/db/parser/grammar_ra.d.ts b/src/db/parser/grammar_ra.d.ts index 5aa1b7df..416224fd 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 5e52bdaa..0d369d29 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/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)); } From 6111b465bf17b525ea87d4e9ffd868b2b84bd429 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodrigo=20Laiola=20Guimar=C3=A3es?= Date: Thu, 11 Apr 2024 11:27:27 -0300 Subject: [PATCH 2/2] Update translate_tests_ra.ts --- src/db/tests/translate_tests_ra.ts | 34 ++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/db/tests/translate_tests_ra.ts b/src/db/tests/translate_tests_ra.ts index f2116f60..4503ea15 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);