Skip to content

Commit

Permalink
Refine error message for contains
Browse files Browse the repository at this point in the history
Signed-off-by: Cai Zhang <[email protected]>
  • Loading branch information
xiaocai2333 committed Nov 2, 2024
1 parent b792b19 commit 02e5cce
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
7 changes: 3 additions & 4 deletions internal/parser/planparserv2/plan_parser_v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -976,7 +976,6 @@ func Test_JSONContains(t *testing.T) {
`JSON_contains(JSONField, 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)`,
Expand Down Expand Up @@ -1009,6 +1008,8 @@ func Test_InvalidJSONContains(t *testing.T) {
`json_contains(A, StringField > 5)`,
`json_contains(A)`,
`json_contains(A, 5, C)`,
`json_contains(ArrayField, "abc")`,
`json_contains(ArrayField, [1,2])`,
}
for _, expr = range exprs {
_, err = CreateSearchPlan(schema, expr, "FloatVectorField", &planpb.QueryInfo{
Expand Down Expand Up @@ -1114,7 +1115,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{
Expand Down Expand Up @@ -1159,8 +1160,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{
Expand Down
6 changes: 5 additions & 1 deletion internal/parser/planparserv2/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,11 @@ 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()
}
Expand Down

0 comments on commit 02e5cce

Please sign in to comment.