Skip to content

Commit

Permalink
Add pi *
Browse files Browse the repository at this point in the history
  • Loading branch information
rlaiola committed Apr 11, 2024
1 parent e43d6ae commit 8a5a5f2
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/db/parser/grammar_ra.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ declare module relalgAst {
relAlias: string | null,
}

interface columnAsterisk {
type: 'column',
name: '*',
relAlias: string | null
}

interface namedColumnExpr {
type: 'namedColumnExpr',
name: string,
Expand Down Expand Up @@ -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 },
Expand Down
16 changes: 16 additions & 0 deletions src/db/parser/grammar_ra.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
12 changes: 11 additions & 1 deletion src/db/translate/relalgFromAst.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down

0 comments on commit 8a5a5f2

Please sign in to comment.