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] 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)); }