Skip to content

Commit b1e2884

Browse files
committed
Add AT TIME ZONE expression parsing
- Add AtTimeZoneCall AST type for AT TIME ZONE expressions - Add parsePostfixExpression to handle postfix operators - Support chained AT TIME ZONE expressions - Enable AtTimeZoneTests130 and Baselines130_AtTimeZoneTests130 tests
1 parent cf71f6a commit b1e2884

5 files changed

Lines changed: 55 additions & 4 deletions

File tree

ast/at_time_zone.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package ast
2+
3+
// AtTimeZoneCall represents an AT TIME ZONE expression
4+
type AtTimeZoneCall struct {
5+
DateValue ScalarExpression
6+
TimeZone ScalarExpression
7+
}
8+
9+
func (*AtTimeZoneCall) node() {}
10+
func (*AtTimeZoneCall) scalarExpression() {}

parser/marshal.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1697,6 +1697,17 @@ func scalarExpressionToJSON(expr ast.ScalarExpression) jsonNode {
16971697
node["Increment"] = scalarExpressionToJSON(e.Increment)
16981698
}
16991699
return node
1700+
case *ast.AtTimeZoneCall:
1701+
node := jsonNode{
1702+
"$type": "AtTimeZoneCall",
1703+
}
1704+
if e.DateValue != nil {
1705+
node["DateValue"] = scalarExpressionToJSON(e.DateValue)
1706+
}
1707+
if e.TimeZone != nil {
1708+
node["TimeZone"] = scalarExpressionToJSON(e.TimeZone)
1709+
}
1710+
return node
17001711
case *ast.BinaryExpression:
17011712
node := jsonNode{
17021713
"$type": "BinaryExpression",

parser/parse_select.go

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ func (p *Parser) parseAdditiveExpression() (ast.ScalarExpression, error) {
709709
}
710710

711711
func (p *Parser) parseMultiplicativeExpression() (ast.ScalarExpression, error) {
712-
left, err := p.parsePrimaryExpression()
712+
left, err := p.parsePostfixExpression()
713713
if err != nil {
714714
return nil, err
715715
}
@@ -726,7 +726,7 @@ func (p *Parser) parseMultiplicativeExpression() (ast.ScalarExpression, error) {
726726
}
727727
p.nextToken()
728728

729-
right, err := p.parsePrimaryExpression()
729+
right, err := p.parsePostfixExpression()
730730
if err != nil {
731731
return nil, err
732732
}
@@ -741,6 +741,36 @@ func (p *Parser) parseMultiplicativeExpression() (ast.ScalarExpression, error) {
741741
return left, nil
742742
}
743743

744+
// parsePostfixExpression handles postfix operators like AT TIME ZONE
745+
func (p *Parser) parsePostfixExpression() (ast.ScalarExpression, error) {
746+
expr, err := p.parsePrimaryExpression()
747+
if err != nil {
748+
return nil, err
749+
}
750+
751+
// Check for AT TIME ZONE - only if followed by "TIME"
752+
for strings.ToUpper(p.curTok.Literal) == "AT" && strings.ToUpper(p.peekTok.Literal) == "TIME" {
753+
p.nextToken() // consume AT
754+
p.nextToken() // consume TIME
755+
if strings.ToUpper(p.curTok.Literal) != "ZONE" {
756+
return nil, fmt.Errorf("expected ZONE after TIME, got %s", p.curTok.Literal)
757+
}
758+
p.nextToken() // consume ZONE
759+
760+
timezone, err := p.parsePrimaryExpression()
761+
if err != nil {
762+
return nil, err
763+
}
764+
765+
expr = &ast.AtTimeZoneCall{
766+
DateValue: expr,
767+
TimeZone: timezone,
768+
}
769+
}
770+
771+
return expr, nil
772+
}
773+
744774
func (p *Parser) parsePrimaryExpression() (ast.ScalarExpression, error) {
745775
switch p.curTok.Type {
746776
case TokenNull:
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"todo": true}
1+
{}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"todo": true}
1+
{}

0 commit comments

Comments
 (0)