Compare commits

..

No commits in common. "69b76c1c3ebc4b4850163837558319df86a8a8c9" and "f5b84539953c609f2bcfbbe566417018b986279d" have entirely different histories.

15 changed files with 1496 additions and 2097 deletions

View File

@ -65,9 +65,9 @@ Cosmium strives to support the core features of Cosmos DB, including:
| Function | Implemented | | Function | Implemented |
| ------------------ | ----------- | | ------------------ | ----------- |
| ARRAY_CONCAT | Yes | | ARRAY_CONCAT | Yes |
| ARRAY_CONTAINS | Yes | | ARRAY_CONTAINS | No |
| ARRAY_CONTAINS_ANY | Yes | | ARRAY_CONTAINS_ANY | No |
| ARRAY_CONTAINS_ALL | Yes | | ARRAY_CONTAINS_ALL | No |
| ARRAY_LENGTH | Yes | | ARRAY_LENGTH | Yes |
| ARRAY_SLICE | Yes | | ARRAY_SLICE | Yes |
| CHOOSE | No | | CHOOSE | No |

View File

@ -123,14 +123,11 @@ const (
FunctionCallIsPrimitive FunctionCallType = "IsPrimitive" FunctionCallIsPrimitive FunctionCallType = "IsPrimitive"
FunctionCallIsString FunctionCallType = "IsString" FunctionCallIsString FunctionCallType = "IsString"
FunctionCallArrayConcat FunctionCallType = "ArrayConcat" FunctionCallArrayConcat FunctionCallType = "ArrayConcat"
FunctionCallArrayContains FunctionCallType = "ArrayContains" FunctionCallArrayLength FunctionCallType = "ArrayLength"
FunctionCallArrayContainsAny FunctionCallType = "ArrayContainsAny" FunctionCallArraySlice FunctionCallType = "ArraySlice"
FunctionCallArrayContainsAll FunctionCallType = "ArrayContainsAll" FunctionCallSetIntersect FunctionCallType = "SetIntersect"
FunctionCallArrayLength FunctionCallType = "ArrayLength" FunctionCallSetUnion FunctionCallType = "SetUnion"
FunctionCallArraySlice FunctionCallType = "ArraySlice"
FunctionCallSetIntersect FunctionCallType = "SetIntersect"
FunctionCallSetUnion FunctionCallType = "SetUnion"
FunctionCallMathAbs FunctionCallType = "MathAbs" FunctionCallMathAbs FunctionCallType = "MathAbs"
FunctionCallMathAcos FunctionCallType = "MathAcos" FunctionCallMathAcos FunctionCallType = "MathAcos"

View File

@ -4,7 +4,6 @@ import (
"testing" "testing"
"github.com/pikami/cosmium/parsers" "github.com/pikami/cosmium/parsers"
testutils "github.com/pikami/cosmium/test_utils"
) )
func Test_Parse_ArrayFunctions(t *testing.T) { func Test_Parse_ArrayFunctions(t *testing.T) {
@ -37,119 +36,6 @@ func Test_Parse_ArrayFunctions(t *testing.T) {
) )
}) })
t.Run("Should parse function ARRAY_CONTAINS()", func(t *testing.T) {
testQueryParse(
t,
`SELECT ARRAY_CONTAINS(c.a1, "value") FROM c`,
parsers.SelectStmt{
SelectItems: []parsers.SelectItem{
{
Type: parsers.SelectItemTypeFunctionCall,
Value: parsers.FunctionCall{
Type: parsers.FunctionCallArrayContains,
Arguments: []interface{}{
parsers.SelectItem{
Path: []string{"c", "a1"},
Type: parsers.SelectItemTypeField,
},
testutils.SelectItem_Constant_String("value"),
nil,
},
},
},
},
Table: parsers.Table{Value: "c"},
},
)
})
t.Run("Should parse function ARRAY_CONTAINS() with partial match", func(t *testing.T) {
testQueryParse(
t,
`SELECT ARRAY_CONTAINS(["a", "b"], "value", true) FROM c`,
parsers.SelectStmt{
SelectItems: []parsers.SelectItem{
{
Type: parsers.SelectItemTypeFunctionCall,
Value: parsers.FunctionCall{
Type: parsers.FunctionCallArrayContains,
Arguments: []interface{}{
parsers.SelectItem{
Type: parsers.SelectItemTypeArray,
SelectItems: []parsers.SelectItem{
testutils.SelectItem_Constant_String("a"),
testutils.SelectItem_Constant_String("b"),
},
},
testutils.SelectItem_Constant_String("value"),
testutils.SelectItem_Constant_Bool(true),
},
},
},
},
Table: parsers.Table{Value: "c"},
},
)
})
t.Run("Should parse function ARRAY_CONTAINS_ANY()", func(t *testing.T) {
testQueryParse(
t,
`SELECT ARRAY_CONTAINS_ANY(["a", "b"], "value", true) FROM c`,
parsers.SelectStmt{
SelectItems: []parsers.SelectItem{
{
Type: parsers.SelectItemTypeFunctionCall,
Value: parsers.FunctionCall{
Type: parsers.FunctionCallArrayContainsAny,
Arguments: []interface{}{
parsers.SelectItem{
Type: parsers.SelectItemTypeArray,
SelectItems: []parsers.SelectItem{
testutils.SelectItem_Constant_String("a"),
testutils.SelectItem_Constant_String("b"),
},
},
testutils.SelectItem_Constant_String("value"),
testutils.SelectItem_Constant_Bool(true),
},
},
},
},
Table: parsers.Table{Value: "c"},
},
)
})
t.Run("Should parse function ARRAY_CONTAINS_ALL()", func(t *testing.T) {
testQueryParse(
t,
`SELECT ARRAY_CONTAINS_ALL(["a", "b"], "value", true) FROM c`,
parsers.SelectStmt{
SelectItems: []parsers.SelectItem{
{
Type: parsers.SelectItemTypeFunctionCall,
Value: parsers.FunctionCall{
Type: parsers.FunctionCallArrayContainsAll,
Arguments: []interface{}{
parsers.SelectItem{
Type: parsers.SelectItemTypeArray,
SelectItems: []parsers.SelectItem{
testutils.SelectItem_Constant_String("a"),
testutils.SelectItem_Constant_String("b"),
},
},
testutils.SelectItem_Constant_String("value"),
testutils.SelectItem_Constant_Bool(true),
},
},
},
},
Table: parsers.Table{Value: "c"},
},
)
})
t.Run("Should parse function ARRAY_LENGTH()", func(t *testing.T) { t.Run("Should parse function ARRAY_LENGTH()", func(t *testing.T) {
testQueryParse( testQueryParse(
t, t,
@ -189,8 +75,20 @@ func Test_Parse_ArrayFunctions(t *testing.T) {
Path: []string{"c", "array"}, Path: []string{"c", "array"},
Type: parsers.SelectItemTypeField, Type: parsers.SelectItemTypeField,
}, },
testutils.SelectItem_Constant_Int(0), parsers.SelectItem{
testutils.SelectItem_Constant_Int(2), Type: parsers.SelectItemTypeConstant,
Value: parsers.Constant{
Type: parsers.ConstantTypeInteger,
Value: 0,
},
},
parsers.SelectItem{
Type: parsers.SelectItemTypeConstant,
Value: parsers.Constant{
Type: parsers.ConstantTypeInteger,
Value: 2,
},
},
}, },
}, },
}, },

