Fix 'NOT (bool)' statements

This commit is contained in:
Pijus Kamandulis
2026-04-04 15:04:42 +03:00
parent 3daba9d0eb
commit d76cc88175
3 changed files with 1477 additions and 1415 deletions

View File

@@ -143,6 +143,34 @@ func Test_Parse(t *testing.T) {
) )
}) })
t.Run("Should parse NOT with parentheses", func(t *testing.T) {
testQueryParse(
t,
`SELECT c.id FROM c WHERE NOT (c.id IN ("123", "456"))`,
parsers.SelectStmt{
SelectItems: []parsers.SelectItem{
{Path: []string{"c", "id"}, Type: parsers.SelectItemTypeField},
},
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
Filters: parsers.SelectItem{
Type: parsers.SelectItemTypeFunctionCall,
Invert: true,
Value: parsers.FunctionCall{
Type: parsers.FunctionCallIn,
Arguments: []interface{}{
parsers.SelectItem{
Path: []string{"c", "id"},
Type: parsers.SelectItemTypeField,
},
testutils.SelectItem_Constant_String("123"),
testutils.SelectItem_Constant_String("456"),
},
},
},
},
)
})
t.Run("Should parse IN function with function call", func(t *testing.T) { t.Run("Should parse IN function with function call", func(t *testing.T) {
testQueryParse( testQueryParse(
t, t,

File diff suppressed because it is too large Load Diff

View File

@@ -425,7 +425,15 @@ MulDivExpression <- left:SelectItemWithParentheses operations:(ws op:MultiplyOrD
return makeMathExpression(left, operations) return makeMathExpression(left, operations)
} }
SelectItemWithParentheses <- "(" ws ex:OrExpression ws ")" { return ex, nil } SelectItemWithParentheses <- inv:(Not ws)? "(" ws ex:OrExpression ws ")" {
if inv != nil {
if ex1, ok := ex.(parsers.SelectItem); ok {
ex1.Invert = true
return ex1, nil
}
}
return ex, nil
}
/ inv:(Not ws)? ex:SelectItem { / inv:(Not ws)? ex:SelectItem {
if inv != nil { if inv != nil {
ex1 := ex.(parsers.SelectItem) ex1 := ex.(parsers.SelectItem)