Implement UPPER/LOWER; minor Fixes

This commit is contained in:
Pijus Kamandulis
2024-02-24 20:00:47 +02:00
parent f37c664c1a
commit f356f26d26
12 changed files with 394 additions and 183 deletions

View File

@@ -89,6 +89,8 @@ const (
FunctionCallIndexOf FunctionCallType = "IndexOf"
FunctionCallToString FunctionCallType = "ToString"
FunctionCallIn FunctionCallType = "In"
FunctionCallUpper FunctionCallType = "Upper"
FunctionCallLower FunctionCallType = "Lower"
)
type FunctionCall struct {

File diff suppressed because it is too large Load Diff

View File

@@ -312,6 +312,16 @@ StringFunctions <- StringEqualsExpression
/ ToStringExpression
/ ConcatExpression
/ ThreeArgumentStringFunctionExpression
/ UpperExpression
/ LowerExpression
UpperExpression <- "UPPER"i ws "(" ex:SelectItem ")" {
return parsers.FunctionCall{Type: parsers.FunctionCallUpper, Arguments: []interface{}{ex}}, nil
}
LowerExpression <- "LOWER"i ws "(" ex:SelectItem ")" {
return parsers.FunctionCall{Type: parsers.FunctionCallLower, Arguments: []interface{}{ex}}, nil
}
StringEqualsExpression <- StringEquals ws "(" ws ex1:SelectItem ws "," ws ex2:SelectItem ws ignoreCase:("," ws boolean:SelectItem { return boolean, nil })? ")" {
return parsers.FunctionCall{Type: parsers.FunctionCallStringEquals, Arguments: []interface{}{ex1, ex2, ignoreCase}}, nil

View File

@@ -288,4 +288,52 @@ func Test_Execute_StringFunctions(t *testing.T) {
},
)
})
t.Run("Should parse function UPPER()", func(t *testing.T) {
testQueryParse(
t,
`SELECT UPPER(c.id) FROM c`,
parsers.SelectStmt{
SelectItems: []parsers.SelectItem{
{
Type: parsers.SelectItemTypeFunctionCall,
Value: parsers.FunctionCall{
Type: parsers.FunctionCallUpper,
Arguments: []interface{}{
parsers.SelectItem{
Path: []string{"c", "id"},
Type: parsers.SelectItemTypeField,
},
},
},
},
},
Table: parsers.Table{Value: "c"},
},
)
})
t.Run("Should parse function LOWER()", func(t *testing.T) {
testQueryParse(
t,
`SELECT LOWER(c.id) FROM c`,
parsers.SelectStmt{
SelectItems: []parsers.SelectItem{
{
Type: parsers.SelectItemTypeFunctionCall,
Value: parsers.FunctionCall{
Type: parsers.FunctionCallLower,
Arguments: []interface{}{
parsers.SelectItem{
Path: []string{"c", "id"},
Type: parsers.SelectItemTypeField,
},
},
},
},
},
Table: parsers.Table{Value: "c"},
},
)
})
}