View File

@ -7,7 +7,6 @@ import (
"github.com/pikami/cosmium/parsers" "github.com/pikami/cosmium/parsers"
"github.com/pikami/cosmium/parsers/nosql" "github.com/pikami/cosmium/parsers/nosql"
testutils "github.com/pikami/cosmium/test_utils"
) )
// For Parser Debugging // For Parser Debugging
@ -103,8 +102,20 @@ func Test_Parse(t *testing.T) {
Path: []string{"c", "id"}, Path: []string{"c", "id"},
Type: parsers.SelectItemTypeField, Type: parsers.SelectItemTypeField,
}, },
testutils.SelectItem_Constant_String("123"), parsers.SelectItem{
testutils.SelectItem_Constant_String("456"), Type: parsers.SelectItemTypeConstant,
Value: parsers.Constant{
Type: parsers.ConstantTypeString,
Value: "123",
},
},
parsers.SelectItem{
Type: parsers.SelectItemTypeConstant,
Value: parsers.Constant{
Type: parsers.ConstantTypeString,
Value: "456",
},
},
}, },
}, },
}, },

File diff suppressed because it is too large Load Diff

View File

@ -457,9 +457,6 @@ AggregateFunctions <- AvgAggregateExpression
/ SumAggregateExpression / SumAggregateExpression
ArrayFunctions <- ArrayConcatExpression ArrayFunctions <- ArrayConcatExpression
/ ArrayContainsExpression
/ ArrayContainsAnyExpression
/ ArrayContainsAllExpression
/ ArrayLengthExpression / ArrayLengthExpression
/ ArraySliceExpression / ArraySliceExpression
/ SetIntersectExpression / SetIntersectExpression
@ -629,18 +626,6 @@ ArrayConcatExpression <- "ARRAY_CONCAT"i ws "(" ws arrays:SelectItem others:(ws
return createFunctionCall(parsers.FunctionCallArrayConcat, append([]interface{}{arrays}, others.([]interface{})...)) return createFunctionCall(parsers.FunctionCallArrayConcat, append([]interface{}{arrays}, others.([]interface{})...))
} }
ArrayContainsExpression <- "ARRAY_CONTAINS"i ws "(" ws array:SelectItem ws "," ws item:SelectItem partialMatch:(ws "," ws ex:SelectItem { return ex, nil })? ws ")" {
return createFunctionCall(parsers.FunctionCallArrayContains, []interface{}{array, item, partialMatch})
}
ArrayContainsAnyExpression <- "ARRAY_CONTAINS_ANY"i ws "(" ws array:SelectItem items:(ws "," ws ex:SelectItem { return ex, nil })+ ws ")" {
return createFunctionCall(parsers.FunctionCallArrayContainsAny, append([]interface{}{array}, items.([]interface{})...))
}
ArrayContainsAllExpression <- "ARRAY_CONTAINS_ALL"i ws "(" ws array:SelectItem items:(ws "," ws ex:SelectItem { return ex, nil })+ ws ")" {
return createFunctionCall(parsers.FunctionCallArrayContainsAll, append([]interface{}{array}, items.([]interface{})...))
}
ArrayLengthExpression <- "ARRAY_LENGTH"i ws "(" ws array:SelectItem ws ")" { ArrayLengthExpression <- "ARRAY_LENGTH"i ws "(" ws array:SelectItem ws ")" {
return createFunctionCall(parsers.FunctionCallArrayLength, []interface{}{array}) return createFunctionCall(parsers.FunctionCallArrayLength, []interface{}{array})
} }

View File

