diff --git a/internal/parser/planparserv2/plan_parser_v2_test.go b/internal/parser/planparserv2/plan_parser_v2_test.go index a7fb176391347..292924a6e84ef 100644 --- a/internal/parser/planparserv2/plan_parser_v2_test.go +++ b/internal/parser/planparserv2/plan_parser_v2_test.go @@ -938,7 +938,6 @@ func Test_JSONContains(t *testing.T) { `JSON_CONTAINS(JSONField["x"], 5)`, `json_contains(A, [1,2,3])`, `array_contains(A, [1,2,3])`, - `array_contains(ArrayField, [1,2,3])`, `array_contains(ArrayField, 1)`, `json_contains(JSONField, 5)`, `json_contains($meta, 1)`, @@ -973,6 +972,8 @@ func Test_InvalidJSONContains(t *testing.T) { `json_contains(A, 5, C)`, `json_Contains(JSONField, 5)`, `JSON_contains(JSONField, 5)`, + `json_contains(ArrayField, "abc")`, + `json_contains(ArrayField, [1,2])`, } for _, expr = range exprs { _, err = CreateSearchPlan(schema, expr, "FloatVectorField", &planpb.QueryInfo{ @@ -1078,7 +1079,7 @@ func Test_JSONContainsAll(t *testing.T) { `JSON_CONTAINS_ALL(A, [1,"2",3.0])`, `array_contains_all(ArrayField, [1,2,3])`, `array_contains_all(ArrayField, [1])`, - `json_contains_all(ArrayField, [1,2,3])`, + `array_contains_all(ArrayField, [1,2,3])`, } for _, expr = range exprs { plan, err = CreateSearchPlan(schema, expr, "FloatVectorField", &planpb.QueryInfo{ @@ -1100,6 +1101,7 @@ func Test_JSONContainsAll(t *testing.T) { `JSON_CONTAINS_ALL(A[""], [1,2,3])`, `JSON_CONTAINS_ALL(Int64Field, [1,2,3])`, `JSON_CONTAINS_ALL(A, B)`, + `JSON_CONTAINS_ALL(ArrayField, [[1,2,3]])`, } for _, expr = range invalidExprs { _, err = CreateSearchPlan(schema, expr, "FloatVectorField", &planpb.QueryInfo{ @@ -1123,8 +1125,6 @@ func Test_JSONContainsAny(t *testing.T) { `json_contains_any(A, [1,"2",3.0])`, `JSON_CONTAINS_ANY(A, [1,"2",3.0])`, `JSON_CONTAINS_ANY(ArrayField, [1,2,3])`, - `JSON_CONTAINS_ANY(ArrayField, [3,4,5])`, - `JSON_CONTAINS_ANY(ArrayField, [1,2,3])`, } for _, expr = range exprs { plan, err = CreateSearchPlan(schema, expr, "FloatVectorField", &planpb.QueryInfo{ @@ -1145,6 +1145,7 @@ func Test_JSONContainsAny(t *testing.T) { `JSON_CONTAINS_ANY(A, [2>>a])`, `JSON_CONTAINS_ANY(A[""], [1,2,3])`, `JSON_CONTAINS_ANY(Int64Field, [1,2,3])`, + `JSON_CONTAINS_ANY(ArrayField, [[1,2,3]])`, `JSON_CONTAINS_ANY(A, B)`, } for _, expr = range invalidExprs { diff --git a/internal/parser/planparserv2/utils.go b/internal/parser/planparserv2/utils.go index 80e7239ba2d73..dab5a55f8fded 100644 --- a/internal/parser/planparserv2/utils.go +++ b/internal/parser/planparserv2/utils.go @@ -664,16 +664,21 @@ func checkContainsElement(columnExpr *ExprWithType, op planpb.JSONContainsExpr_J if typeutil.IsArrayType(columnExpr.expr.GetColumnExpr().GetInfo().GetDataType()) { var elements []*planpb.GenericValue if op == planpb.JSONContainsExpr_Contains { - elements = []*planpb.GenericValue{elementValue} + castedValue, err := castValue(columnExpr.expr.GetColumnExpr().GetInfo().GetElementType(), elementValue) + if err != nil { + return err + } + elements = []*planpb.GenericValue{castedValue} } else { elements = elementValue.GetArrayVal().GetArray() } + arrayElementType := columnExpr.expr.GetColumnExpr().GetInfo().GetElementType() for _, value := range elements { valExpr := toValueExpr(value) - if !canBeCompared(columnExpr, valExpr) { + if !canBeComparedDataType(arrayElementType, valExpr.dataType) { return fmt.Errorf("%s operation can't compare between array element type: %s and %s", op.String(), - columnExpr.expr.GetColumnExpr().GetInfo().GetElementType(), + arrayElementType, valExpr.dataType) } }