mirror of
https://github.com/pikami/cosmium.git
synced 2025-12-19 17:00:37 +00:00
Implement IS_DEFINED function
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -15,6 +15,8 @@ func makeSelectStmt(columns, table, whereClause interface{}, count interface{},
|
||||
selectStmt.Filters = filters
|
||||
} else if filters, ok := whereClause.(parsers.Constant); ok {
|
||||
selectStmt.Filters = filters
|
||||
} else if filters, ok := whereClause.(parsers.SelectItem); ok {
|
||||
selectStmt.Filters = filters
|
||||
}
|
||||
|
||||
if n, ok := count.(int); ok {
|
||||
@@ -186,7 +188,7 @@ SelectProperty <- name:Identifier path:(DotFieldAccess / ArrayFieldAccess)* {
|
||||
return makeSelectItem(name, path, parsers.SelectItemTypeField)
|
||||
}
|
||||
|
||||
SelectItem <- selectItem:(Literal / StringEqualsExpression / SelectArray / SelectObject / SelectProperty) asClause:AsClause? {
|
||||
SelectItem <- selectItem:(Literal / FunctionCall / SelectArray / SelectObject / SelectProperty) asClause:AsClause? {
|
||||
var itemResult parsers.SelectItem
|
||||
switch typedValue := selectItem.(type) {
|
||||
case parsers.SelectItem:
|
||||
@@ -240,6 +242,7 @@ ComparisonExpression <- "(" ws ex:OrExpression ws ")" { return ex, nil }
|
||||
/ left:SelectItem ws op:ComparisonOperator ws right:SelectItem {
|
||||
return parsers.ComparisonExpression{Left:left,Right:right,Operation:string(op.([]uint8))}, nil
|
||||
} / ex:BooleanLiteral { return ex, nil }
|
||||
/ ex:SelectItem { return ex, nil }
|
||||
|
||||
OrderByClause <- OrderBy ws ex1:OrderExpression others:(ws "," ws ex:OrderExpression { return ex, nil })* {
|
||||
return makeOrderByClause(ex1, others)
|
||||
@@ -303,10 +306,16 @@ BooleanLiteral <- ("true"i / "false"i) {
|
||||
return parsers.Constant{Type: parsers.ConstantTypeBoolean, Value: boolValue}, nil
|
||||
}
|
||||
|
||||
FunctionCall <- StringEqualsExpression / IsDefined
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
IsDefined <- "IS_DEFINED"i ws "(" ws ex:SelectItem ws ")" {
|
||||
return parsers.FunctionCall{Type: parsers.FunctionCallIsDefined, Arguments: []interface{}{ex}}, nil
|
||||
}
|
||||
|
||||
Integer <- [0-9]+ {
|
||||
return strconv.Atoi(string(c.text))
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
|
||||
func Test_Execute_StringFunctions(t *testing.T) {
|
||||
|
||||
t.Run("Should execute function STRINGEQUALS(ex1, ex2, ignoreCase)", func(t *testing.T) {
|
||||
t.Run("Should parse function STRINGEQUALS(ex1, ex2, ignoreCase)", func(t *testing.T) {
|
||||
testQueryParse(
|
||||
t,
|
||||
`SELECT STRINGEQUALS(c.id, "123", true) FROM c`,
|
||||
@@ -46,7 +46,7 @@ func Test_Execute_StringFunctions(t *testing.T) {
|
||||
)
|
||||
})
|
||||
|
||||
t.Run("Should execute function STRINGEQUALS(ex1, ex2)", func(t *testing.T) {
|
||||
t.Run("Should parse function STRINGEQUALS(ex1, ex2)", func(t *testing.T) {
|
||||
testQueryParse(
|
||||
t,
|
||||
`SELECT STRINGEQUALS(c.id, "123") FROM c`,
|
||||
46
parsers/nosql/nosql_type_checking_functions_test.go
Normal file
46
parsers/nosql/nosql_type_checking_functions_test.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package nosql_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/pikami/cosmium/parsers"
|
||||
)
|
||||
|
||||
func Test_Execute_TypeCheckingFunctions(t *testing.T) {
|
||||
|
||||
t.Run("Should parse function IS_DEFINED", func(t *testing.T) {
|
||||
testQueryParse(
|
||||
t,
|
||||
`SELECT IS_DEFINED(c.id) FROM c WHERE IS_DEFINED(c.pk)`,
|
||||
parsers.SelectStmt{
|
||||
SelectItems: []parsers.SelectItem{
|
||||
{
|
||||
Type: parsers.SelectItemTypeFunctionCall,
|
||||
Value: parsers.FunctionCall{
|
||||
Type: parsers.FunctionCallIsDefined,
|
||||
Arguments: []interface{}{
|
||||
parsers.SelectItem{
|
||||
Path: []string{"c", "id"},
|
||||
Type: parsers.SelectItemTypeField,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Filters: parsers.SelectItem{
|
||||
Type: parsers.SelectItemTypeFunctionCall,
|
||||
Value: parsers.FunctionCall{
|
||||
Type: parsers.FunctionCallIsDefined,
|
||||
Arguments: []interface{}{
|
||||
parsers.SelectItem{
|
||||
Path: []string{"c", "pk"},
|
||||
Type: parsers.SelectItemTypeField,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
)
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user