@ -4,7 +4,6 @@ import (
"testing" "testing"
"github.com/pikami/cosmium/parsers" "github.com/pikami/cosmium/parsers"
testutils "github.com/pikami/cosmium/test_utils"
) )
func Test_Execute_StringFunctions(t *testing.T) { func Test_Execute_StringFunctions(t *testing.T) {
@ -24,8 +23,20 @@ func Test_Execute_StringFunctions(t *testing.T) {
Path: []string{"c", "id"}, Path: []string{"c", "id"},
Type: parsers.SelectItemTypeField, Type: parsers.SelectItemTypeField,
}, },
testutils.SelectItem_Constant_String("123"), parsers.SelectItem{
testutils.SelectItem_Constant_Bool(true), Type: parsers.SelectItemTypeConstant,
Value: parsers.Constant{
Type: parsers.ConstantTypeString,
Value: "123",
},
},
parsers.SelectItem{
Type: parsers.SelectItemTypeConstant,
Value: parsers.Constant{
Type: parsers.ConstantTypeBoolean,
Value: true,
},
},
}, },
}, },
}, },
@ -50,7 +61,13 @@ func Test_Execute_StringFunctions(t *testing.T) {
Path: []string{"c", "id"}, Path: []string{"c", "id"},
Type: parsers.SelectItemTypeField, Type: parsers.SelectItemTypeField,
}, },
testutils.SelectItem_Constant_String("123"), parsers.SelectItem{
Type: parsers.SelectItemTypeConstant,
Value: parsers.Constant{
Type: parsers.ConstantTypeString,
Value: "123",
},
},
nil, nil,
}, },
}, },
@ -76,7 +93,13 @@ func Test_Execute_StringFunctions(t *testing.T) {
Path: []string{"c", "id"}, Path: []string{"c", "id"},
Type: parsers.SelectItemTypeField, Type: parsers.SelectItemTypeField,
}, },
testutils.SelectItem_Constant_String("123"), parsers.SelectItem{
Type: parsers.SelectItemTypeConstant,
Value: parsers.Constant{
Type: parsers.ConstantTypeString,
Value: "123",
},
},
parsers.SelectItem{ parsers.SelectItem{
Path: []string{"c", "pk"}, Path: []string{"c", "pk"},
Type: parsers.SelectItemTypeField, Type: parsers.SelectItemTypeField,
@ -105,8 +128,20 @@ func Test_Execute_StringFunctions(t *testing.T) {
Path: []string{"c", "id"}, Path: []string{"c", "id"},
Type: parsers.SelectItemTypeField, Type: parsers.SelectItemTypeField,
}, },
testutils.SelectItem_Constant_String("123"), parsers.SelectItem{
testutils.SelectItem_Constant_Bool(true), Type: parsers.SelectItemTypeConstant,
Value: parsers.Constant{
Type: parsers.ConstantTypeString,
Value: "123",
},
},
parsers.SelectItem{
Type: parsers.SelectItemTypeConstant,
Value: parsers.Constant{
Type: parsers.ConstantTypeBoolean,
Value: true,
},
},
}, },
}, },
}, },
@ -131,8 +166,20 @@ func Test_Execute_StringFunctions(t *testing.T) {
Path: []string{"c", "id"}, Path: []string{"c", "id"},
Type: parsers.SelectItemTypeField, Type: parsers.SelectItemTypeField,
}, },
testutils.SelectItem_Constant_String("123"), parsers.SelectItem{
testutils.SelectItem_Constant_Bool(true), Type: parsers.SelectItemTypeConstant,
Value: parsers.Constant{
Type: parsers.ConstantTypeString,
Value: "123",
},
},
parsers.SelectItem{
Type: parsers.SelectItemTypeConstant,
Value: parsers.Constant{
Type: parsers.ConstantTypeBoolean,
Value: true,
},
},
}, },
}, },
}, },
@ -157,8 +204,20 @@ func Test_Execute_StringFunctions(t *testing.T) {
Path: []string{"c", "id"}, Path: []string{"c", "id"},
Type: parsers.SelectItemTypeField, Type: parsers.SelectItemTypeField,
}, },
testutils.SelectItem_Constant_String("123"), parsers.SelectItem{
testutils.SelectItem_Constant_Bool(true), Type: parsers.SelectItemTypeConstant,
Value: parsers.Constant{
Type: parsers.ConstantTypeString,
Value: "123",
},
},
parsers.SelectItem{
Type: parsers.SelectItemTypeConstant,
Value: parsers.Constant{
Type: parsers.ConstantTypeBoolean,
Value: true,
},
},
}, },
}, },
}, },
@ -183,8 +242,20 @@ func Test_Execute_StringFunctions(t *testing.T) {
Path: []string{"c", "id"}, Path: []string{"c", "id"},
Type: parsers.SelectItemTypeField, Type: parsers.SelectItemTypeField,
}, },
testutils.SelectItem_Constant_String("2"), parsers.SelectItem{
testutils.SelectItem_Constant_Int(1), Type: parsers.SelectItemTypeConstant,
Value: parsers.Constant{
Type: parsers.ConstantTypeString,
Value: "2",
},
},
parsers.SelectItem{
Type: parsers.SelectItemTypeConstant,
Value: parsers.Constant{
Type: parsers.ConstantTypeInteger,
Value: 1,
},
},
}, },
}, },
}, },
@ -281,7 +352,13 @@ func Test_Execute_StringFunctions(t *testing.T) {
Path: []string{"c", "id"}, Path: []string{"c", "id"},
Type: parsers.SelectItemTypeField, Type: parsers.SelectItemTypeField,
}, },
testutils.SelectItem_Constant_Int(5), parsers.SelectItem{
Type: parsers.SelectItemTypeConstant,
Value: parsers.Constant{
Type: parsers.ConstantTypeInteger,
Value: 5,
},
},
}, },
}, },
}, },
@ -354,8 +431,20 @@ func Test_Execute_StringFunctions(t *testing.T) {
Path: []string{"c", "id"}, Path: []string{"c", "id"},
Type: parsers.SelectItemTypeField, Type: parsers.SelectItemTypeField,
}, },
testutils.SelectItem_Constant_String("old"), parsers.SelectItem{
testutils.SelectItem_Constant_String("new"), Type: parsers.SelectItemTypeConstant,
Value: parsers.Constant{
Type: parsers.ConstantTypeString,
Value: "old",
},
},
parsers.SelectItem{
Type: parsers.SelectItemTypeConstant,
Value: parsers.Constant{
Type: parsers.ConstantTypeString,
Value: "new",
},
},
}, },
}, },
}, },
@ -380,7 +469,13 @@ func Test_Execute_StringFunctions(t *testing.T) {
Path: []string{"c", "id"}, Path: []string{"c", "id"},
Type: parsers.SelectItemTypeField, Type: parsers.SelectItemTypeField,
}, },
testutils.SelectItem_Constant_Int(3), parsers.SelectItem{
Type: parsers.SelectItemTypeConstant,
Value: parsers.Constant{
Type: parsers.ConstantTypeInteger,
Value: 3,
},
},
}, },
}, },
}, },
@ -429,7 +524,13 @@ func Test_Execute_StringFunctions(t *testing.T) {
Path: []string{"c", "id"}, Path: []string{"c", "id"},
Type: parsers.SelectItemTypeField, Type: parsers.SelectItemTypeField,
}, },
testutils.SelectItem_Constant_Int(3), parsers.SelectItem{
Type: parsers.SelectItemTypeConstant,
Value: parsers.Constant{
Type: parsers.ConstantTypeInteger,
Value: 3,
},
},
}, },
}, },
}, },
@ -478,8 +579,20 @@ func Test_Execute_StringFunctions(t *testing.T) {
Path: []string{"c", "id"}, Path: []string{"c", "id"},
Type: parsers.SelectItemTypeField, Type: parsers.SelectItemTypeField,
}, },
testutils.SelectItem_Constant_Int(1), parsers.SelectItem{
testutils.SelectItem_Constant_Int(5), Type: parsers.SelectItemTypeConstant,
Value: parsers.Constant{
Type: parsers.ConstantTypeInteger,
Value: 1,
},
},
parsers.SelectItem{
Type: parsers.SelectItemTypeConstant,
Value: parsers.Constant{
Type: parsers.ConstantTypeInteger,
Value: 5,
},
},
}, },
}, },
}, },

View File

@ -4,7 +4,6 @@ import (
"testing" "testing"
"github.com/pikami/cosmium/parsers" "github.com/pikami/cosmium/parsers"
testutils "github.com/pikami/cosmium/test_utils"
) )
func Test_Parse_Were(t *testing.T) { func Test_Parse_Were(t *testing.T) {
@ -23,7 +22,10 @@ func Test_Parse_Were(t *testing.T) {
Filters: parsers.ComparisonExpression{ Filters: parsers.ComparisonExpression{
Operation: "=", Operation: "=",
Left: parsers.SelectItem{Path: []string{"c", "isCool"}}, Left: parsers.SelectItem{Path: []string{"c", "isCool"}},
Right: testutils.SelectItem_Constant_Bool(true), Right: parsers.SelectItem{
Type: parsers.SelectItemTypeConstant,
Value: parsers.Constant{Type: parsers.ConstantTypeBoolean, Value: true},
},
}, },
}, },
) )
@ -49,12 +51,18 @@ func Test_Parse_Were(t *testing.T) {
parsers.ComparisonExpression{ parsers.ComparisonExpression{
Operation: "=", Operation: "=",
Left: parsers.SelectItem{Path: []string{"c", "id"}}, Left: parsers.SelectItem{Path: []string{"c", "id"}},
Right: testutils.SelectItem_Constant_String("12345"), Right: parsers.SelectItem{
Type: parsers.SelectItemTypeConstant,
Value: parsers.Constant{Type: parsers.ConstantTypeString, Value: "12345"},
},
}, },
parsers.ComparisonExpression{ parsers.ComparisonExpression{
Operation: "=", Operation: "=",
Left: parsers.SelectItem{Path: []string{"c", "pk"}}, Left: parsers.SelectItem{Path: []string{"c", "pk"}},
Right: testutils.SelectItem_Constant_Int(123), Right: parsers.SelectItem{
Type: parsers.SelectItemTypeConstant,
Value: parsers.Constant{Type: parsers.ConstantTypeInteger, Value: 123},
},
}, },
}, },
}, },
@ -79,7 +87,10 @@ func Test_Parse_Were(t *testing.T) {
parsers.ComparisonExpression{ parsers.ComparisonExpression{
Operation: "=", Operation: "=",
Left: parsers.SelectItem{Path: []string{"c", "isCool"}}, Left: parsers.SelectItem{Path: []string{"c", "isCool"}},
Right: testutils.SelectItem_Constant_Bool(true), Right: parsers.SelectItem{
Type: parsers.SelectItemTypeConstant,
Value: parsers.Constant{Type: parsers.ConstantTypeBoolean, Value: true},
},
}, },
parsers.LogicalExpression{ parsers.LogicalExpression{
Operation: parsers.LogicalExpressionTypeOr, Operation: parsers.LogicalExpressionTypeOr,
@ -87,12 +98,18 @@ func Test_Parse_Were(t *testing.T) {
parsers.ComparisonExpression{ parsers.ComparisonExpression{
Operation: "=", Operation: "=",
Left: parsers.SelectItem{Path: []string{"c", "id"}}, Left: parsers.SelectItem{Path: []string{"c", "id"}},
Right: testutils.SelectItem_Constant_String("123"), Right: parsers.SelectItem{
Type: parsers.SelectItemTypeConstant,
Value: parsers.Constant{Type: parsers.ConstantTypeString, Value: "123"},
},
}, },
parsers.ComparisonExpression{ parsers.ComparisonExpression{
Operation: "=", Operation: "=",
Left: parsers.SelectItem{Path: []string{"c", "id"}}, Left: parsers.SelectItem{Path: []string{"c", "id"}},
Right: testutils.SelectItem_Constant_String("456"), Right: parsers.SelectItem{
Type: parsers.SelectItemTypeConstant,
Value: parsers.Constant{Type: parsers.ConstantTypeString, Value: "456"},
},
}, },
}, },
}, },
@ -118,28 +135,43 @@ func Test_Parse_Were(t *testing.T) {
Filters: parsers.LogicalExpression{ Filters: parsers.LogicalExpression{
Expressions: []interface{}{ Expressions: []interface{}{
parsers.ComparisonExpression{ parsers.ComparisonExpression{
Left: parsers.SelectItem{Path: []string{"c", "boolean"}}, Left: parsers.SelectItem{Path: []string{"c", "boolean"}},
Right: testutils.SelectItem_Constant_Bool(true), Right: parsers.SelectItem{
Type: parsers.SelectItemTypeConstant,
Value: parsers.Constant{Type: parsers.ConstantTypeBoolean, Value: true},
},
Operation: "=", Operation: "=",
}, },
parsers.ComparisonExpression{ parsers.ComparisonExpression{
Left: parsers.SelectItem{Path: []string{"c", "integer"}}, Left: parsers.SelectItem{Path: []string{"c", "integer"}},
Right: testutils.SelectItem_Constant_Int(1), Right: parsers.SelectItem{
Type: parsers.SelectItemTypeConstant,
Value: parsers.Constant{Type: parsers.ConstantTypeInteger, Value: 1},
},
Operation: "=", Operation: "=",
}, },
parsers.ComparisonExpression{ parsers.ComparisonExpression{
Left: parsers.SelectItem{Path: []string{"c", "float"}}, Left: parsers.SelectItem{Path: []string{"c", "float"}},
Right: testutils.SelectItem_Constant_Float(6.9), Right: parsers.SelectItem{
Type: parsers.SelectItemTypeConstant,
Value: parsers.Constant{Type: parsers.ConstantTypeFloat, Value: 6.9},
},
Operation: "=", Operation: "=",
}, },
parsers.ComparisonExpression{ parsers.ComparisonExpression{
Left: parsers.SelectItem{Path: []string{"c", "string"}}, Left: parsers.SelectItem{Path: []string{"c", "string"}},
Right: testutils.SelectItem_Constant_String("hello"), Right: parsers.SelectItem{
Type: parsers.SelectItemTypeConstant,
Value: parsers.Constant{Type: parsers.ConstantTypeString, Value: "hello"},
},
Operation: "=", Operation: "=",
}, },
parsers.ComparisonExpression{ parsers.ComparisonExpression{
Left: parsers.SelectItem{Path: []string{"c", "param"}}, Left: parsers.SelectItem{Path: []string{"c", "param"}},
Right: testutils.SelectItem_Constant_Parameter("@param_id1"), Right: parsers.SelectItem{
Type: parsers.SelectItemTypeConstant,
Value: parsers.Constant{Type: parsers.ConstantTypeParameterConstant, Value: "@param_id1"},
},
Operation: "=", Operation: "=",
}, },
}, },

View File

@ -16,86 +16,6 @@ func (r rowContext) array_Concat(arguments []interface{}) []interface{} {
return result return result
} }
func (r rowContext) array_Contains(arguments []interface{}) bool {
array := r.parseArray(arguments[0])
if array == nil {
return false
}
exprToSearch := r.resolveSelectItem(arguments[1].(parsers.SelectItem))
partialSearch := false
if len(arguments) > 2 {
boolExpr := r.resolveSelectItem(arguments[2].(parsers.SelectItem))
if boolValue, ok := boolExpr.(bool); ok {
partialSearch = boolValue
} else {
logger.Error("array_Contains - got parameters of wrong type")
return false
}
}
for _, item := range array {
if partialSearch {
if r.partialMatch(item, exprToSearch) {
return true
}
} else {
if reflect.DeepEqual(item, exprToSearch) {
return true
}
}
}
return false
}
func (r rowContext) array_Contains_Any(arguments []interface{}) bool {
array := r.parseArray(arguments[0])
if array == nil {
return false
}
valueSelectItems := arguments[1:]
for _, valueSelectItem := range valueSelectItems {
value := r.resolveSelectItem(valueSelectItem.(parsers.SelectItem))
for _, item := range array {
if reflect.DeepEqual(item, value) {
return true
}
}
}
return false
}
func (r rowContext) array_Contains_All(arguments []interface{}) bool {
array := r.parseArray(arguments[0])
if array == nil {
return false
}
valueSelectItems := arguments[1:]
for _, valueSelectItem := range valueSelectItems {
value := r.resolveSelectItem(valueSelectItem.(parsers.SelectItem))
found := false
for _, item := range array {
if reflect.DeepEqual(item, value) {
found = true
break
}
}
if !found {
return false
}
}
return true
}
func (r rowContext) array_Length(arguments []interface{}) int { func (r rowContext) array_Length(arguments []interface{}) int {
array := r.parseArray(arguments[0]) array := r.parseArray(arguments[0])
if array == nil { if array == nil {
@ -209,21 +129,3 @@ func (r rowContext) parseArray(argument interface{}) []interface{} {
return result return result
} }
func (r rowContext) partialMatch(item interface{}, exprToSearch interface{}) bool {
itemValue := reflect.ValueOf(item)
exprValue := reflect.ValueOf(exprToSearch)
if itemValue.Kind() != reflect.Map || exprValue.Kind() != reflect.Map {
logger.Error("partialMatch got parameters of wrong type")
return false
}
for _, key := range exprValue.MapKeys() {
if itemValue.MapIndex(key).Interface() != exprValue.MapIndex(key).Interface() {
return false
}
}
return true
}

View File

@ -5,7 +5,6 @@ import (
"github.com/pikami/cosmium/parsers" "github.com/pikami/cosmium/parsers"
memoryexecutor "github.com/pikami/cosmium/query_executors/memory_executor" memoryexecutor "github.com/pikami/cosmium/query_executors/memory_executor"
testutils "github.com/pikami/cosmium/test_utils"
) )
func Test_Execute_ArrayFunctions(t *testing.T) { func Test_Execute_ArrayFunctions(t *testing.T) {
@ -53,286 +52,6 @@ func Test_Execute_ArrayFunctions(t *testing.T) {
) )
}) })
t.Run("Should execute function ARRAY_CONTAINS()", func(t *testing.T) {
testQueryExecute(
t,
parsers.SelectStmt{
Parameters: map[string]interface{}{
"@categories": []interface{}{"coats", "jackets", "sweatshirts"},
"@objectArray": []interface{}{map[string]interface{}{"category": "shirts", "color": "blue"}},
"@fullMatchObject": map[string]interface{}{"category": "shirts", "color": "blue"},
"@partialMatchObject": map[string]interface{}{"category": "shirts"},
"@missingPartialMatchObject": map[string]interface{}{"category": "shorts", "color": "blue"},
},
SelectItems: []parsers.SelectItem{
{
Alias: "ContainsItem",
Type: parsers.SelectItemTypeFunctionCall,
Value: parsers.FunctionCall{
Type: parsers.FunctionCallArrayContains,
Arguments: []interface{}{
testutils.SelectItem_Constant_Parameter("@categories"),
testutils.SelectItem_Constant_String("coats"),
},
},
},
{
Alias: "MissingItem",
Type: parsers.SelectItemTypeFunctionCall,
Value: parsers.FunctionCall{
Type: parsers.FunctionCallArrayContains,
Arguments: []interface{}{
testutils.SelectItem_Constant_Parameter("@categories"),
testutils.SelectItem_Constant_String("hoodies"),
},
},
},
{
Alias: "ContainsFullMatchObject",
Type: parsers.SelectItemTypeFunctionCall,
Value: parsers.FunctionCall{
Type: parsers.FunctionCallArrayContains,
Arguments: []interface{}{
testutils.SelectItem_Constant_Parameter("@objectArray"),
testutils.SelectItem_Constant_Parameter("@fullMatchObject"),
},
},
},
{
Alias: "MissingFullMatchObject",
Type: parsers.SelectItemTypeFunctionCall,
Value: parsers.FunctionCall{
Type: parsers.FunctionCallArrayContains,
Arguments: []interface{}{
testutils.SelectItem_Constant_Parameter("@objectArray"),
testutils.SelectItem_Constant_Parameter("@partialMatchObject"),
},
},
},
{
Alias: "ContainsPartialMatchObject",
Type: parsers.SelectItemTypeFunctionCall,
Value: parsers.FunctionCall{
Type: parsers.FunctionCallArrayContains,
Arguments: []interface{}{
testutils.SelectItem_Constant_Parameter("@objectArray"),
testutils.SelectItem_Constant_Parameter("@partialMatchObject"),
testutils.SelectItem_Constant_Bool(true),
},
},
},
{
Alias: "MissingPartialMatchObject",
Type: parsers.SelectItemTypeFunctionCall,
Value: parsers.FunctionCall{
Type: parsers.FunctionCallArrayContains,
Arguments: []interface{}{
testutils.SelectItem_Constant_Parameter("@objectArray"),
testutils.SelectItem_Constant_Parameter("@missingPartialMatchObject"),
testutils.SelectItem_Constant_Bool(true),
},
},
},
},
},
[]memoryexecutor.RowType{map[string]interface{}{"id": "123"}},
[]memoryexecutor.RowType{
map[string]interface{}{
"ContainsItem": true,
"MissingItem": false,
"ContainsFullMatchObject": true,
"MissingFullMatchObject": false,
"ContainsPartialMatchObject": true,
"MissingPartialMatchObject": false,
},
},
)
})
t.Run("Should execute function ARRAY_CONTAINS_ANY()", func(t *testing.T) {
testQueryExecute(
t,
parsers.SelectStmt{
Parameters: map[string]interface{}{
"@mixedArray": []interface{}{1, true, "3", []int{1, 2, 3}},
"@numbers": []interface{}{1, 2, 3, 4},
"@emptyArray": []interface{}{},
"@arr123": []interface{}{1, 2, 3},
},
SelectItems: []parsers.SelectItem{
{
Alias: "matchesEntireArray",
Type: parsers.SelectItemTypeFunctionCall,
Value: parsers.FunctionCall{
Type: parsers.FunctionCallArrayContainsAny,
Arguments: []interface{}{
testutils.SelectItem_Constant_Parameter("@mixedArray"),
testutils.SelectItem_Constant_Int(1),
testutils.SelectItem_Constant_Bool(true),
testutils.SelectItem_Constant_String("3"),
testutils.SelectItem_Constant_Parameter("@arr123"),
},
},
},
{
Alias: "matchesSomeValues",
Type: parsers.SelectItemTypeFunctionCall,
Value: parsers.FunctionCall{
Type: parsers.FunctionCallArrayContainsAny,
Arguments: []interface{}{
testutils.SelectItem_Constant_Parameter("@numbers"),
testutils.SelectItem_Constant_Int(2),
testutils.SelectItem_Constant_Int(3),
testutils.SelectItem_Constant_Int(4),
testutils.SelectItem_Constant_Int(5),
},
},
},
{
Alias: "matchSingleValue",
Type: parsers.SelectItemTypeFunctionCall,
Value: parsers.FunctionCall{
Type: parsers.FunctionCallArrayContainsAny,
Arguments: []interface{}{
testutils.SelectItem_Constant_Parameter("@numbers"),
testutils.SelectItem_Constant_Int(1),
},
},
},
{
Alias: "noMatches",
Type: parsers.SelectItemTypeFunctionCall,
Value: parsers.FunctionCall{
Type: parsers.FunctionCallArrayContainsAny,
Arguments: []interface{}{
testutils.SelectItem_Constant_Parameter("@numbers"),
testutils.SelectItem_Constant_Int(5),
testutils.SelectItem_Constant_Int(6),
testutils.SelectItem_Constant_Int(7),
testutils.SelectItem_Constant_Int(8),
},
},
},
{
Alias: "emptyArray",
Type: parsers.SelectItemTypeFunctionCall,
Value: parsers.FunctionCall{
Type: parsers.FunctionCallArrayContainsAny,
Arguments: []interface{}{
testutils.SelectItem_Constant_Parameter("@emptyArray"),
testutils.SelectItem_Constant_Int(1),
testutils.SelectItem_Constant_Int(2),
testutils.SelectItem_Constant_Int(3),
},
},
},
},
},
[]memoryexecutor.RowType{map[string]interface{}{"id": "123"}},
[]memoryexecutor.RowType{
map[string]interface{}{
"matchesEntireArray": true,
"matchesSomeValues": true,
"matchSingleValue": true,
"noMatches": false,
"emptyArray": false,
},
},
)
})
t.Run("Should execute function ARRAY_CONTAINS_ALL()", func(t *testing.T) {
testQueryExecute(
t,
parsers.SelectStmt{
Parameters: map[string]interface{}{
"@mixedArray": []interface{}{1, true, "3", []interface{}{1, 2, 3}},
"@numbers": []interface{}{1, 2, 3, 4},
"@emptyArray": []interface{}{},
"@arr123": []interface{}{1, 2, 3},
},
SelectItems: []parsers.SelectItem{
{
Alias: "matchesEntireArray",
Type: parsers.SelectItemTypeFunctionCall,
Value: parsers.FunctionCall{
Type: parsers.FunctionCallArrayContainsAll,
Arguments: []interface{}{
testutils.SelectItem_Constant_Parameter("@mixedArray"),
testutils.SelectItem_Constant_Int(1),
testutils.SelectItem_Constant_Bool(true),
testutils.SelectItem_Constant_String("3"),
testutils.SelectItem_Constant_Parameter("@arr123"),
},
},
},
{
Alias: "matchesSomeValues",
Type: parsers.SelectItemTypeFunctionCall,
Value: parsers.FunctionCall{
Type: parsers.FunctionCallArrayContainsAll,
Arguments: []interface{}{
testutils.SelectItem_Constant_Parameter("@numbers"),
testutils.SelectItem_Constant_Int(2),
testutils.SelectItem_Constant_Int(3),
testutils.SelectItem_Constant_Int(4),
testutils.SelectItem_Constant_Int(5),
},
},
},
{
Alias: "matchSingleValue",
Type: parsers.SelectItemTypeFunctionCall,
Value: parsers.FunctionCall{
Type: parsers.FunctionCallArrayContainsAll,
Arguments: []interface{}{
testutils.SelectItem_Constant_Parameter("@numbers"),
testutils.SelectItem_Constant_Int(1),
},
},
},
{
Alias: "noMatches",
Type: parsers.SelectItemTypeFunctionCall,
Value: parsers.FunctionCall{
Type: parsers.FunctionCallArrayContainsAll,
Arguments: []interface{}{
testutils.SelectItem_Constant_Parameter("@numbers"),
testutils.SelectItem_Constant_Int(5),
testutils.SelectItem_Constant_Int(6),
testutils.SelectItem_Constant_Int(7),
testutils.SelectItem_Constant_Int(8),
},
},
},
{
Alias: "emptyArray",
Type: parsers.SelectItemTypeFunctionCall,
Value: parsers.FunctionCall{
Type: parsers.FunctionCallArrayContainsAll,
Arguments: []interface{}{
testutils.SelectItem_Constant_Parameter("@emptyArray"),
testutils.SelectItem_Constant_Int(1),
testutils.SelectItem_Constant_Int(2),
testutils.SelectItem_Constant_Int(3),
},
},
},
},
},
[]memoryexecutor.RowType{map[string]interface{}{"id": "123"}},
[]memoryexecutor.RowType{
map[string]interface{}{
"matchesEntireArray": true,
"matchesSomeValues": false,
"matchSingleValue": true,
"noMatches": false,
"emptyArray": false,
},
},
)
})
t.Run("Should execute function ARRAY_LENGTH()", func(t *testing.T) { t.Run("Should execute function ARRAY_LENGTH()", func(t *testing.T) {
testQueryExecute( testQueryExecute(
t, t,
@ -386,8 +105,20 @@ func Test_Execute_ArrayFunctions(t *testing.T) {
Path: []string{"c", "arr2"}, Path: []string{"c", "arr2"},
Type: parsers.SelectItemTypeField, Type: parsers.SelectItemTypeField,
}, },
testutils.SelectItem_Constant_Int(1), parsers.SelectItem{
testutils.SelectItem_Constant_Int(2), Type: parsers.SelectItemTypeConstant,
Value: parsers.Constant{
Type: parsers.ConstantTypeInteger,
Value: 1,
},
},
parsers.SelectItem{
Type: parsers.SelectItemTypeConstant,
Value: parsers.Constant{
Type: parsers.ConstantTypeInteger,
Value: 2,
},
},
}, },
}, },
}, },

