Skip to content

Commit c424670

Browse files
committed
Allow keywords as WITH clause aliases
In scalar WITH clauses like `WITH expr AS name`, the alias can now be a keyword (e.g., `key`, `values`) in addition to regular identifiers. This matches ClickHouse's behavior. This fixes 20+ statements across multiple tests including: - 02124_encrypt_decrypt_nullable - 03254_timeseries_to_grid_aggregate_function (various) - 03205_overlay - 01930_optimize_skip_unused_shards_rewrite_in
1 parent eda6f46 commit c424670

12 files changed

Lines changed: 13 additions & 70 deletions

File tree

parser/parser.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1057,7 +1057,8 @@ func (p *Parser) parseWithClause() []ast.Expression {
10571057
// AS name is optional
10581058
if p.currentIs(token.AS) {
10591059
p.nextToken()
1060-
if p.currentIs(token.IDENT) {
1060+
// Alias can be IDENT or certain keywords (KEY, VALUES, etc.)
1061+
if p.currentIs(token.IDENT) || p.current.Token.IsKeyword() {
10611062
elem.Name = p.current.Value
10621063
p.nextToken()
10631064
}
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt67": true
4-
}
5-
}
1+
{}
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt47": true
4-
}
5-
}
1+
{}
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt46": true
4-
}
5-
}
1+
{}
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt3": true
4-
}
5-
}
1+
{}
Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt10": true,
4-
"stmt11": true,
5-
"stmt13": true,
6-
"stmt14": true,
7-
"stmt15": true,
8-
"stmt16": true,
9-
"stmt3": true,
10-
"stmt6": true,
11-
"stmt8": true,
12-
"stmt9": true
13-
}
14-
}
1+
{}
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt35": true
4-
}
5-
}
1+
{}
Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt5": true,
4-
"stmt6": true,
5-
"stmt7": true
6-
}
7-
}
1+
{}
Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
{
22
"explain_todo": {
3-
"stmt10": true,
4-
"stmt11": true,
5-
"stmt12": true,
63
"stmt2": true,
7-
"stmt3": true,
8-
"stmt8": true,
9-
"stmt9": true
4+
"stmt3": true
105
}
116
}
Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
{
22
"explain_todo": {
3-
"stmt10": true,
4-
"stmt11": true,
5-
"stmt12": true,
6-
"stmt13": true,
73
"stmt2": true,
8-
"stmt3": true,
9-
"stmt8": true,
10-
"stmt9": true
4+
"stmt3": true
115
}
126
}

0 commit comments

Comments
 (0)