Skip to content

Commit 077a4e0

Browse files
committed
Add RESPECT NULLS / IGNORE NULLS window function syntax support
- Add IgnoreRespectNulls field to FunctionCall AST type - Parse RESPECT NULLS and IGNORE NULLS clauses after function parameters and before OVER clause - Update JSON marshaling to output IgnoreRespectNulls Tests enabled: - Baselines160_IgnoreRespectNullsSyntaxTests160 - IgnoreRespectNullsSyntaxTests160
1 parent ea35df6 commit 077a4e0

5 files changed

Lines changed: 40 additions & 9 deletions

File tree

ast/function_call.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,14 @@ func (*WithinGroupClause) node() {}
4141

4242
// FunctionCall represents a function call.
4343
type FunctionCall struct {
44-
CallTarget CallTarget `json:"CallTarget,omitempty"`
45-
FunctionName *Identifier `json:"FunctionName,omitempty"`
46-
Parameters []ScalarExpression `json:"Parameters,omitempty"`
47-
UniqueRowFilter string `json:"UniqueRowFilter,omitempty"`
48-
WithinGroupClause *WithinGroupClause `json:"WithinGroupClause,omitempty"`
49-
OverClause *OverClause `json:"OverClause,omitempty"`
50-
WithArrayWrapper bool `json:"WithArrayWrapper,omitempty"`
44+
CallTarget CallTarget `json:"CallTarget,omitempty"`
45+
FunctionName *Identifier `json:"FunctionName,omitempty"`
46+
Parameters []ScalarExpression `json:"Parameters,omitempty"`
47+
UniqueRowFilter string `json:"UniqueRowFilter,omitempty"`
48+
WithinGroupClause *WithinGroupClause `json:"WithinGroupClause,omitempty"`
49+
OverClause *OverClause `json:"OverClause,omitempty"`
50+
IgnoreRespectNulls []*Identifier `json:"IgnoreRespectNulls,omitempty"`
51+
WithArrayWrapper bool `json:"WithArrayWrapper,omitempty"`
5152
}
5253

5354
func (*FunctionCall) node() {}

parser/marshal.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1375,6 +1375,13 @@ func scalarExpressionToJSON(expr ast.ScalarExpression) jsonNode {
13751375
"$type": "OverClause",
13761376
}
13771377
}
1378+
if len(e.IgnoreRespectNulls) > 0 {
1379+
idents := make([]jsonNode, len(e.IgnoreRespectNulls))
1380+
for i, ident := range e.IgnoreRespectNulls {
1381+
idents[i] = identifierToJSON(ident)
1382+
}
1383+
node["IgnoreRespectNulls"] = idents
1384+
}
13781385
node["WithArrayWrapper"] = e.WithArrayWrapper
13791386
return node
13801387
case *ast.UserDefinedTypePropertyAccess:

parser/parse_select.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1323,6 +1323,29 @@ func (p *Parser) parsePostExpressionAccess(expr ast.ScalarExpression) (ast.Scala
13231323
continue // continue to check for more clauses like OVER
13241324
}
13251325

1326+
// Check for RESPECT NULLS or IGNORE NULLS for window functions
1327+
if fc, ok := expr.(*ast.FunctionCall); ok {
1328+
upperLit := strings.ToUpper(p.curTok.Literal)
1329+
if upperLit == "RESPECT" || upperLit == "IGNORE" {
1330+
// Parse RESPECT NULLS or IGNORE NULLS
1331+
firstIdent := &ast.Identifier{
1332+
Value: strings.ToUpper(p.curTok.Literal),
1333+
QuoteType: "NotQuoted",
1334+
}
1335+
p.nextToken() // consume RESPECT/IGNORE
1336+
1337+
if strings.ToUpper(p.curTok.Literal) == "NULLS" {
1338+
secondIdent := &ast.Identifier{
1339+
Value: strings.ToUpper(p.curTok.Literal),
1340+
QuoteType: "NotQuoted",
1341+
}
1342+
p.nextToken() // consume NULLS
1343+
fc.IgnoreRespectNulls = []*ast.Identifier{firstIdent, secondIdent}
1344+
}
1345+
continue // continue to check for OVER clause
1346+
}
1347+
}
1348+
13261349
// Check for OVER clause for function calls
13271350
if fc, ok := expr.(*ast.FunctionCall); ok && strings.ToUpper(p.curTok.Literal) == "OVER" {
13281351
p.nextToken() // consume OVER
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)