View File

@ -470,12 +470,6 @@ func (r rowContext) selectItem_SelectItemTypeFunctionCall(functionCall parsers.F
case parsers.FunctionCallArrayConcat: case parsers.FunctionCallArrayConcat:
return r.array_Concat(functionCall.Arguments) return r.array_Concat(functionCall.Arguments)
case parsers.FunctionCallArrayContains:
return r.array_Contains(functionCall.Arguments)
case parsers.FunctionCallArrayContainsAny:
return r.array_Contains_Any(functionCall.Arguments)
case parsers.FunctionCallArrayContainsAll:
return r.array_Contains_All(functionCall.Arguments)
case parsers.FunctionCallArrayLength: case parsers.FunctionCallArrayLength:
return r.array_Length(functionCall.Arguments) return r.array_Length(functionCall.Arguments)
case parsers.FunctionCallArraySlice: case parsers.FunctionCallArraySlice:

View File

@ -6,7 +6,6 @@ import (
"github.com/pikami/cosmium/parsers" "github.com/pikami/cosmium/parsers"
memoryexecutor "github.com/pikami/cosmium/query_executors/memory_executor" memoryexecutor "github.com/pikami/cosmium/query_executors/memory_executor"
testutils "github.com/pikami/cosmium/test_utils"
) )
func testQueryExecute( func testQueryExecute(
@ -112,8 +111,20 @@ func Test_Execute(t *testing.T) {
Path: []string{"c", "id"}, Path: []string{"c", "id"},
Type: parsers.SelectItemTypeField, Type: parsers.SelectItemTypeField,
}, },
testutils.SelectItem_Constant_String("123"), parsers.SelectItem{
testutils.SelectItem_Constant_String("456"), Type: parsers.SelectItemTypeConstant,
Value: parsers.Constant{
Type: parsers.ConstantTypeString,
Value: "123",
},
},
parsers.SelectItem{
Type: parsers.SelectItemTypeConstant,
Value: parsers.Constant{
Type: parsers.ConstantTypeString,
Value: "456",
},
},
}, },
}, },
}, },

