Skip to content

Commit e99acd5

Browse files
kyleconroyclaude
andcommitted
Fix CAST parsing to handle expression type arguments like 'Str'||'ing'
When parsing CAST(x, type) with comma syntax, check if the type string is followed by an operator (CONCAT, PLUS, MINUS) before consuming it. If so, parse it as a full expression to handle cases like: CAST(123, 'Str'||'ing') Fixes 03011_definitive_guide_to_cast/stmt36. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 7a62b45 commit e99acd5

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

parser/expression.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1557,7 +1557,9 @@ func (p *Parser) parseCast() ast.Expression {
15571557
p.nextToken()
15581558
// Type can be given as a string literal or an expression (e.g., if(cond, 'Type1', 'Type2'))
15591559
// It can also have an alias like: cast('1234', 'UInt32' AS rhs)
1560-
if p.currentIs(token.STRING) {
1560+
// For expressions like 'Str'||'ing', we need to parse the full expression
1561+
if p.currentIs(token.STRING) && !p.peekIs(token.CONCAT) && !p.peekIs(token.PLUS) && !p.peekIs(token.MINUS) {
1562+
// Simple string literal type, not part of an expression
15611563
typeStr := p.current.Value
15621564
typePos := p.current.Pos
15631565
p.nextToken()
@@ -1597,7 +1599,7 @@ func (p *Parser) parseCast() ast.Expression {
15971599
expr.Type = &ast.DataType{Position: typePos, Name: typeStr}
15981600
}
15991601
} else {
1600-
// Parse as expression for dynamic type casting
1602+
// Parse as expression for dynamic type casting or expressions like 'Str'||'ing'
16011603
expr.TypeExpr = p.parseExpression(LOWEST)
16021604
}
16031605
}
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt36": true
4-
}
5-
}
1+
{}

0 commit comments

Comments
 (0)