Skip to content

Commit 40b7213

Browse files
committed
Handle +Inf and -Inf as infinity literals in parser
Previously +Inf was being parsed as a unary plus function applied to the Inf identifier, causing array literals containing +Inf to be treated as function calls instead of literal arrays. Now +Inf and -Inf are recognized as special Float64 infinity literals.
1 parent 44a42e1 commit 40b7213

2 files changed

Lines changed: 26 additions & 13 deletions

File tree

parser/expression.go

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -984,6 +984,16 @@ func (p *Parser) parseUnaryMinus() ast.Expression {
984984
pos := p.current.Pos
985985
p.nextToken() // skip minus
986986

987+
// Handle -Inf as a special negative infinity literal
988+
if p.currentIs(token.INF) {
989+
p.nextToken() // skip INF
990+
return &ast.Literal{
991+
Position: pos,
992+
Type: ast.LiteralFloat,
993+
Value: math.Inf(-1),
994+
}
995+
}
996+
987997
// For negative number literals followed by ::, keep them together as a signed literal
988998
// This matches ClickHouse's behavior where -0::Int16 becomes CAST('-0', 'Int16')
989999
if p.currentIs(token.NUMBER) && p.peekIs(token.COLONCOLON) {
@@ -1031,11 +1041,24 @@ func (p *Parser) parseUnaryMinus() ast.Expression {
10311041
}
10321042

10331043
func (p *Parser) parseUnaryPlus() ast.Expression {
1044+
pos := p.current.Pos
1045+
p.nextToken() // skip plus
1046+
1047+
// Handle +Inf as a special positive infinity literal
1048+
if p.currentIs(token.INF) {
1049+
p.nextToken() // skip INF
1050+
return &ast.Literal{
1051+
Position: pos,
1052+
Type: ast.LiteralFloat,
1053+
Value: math.Inf(1),
1054+
}
1055+
}
1056+
1057+
// Standard unary plus handling
10341058
expr := &ast.UnaryExpr{
1035-
Position: p.current.Pos,
1059+
Position: pos,
10361060
Op: "+",
10371061
}
1038-
p.nextToken()
10391062
expr.Operand = p.parseExpression(UNARY)
10401063
return expr
10411064
}
Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt1": true,
4-
"stmt2": true,
5-
"stmt3": true,
6-
"stmt5": true,
7-
"stmt6": true,
8-
"stmt7": true,
9-
"stmt8": true
10-
}
11-
}
1+
{}

0 commit comments

Comments
 (0)