View File

@ -5,7 +5,6 @@ import (
"github.com/pikami/cosmium/parsers" "github.com/pikami/cosmium/parsers"
memoryexecutor "github.com/pikami/cosmium/query_executors/memory_executor" memoryexecutor "github.com/pikami/cosmium/query_executors/memory_executor"
testutils "github.com/pikami/cosmium/test_utils"
) )
func Test_Execute_StringFunctions(t *testing.T) { func Test_Execute_StringFunctions(t *testing.T) {
@ -34,8 +33,20 @@ func Test_Execute_StringFunctions(t *testing.T) {
Path: []string{"c", "pk"}, Path: []string{"c", "pk"},
Type: parsers.SelectItemTypeField, Type: parsers.SelectItemTypeField,
}, },
testutils.SelectItem_Constant_String("aaa"), parsers.SelectItem{
testutils.SelectItem_Constant_Bool(true), Type: parsers.SelectItemTypeConstant,
Value: parsers.Constant{
Type: parsers.ConstantTypeString,
Value: "aaa",
},
},
parsers.SelectItem{
Type: parsers.SelectItemTypeConstant,
Value: parsers.Constant{
Type: parsers.ConstantTypeBoolean,
Value: true,
},
},
}, },
}, },
}, },
@ -70,7 +81,13 @@ func Test_Execute_StringFunctions(t *testing.T) {
Path: []string{"c", "pk"}, Path: []string{"c", "pk"},
Type: parsers.SelectItemTypeField, Type: parsers.SelectItemTypeField,
}, },
testutils.SelectItem_Constant_String("aaa"), parsers.SelectItem{
Type: parsers.SelectItemTypeConstant,
Value: parsers.Constant{
Type: parsers.ConstantTypeString,
Value: "aaa",
},
},
nil, nil,
}, },
}, },
@ -102,8 +119,20 @@ func Test_Execute_StringFunctions(t *testing.T) {
Path: []string{"c", "id"}, Path: []string{"c", "id"},
Type: parsers.SelectItemTypeField, Type: parsers.SelectItemTypeField,
}, },
testutils.SelectItem_Constant_String(" "), parsers.SelectItem{
testutils.SelectItem_Constant_Int(123), Type: parsers.SelectItemTypeConstant,
Value: parsers.Constant{
Type: parsers.ConstantTypeString,
Value: " ",
},
},
parsers.SelectItem{
Type: parsers.SelectItemTypeConstant,
Value: parsers.Constant{
Type: parsers.ConstantTypeString,
Value: 123,
},
},
parsers.SelectItem{ parsers.SelectItem{
Path: []string{"c", "pk"}, Path: []string{"c", "pk"},
Type: parsers.SelectItemTypeField, Type: parsers.SelectItemTypeField,
@ -142,8 +171,20 @@ func Test_Execute_StringFunctions(t *testing.T) {
Path: []string{"c", "id"}, Path: []string{"c", "id"},
Type: parsers.SelectItemTypeField, Type: parsers.SelectItemTypeField,
}, },
testutils.SelectItem_Constant_String("2"), parsers.SelectItem{
testutils.SelectItem_Constant_Bool(true), Type: parsers.SelectItemTypeConstant,
Value: parsers.Constant{
Type: parsers.ConstantTypeString,
Value: "2",
},
},
parsers.SelectItem{
Type: parsers.SelectItemTypeConstant,
Value: parsers.Constant{
Type: parsers.ConstantTypeBoolean,
Value: true,
},
},
}, },
}, },
}, },
@ -178,8 +219,20 @@ func Test_Execute_StringFunctions(t *testing.T) {
Path: []string{"c", "id"}, Path: []string{"c", "id"},
Type: parsers.SelectItemTypeField, Type: parsers.SelectItemTypeField,
}, },
testutils.SelectItem_Constant_String("3"), parsers.SelectItem{
testutils.SelectItem_Constant_Bool(true), Type: parsers.SelectItemTypeConstant,
Value: parsers.Constant{
Type: parsers.ConstantTypeString,
Value: "3",
},
},
parsers.SelectItem{
Type: parsers.SelectItemTypeConstant,
Value: parsers.Constant{
Type: parsers.ConstantTypeBoolean,
Value: true,
},
},
}, },
}, },
}, },
@ -214,8 +267,20 @@ func Test_Execute_StringFunctions(t *testing.T) {
Path: []string{"c", "id"}, Path: []string{"c", "id"},
Type: parsers.SelectItemTypeField, Type: parsers.SelectItemTypeField,
}, },
testutils.SelectItem_Constant_String("1"), parsers.SelectItem{
testutils.SelectItem_Constant_Bool(true), Type: parsers.SelectItemTypeConstant,
Value: parsers.Constant{
Type: parsers.ConstantTypeString,
Value: "1",
},
},
parsers.SelectItem{
Type: parsers.SelectItemTypeConstant,
Value: parsers.Constant{
Type: parsers.ConstantTypeBoolean,
Value: true,
},
},
}, },
}, },
}, },
@ -250,8 +315,20 @@ func Test_Execute_StringFunctions(t *testing.T) {
Path: []string{"c", "str"}, Path: []string{"c", "str"},
Type: parsers.SelectItemTypeField, Type: parsers.SelectItemTypeField,
}, },
testutils.SelectItem_Constant_String("o"), parsers.SelectItem{
testutils.SelectItem_Constant_Int(4), Type: parsers.SelectItemTypeConstant,
Value: parsers.Constant{
Type: parsers.ConstantTypeString,
Value: "o",
},
},
parsers.SelectItem{
Type: parsers.SelectItemTypeConstant,
Value: parsers.Constant{
Type: parsers.ConstantTypeInteger,
Value: 4,
},
},
}, },
}, },
}, },
@ -320,7 +397,13 @@ func Test_Execute_StringFunctions(t *testing.T) {
Path: []string{"c", "str"}, Path: []string{"c", "str"},
Type: parsers.SelectItemTypeField, Type: parsers.SelectItemTypeField,
}, },
testutils.SelectItem_Constant_Int(3), parsers.SelectItem{
Type: parsers.SelectItemTypeConstant,
Value: parsers.Constant{
Type: parsers.ConstantTypeInteger,
Value: 3,
},
},
}, },
}, },
}, },
@ -423,8 +506,20 @@ func Test_Execute_StringFunctions(t *testing.T) {
Path: []string{"c", "str"}, Path: []string{"c", "str"},
Type: parsers.SelectItemTypeField, Type: parsers.SelectItemTypeField,
}, },
testutils.SelectItem_Constant_String("world"), parsers.SelectItem{
testutils.SelectItem_Constant_String("universe"), Type: parsers.SelectItemTypeConstant,
Value: parsers.Constant{
Type: parsers.ConstantTypeString,
Value: "world",
},
},
parsers.SelectItem{
Type: parsers.SelectItemTypeConstant,
Value: parsers.Constant{
Type: parsers.ConstantTypeString,
Value: "universe",
},
},
}, },
}, },
}, },
@ -459,7 +554,13 @@ func Test_Execute_StringFunctions(t *testing.T) {
Path: []string{"c", "str"}, Path: []string{"c", "str"},
Type: parsers.SelectItemTypeField, Type: parsers.SelectItemTypeField,
}, },
testutils.SelectItem_Constant_Int(3), parsers.SelectItem{
Type: parsers.SelectItemTypeConstant,
Value: parsers.Constant{
Type: parsers.ConstantTypeInteger,
Value: 3,
},
},
}, },
}, },
}, },
@ -528,7 +629,13 @@ func Test_Execute_StringFunctions(t *testing.T) {
Path: []string{"c", "str"}, Path: []string{"c", "str"},
Type: parsers.SelectItemTypeField, Type: parsers.SelectItemTypeField,
}, },
testutils.SelectItem_Constant_Int(3), parsers.SelectItem{
Type: parsers.SelectItemTypeConstant,
Value: parsers.Constant{
Type: parsers.ConstantTypeInteger,
Value: 3,
},
},
}, },
}, },
}, },
@ -597,8 +704,20 @@ func Test_Execute_StringFunctions(t *testing.T) {
Path: []string{"c", "str"}, Path: []string{"c", "str"},
Type: parsers.SelectItemTypeField, Type: parsers.SelectItemTypeField,
}, },
testutils.SelectItem_Constant_Int(2), parsers.SelectItem{
testutils.SelectItem_Constant_Int(4), Type: parsers.SelectItemTypeConstant,
Value: parsers.Constant{
Type: parsers.ConstantTypeInteger,
Value: 2,
},
},
parsers.SelectItem{
Type: parsers.SelectItemTypeConstant,
Value: parsers.Constant{
Type: parsers.ConstantTypeInteger,
Value: 4,
},
},
}, },
}, },
}, },

