mirror of https://github.com/milvus-io/milvus.git
enhance: [2.4] Refine error message for contains array (#37443)
issue: #36221 master pr: #37383 Signed-off-by: Cai Zhang <cai.zhang@zilliz.com>pull/37471/head^2
parent
20534a3f7b
commit
4ae5337343
|
@ -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 {
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue