mirror of
https://github.com/pikami/cosmium.git
synced 2025-12-18 16:30:44 +00:00
Implement IN function
This commit is contained in:
@@ -192,6 +192,8 @@ func getFieldValue(field parsers.SelectItem, queryParameters map[string]interfac
|
||||
return strings_ToString(typedValue.Arguments, queryParameters, row)
|
||||
case parsers.FunctionCallIsDefined:
|
||||
return typeChecking_IsDefined(typedValue.Arguments, queryParameters, row)
|
||||
case parsers.FunctionCallIn:
|
||||
return misc_In(typedValue.Arguments, queryParameters, row)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -58,4 +58,50 @@ func Test_Execute(t *testing.T) {
|
||||
},
|
||||
)
|
||||
})
|
||||
|
||||
t.Run("Should execute IN function", func(t *testing.T) {
|
||||
testQueryExecute(
|
||||
t,
|
||||
parsers.SelectStmt{
|
||||
SelectItems: []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.FunctionCallIn,
|
||||
Arguments: []interface{}{
|
||||
parsers.SelectItem{
|
||||
Path: []string{"c", "id"},
|
||||
Type: parsers.SelectItemTypeField,
|
||||
},
|
||||
parsers.SelectItem{
|
||||
Type: parsers.SelectItemTypeConstant,
|
||||
Value: parsers.Constant{
|
||||
Type: parsers.ConstantTypeString,
|
||||
Value: "123",
|
||||
},
|
||||
},
|
||||
parsers.SelectItem{
|
||||
Type: parsers.SelectItemTypeConstant,
|
||||
Value: parsers.Constant{
|
||||
Type: parsers.ConstantTypeString,
|
||||
Value: "456",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
mockData,
|
||||
[]memoryexecutor.RowType{
|
||||
map[string]interface{}{"id": "456"},
|
||||
map[string]interface{}{"id": "123"},
|
||||
},
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
18
query_executors/memory_executor/misc_functions.go
Normal file
18
query_executors/memory_executor/misc_functions.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package memoryexecutor
|
||||
|
||||
import (
|
||||
"github.com/pikami/cosmium/parsers"
|
||||
)
|
||||
|
||||
func misc_In(arguments []interface{}, queryParameters map[string]interface{}, row RowType) bool {
|
||||
value := getFieldValue(arguments[0].(parsers.SelectItem), queryParameters, row)
|
||||
|
||||
for i := 1; i < len(arguments); i++ {
|
||||
compareValue := getFieldValue(arguments[i].(parsers.SelectItem), queryParameters, row)
|
||||
if compareValues(value, compareValue) == 0 {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
Reference in New Issue
Block a user