View File

@ -5,7 +5,6 @@ import (
"github.com/pikami/cosmium/parsers" "github.com/pikami/cosmium/parsers"
memoryexecutor "github.com/pikami/cosmium/query_executors/memory_executor" memoryexecutor "github.com/pikami/cosmium/query_executors/memory_executor"
testutils "github.com/pikami/cosmium/test_utils"
) )
func Test_Execute_Where(t *testing.T) { func Test_Execute_Where(t *testing.T) {
@ -27,7 +26,10 @@ func Test_Execute_Where(t *testing.T) {
Filters: parsers.ComparisonExpression{ Filters: parsers.ComparisonExpression{
Operation: "=", Operation: "=",
Left: parsers.SelectItem{Path: []string{"c", "isCool"}}, Left: parsers.SelectItem{Path: []string{"c", "isCool"}},
Right: testutils.SelectItem_Constant_Bool(true), Right: parsers.SelectItem{
Type: parsers.SelectItemTypeConstant,
Value: parsers.Constant{Type: parsers.ConstantTypeBoolean, Value: true},
},
}, },
}, },
mockData, mockData,
@ -50,7 +52,10 @@ func Test_Execute_Where(t *testing.T) {
Filters: parsers.ComparisonExpression{ Filters: parsers.ComparisonExpression{
Operation: "=", Operation: "=",
Left: parsers.SelectItem{Path: []string{"c", "id"}}, Left: parsers.SelectItem{Path: []string{"c", "id"}},
Right: testutils.SelectItem_Constant_Parameter("@param_id"), Right: parsers.SelectItem{
Type: parsers.SelectItemTypeConstant,
Value: parsers.Constant{Type: parsers.ConstantTypeParameterConstant, Value: "@param_id"},
},
}, },
Parameters: map[string]interface{}{ Parameters: map[string]interface{}{
"@param_id": "456", "@param_id": "456",
@ -78,12 +83,18 @@ func Test_Execute_Where(t *testing.T) {
parsers.ComparisonExpression{ parsers.ComparisonExpression{
Operation: "=", Operation: "=",
Left: parsers.SelectItem{Path: []string{"c", "id"}}, Left: parsers.SelectItem{Path: []string{"c", "id"}},
Right: testutils.SelectItem_Constant_String("67890"), Right: parsers.SelectItem{
Type: parsers.SelectItemTypeConstant,
Value: parsers.Constant{Type: parsers.ConstantTypeString, Value: "67890"},
},
}, },
parsers.ComparisonExpression{ parsers.ComparisonExpression{
Operation: "=", Operation: "=",
Left: parsers.SelectItem{Path: []string{"c", "pk"}}, Left: parsers.SelectItem{Path: []string{"c", "pk"}},
Right: testutils.SelectItem_Constant_Int(456), Right: parsers.SelectItem{
Type: parsers.SelectItemTypeConstant,
Value: parsers.Constant{Type: parsers.ConstantTypeInteger, Value: 456},
},
}, },
}, },
}, },
@ -109,7 +120,10 @@ func Test_Execute_Where(t *testing.T) {
parsers.ComparisonExpression{ parsers.ComparisonExpression{
Operation: "=", Operation: "=",
Left: parsers.SelectItem{Path: []string{"c", "isCool"}}, Left: parsers.SelectItem{Path: []string{"c", "isCool"}},
Right: testutils.SelectItem_Constant_Bool(true), Right: parsers.SelectItem{
Type: parsers.SelectItemTypeConstant,
Value: parsers.Constant{Type: parsers.ConstantTypeBoolean, Value: true},
},
}, },
parsers.LogicalExpression{ parsers.LogicalExpression{
Operation: parsers.LogicalExpressionTypeOr, Operation: parsers.LogicalExpressionTypeOr,
@ -117,12 +131,18 @@ func Test_Execute_Where(t *testing.T) {
parsers.ComparisonExpression{ parsers.ComparisonExpression{
Operation: "=", Operation: "=",
Left: parsers.SelectItem{Path: []string{"c", "id"}}, Left: parsers.SelectItem{Path: []string{"c", "id"}},
Right: testutils.SelectItem_Constant_String("123"), Right: parsers.SelectItem{
Type: parsers.SelectItemTypeConstant,
Value: parsers.Constant{Type: parsers.ConstantTypeString, Value: "123"},
},
}, },
parsers.ComparisonExpression{ parsers.ComparisonExpression{
Operation: "=", Operation: "=",
Left: parsers.SelectItem{Path: []string{"c", "id"}}, Left: parsers.SelectItem{Path: []string{"c", "id"}},
Right: testutils.SelectItem_Constant_String("456"), Right: parsers.SelectItem{
Type: parsers.SelectItemTypeConstant,
Value: parsers.Constant{Type: parsers.ConstantTypeString, Value: "456"},
},
}, },
}, },
}, },

View File

@ -1,53 +0,0 @@
package testutils
import "github.com/pikami/cosmium/parsers"
func SelectItem_Constant_String(value string) parsers.SelectItem {
return parsers.SelectItem{
Type: parsers.SelectItemTypeConstant,
Value: parsers.Constant{
Type: parsers.ConstantTypeString,
Value: value,
},
}
}
func SelectItem_Constant_Int(value int) parsers.SelectItem {
return parsers.SelectItem{
Type: parsers.SelectItemTypeConstant,
Value: parsers.Constant{
Type: parsers.ConstantTypeInteger,
Value: value,
},
}
}
func SelectItem_Constant_Float(value float64) parsers.SelectItem {
return parsers.SelectItem{
Type: parsers.SelectItemTypeConstant,
Value: parsers.Constant{
Type: parsers.ConstantTypeFloat,
Value: value,
},
}
}
func SelectItem_Constant_Bool(value bool) parsers.SelectItem {
return parsers.SelectItem{
Type: parsers.SelectItemTypeConstant,
Value: parsers.Constant{
Type: parsers.ConstantTypeBoolean,
Value: value,
},
}
}
func SelectItem_Constant_Parameter(name string) parsers.SelectItem {
return parsers.SelectItem{
Type: parsers.SelectItemTypeConstant,
Value: parsers.Constant{
Type: parsers.ConstantTypeParameterConstant,
Value: name,
},
}
}