Fix ARRAY_CONTAINS partial matches for nested objects

This commit is contained in:
Pijus Kamandulis 2025-02-03 19:29:29 +02:00
parent 8657c48fc8
commit 3fee3bc816
2 changed files with 23 additions and 9 deletions

View File

@ -220,7 +220,7 @@ func (r rowContext) partialMatch(item interface{}, exprToSearch interface{}) boo
} }
for _, key := range exprValue.MapKeys() { for _, key := range exprValue.MapKeys() {
if itemValue.MapIndex(key).Interface() != exprValue.MapIndex(key).Interface() { if !reflect.DeepEqual(itemValue.MapIndex(key).Interface(), exprValue.MapIndex(key).Interface()) {
return false return false
} }
} }

View File

@ -59,10 +59,11 @@ func Test_Execute_ArrayFunctions(t *testing.T) {
parsers.SelectStmt{ parsers.SelectStmt{
Parameters: map[string]interface{}{ Parameters: map[string]interface{}{
"@categories": []interface{}{"coats", "jackets", "sweatshirts"}, "@categories": []interface{}{"coats", "jackets", "sweatshirts"},
"@objectArray": []interface{}{map[string]interface{}{"category": "shirts", "color": "blue"}}, "@objectArray": []interface{}{map[string]interface{}{"category": "shirts", "color": "blue", "nestedObject": map[string]interface{}{"size": "M"}}},
"@fullMatchObject": map[string]interface{}{"category": "shirts", "color": "blue"}, "@fullMatchObject": map[string]interface{}{"category": "shirts", "color": "blue", "nestedObject": map[string]interface{}{"size": "M"}},
"@partialMatchObject": map[string]interface{}{"category": "shirts"}, "@partialMatchObject": map[string]interface{}{"category": "shirts"},
"@missingPartialMatchObject": map[string]interface{}{"category": "shorts", "color": "blue"}, "@missingPartialMatchObject": map[string]interface{}{"category": "shorts", "color": "blue"},
"@nestedPartialMatchObject": map[string]interface{}{"nestedObject": map[string]interface{}{"size": "M"}},
}, },
SelectItems: []parsers.SelectItem{ SelectItems: []parsers.SelectItem{
{ {
@ -133,17 +134,30 @@ func Test_Execute_ArrayFunctions(t *testing.T) {
}, },
}, },
}, },
{
Alias: "ContainsNestedPartialMatchObject",
Type: parsers.SelectItemTypeFunctionCall,
Value: parsers.FunctionCall{
Type: parsers.FunctionCallArrayContains,
Arguments: []interface{}{
testutils.SelectItem_Constant_Parameter("@objectArray"),
testutils.SelectItem_Constant_Parameter("@nestedPartialMatchObject"),
testutils.SelectItem_Constant_Bool(true),
},
},
},
}, },
}, },
[]memoryexecutor.RowType{map[string]interface{}{"id": "123"}}, []memoryexecutor.RowType{map[string]interface{}{"id": "123"}},
[]memoryexecutor.RowType{ []memoryexecutor.RowType{
map[string]interface{}{ map[string]interface{}{
"ContainsItem": true, "ContainsItem": true,
"MissingItem": false, "MissingItem": false,
"ContainsFullMatchObject": true, "ContainsFullMatchObject": true,
"MissingFullMatchObject": false, "MissingFullMatchObject": false,
"ContainsPartialMatchObject": true, "ContainsPartialMatchObject": true,
"MissingPartialMatchObject": false, "MissingPartialMatchObject": false,
"ContainsNestedPartialMatchObject": true,
}, },
}, },
) )