Skip to content

Commit 1688c85

Browse files
Copilotmathiasrw
andcommitted
Refactor: Make GROUP_CONCAT a proper token instead of using IF in grammar
Co-authored-by: mathiasrw <1063454+mathiasrw@users.noreply.github.com>
1 parent 3ec3fea commit 1688c85

2 files changed

Lines changed: 576 additions & 583 deletions

File tree

src/alasqlparser.jison

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ DATABASE(S)? return 'DATABASE'
144144
'GO' return 'GO'
145145
'GRAPH' return 'GRAPH'
146146
'GROUP' return 'GROUP'
147+
'GROUP_CONCAT' return 'GROUP_CONCAT'
147148
'GROUPING' return 'GROUPING'
148149
'HAVING' return 'HAVING'
149150
/*'HELP' return 'HELP'*/
@@ -1416,22 +1417,10 @@ AggrValue
14161417
| Aggregator LPAR ALL Expression RPAR OverClause
14171418
{ $$ = new yy.AggrValue({aggregatorid: $1.toUpperCase(), expression: $4,
14181419
over:$6}); }
1419-
| Literal LPAR Expression GroupConcatOrderClause GroupConcatSeparatorClause RPAR
1420-
{
1421-
if($1.toUpperCase() === 'GROUP_CONCAT') {
1422-
$$ = new yy.AggrValue({aggregatorid: 'REDUCE', funcid: $1, expression: $3, order: $4, separator: $5});
1423-
} else {
1424-
throw new Error('Syntax error: ORDER BY and SEPARATOR are only supported in GROUP_CONCAT');
1425-
}
1426-
}
1427-
| Literal LPAR DISTINCT Expression GroupConcatOrderClause GroupConcatSeparatorClause RPAR
1428-
{
1429-
if($1.toUpperCase() === 'GROUP_CONCAT') {
1430-
$$ = new yy.AggrValue({aggregatorid: 'REDUCE', funcid: $1, expression: $4, distinct: true, order: $5, separator: $6});
1431-
} else {
1432-
throw new Error('Syntax error: ORDER BY and SEPARATOR are only supported in GROUP_CONCAT');
1433-
}
1434-
}
1420+
| GROUP_CONCAT LPAR Expression GroupConcatOrderClause GroupConcatSeparatorClause RPAR
1421+
{ $$ = new yy.AggrValue({aggregatorid: 'REDUCE', funcid: 'GROUP_CONCAT', expression: $3, order: $4, separator: $5}); }
1422+
| GROUP_CONCAT LPAR DISTINCT Expression GroupConcatOrderClause GroupConcatSeparatorClause RPAR
1423+
{ $$ = new yy.AggrValue({aggregatorid: 'REDUCE', funcid: 'GROUP_CONCAT', expression: $4, distinct: true, order: $5, separator: $6}); }
14351424
;
14361425

14371426
OverClause
@@ -1465,7 +1454,12 @@ GroupConcatSeparatorClause
14651454
:
14661455
{ $$ = undefined; }
14671456
| SEPARATOR STRING
1468-
{ $$ = $2.substring(1, $2.length-1); }
1457+
{
1458+
var str = $2.substring(1, $2.length-1);
1459+
// Process common escape sequences
1460+
str = str.replace(/\\n/g, '\n').replace(/\\t/g, '\t').replace(/\\r/g, '\r').replace(/\\\\/g, '\\');
1461+
$$ = str;
1462+
}
14691463
;
14701464

14711465
Aggregator
@@ -1479,6 +1473,7 @@ Aggregator
14791473
| LAST { $$ = "LAST"; }
14801474
| AGGR { $$ = "AGGR"; }
14811475
| ARRAY { $$ = "ARRAY"; }
1476+
| GROUP_CONCAT { $$ = "GROUP_CONCAT"; }
14821477
/* | REDUCE { $$ = "REDUCE"; } */
14831478
;
14841479

0 commit comments

Comments
 (0)