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 4, 2024
1 parent 0c4321c commit 16360fe
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
9 changes: 5 additions & 4 deletions internal/parser/planparserv2/plan_parser_v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -997,7 +997,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 @@ -1030,6 +1029,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 @@ -1135,7 +1136,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 All @@ -1157,6 +1158,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{
Expand All @@ -1180,8 +1182,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 All @@ -1202,6 +1202,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 {
Expand Down
11 changes: 8 additions & 3 deletions internal/parser/planparserv2/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -665,16 +665,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)
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/python_client/testcases/test_mix_scenes.py
Original file line number Diff line number Diff line change
Expand Up @@ -889,11 +889,11 @@ def test_bitmap_index_query_with_invalid_array_params(self):
# query
self.collection_wrap.query(
expr=Expr.array_contains_any('ARRAY_VARCHAR', [['a', 'b']]).value, limit=1, check_task=CheckTasks.err_res,
check_items={ct.err_code: 65535, ct.err_msg: "fail to Query on QueryNode"})
check_items={ct.err_code: 1100, ct.err_msg: qem.ParseExpressionFailed})

self.collection_wrap.query(
expr=Expr.array_contains_all('ARRAY_VARCHAR', [['a', 'b']]).value, limit=1, check_task=CheckTasks.err_res,
check_items={ct.err_code: 65535, ct.err_msg: "fail to Query on QueryNode"})
check_items={ct.err_code: 1100, ct.err_msg: qem.ParseExpressionFailed})

self.collection_wrap.query(
expr=Expr.array_contains('ARRAY_VARCHAR', [['a', 'b']]).value, limit=1, check_task=CheckTasks.err_res,
Expand Down

0 comments on commit 16360fe

Please sign in to comment.