Add error return with invalid bool expr (#12168)

Signed-off-by: fishpenguin <kun.yu@zilliz.com>
pull/12178/head
yukun 2021-11-22 16:57:15 +08:00 committed by GitHub
parent 4121e31df1
commit e9585625e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View File

@ -573,8 +573,10 @@ func (pc *parserContext) handleLeafValue(nodeRaw *ant_ast.Node, dataType schemap
}
if node.Value == 1 {
gv.Val.(*planpb.GenericValue_BoolVal).BoolVal = true
} else {
} else if node.Value == 0 {
gv.Val.(*planpb.GenericValue_BoolVal).BoolVal = false
} else {
return nil, fmt.Errorf("bool field should only match 0 or 1")
}
} else {
return nil, fmt.Errorf("type mismatch")

View File

@ -253,6 +253,10 @@ func TestExprMultiRange_Str(t *testing.T) {
"BoolN1 == 1",
"BoolN1 == 0",
}
invalidExprs := []string{
"BoolN1 == 2",
"BoolN1 > 2",
}
fields := []*schemapb.FieldSchema{
{FieldID: 100, Name: "fakevec", DataType: schemapb.DataType_FloatVector},
@ -283,6 +287,13 @@ func TestExprMultiRange_Str(t *testing.T) {
dbgStr := proto.MarshalTextString(planProto)
println(dbgStr)
}
for offset, exprStr := range invalidExprs {
fmt.Printf("invalid case %d: %s\n", offset, exprStr)
planProto, err := createQueryPlan(schema, exprStr, "fakevec", queryInfo)
assert.Error(t, err)
dbgStr := proto.MarshalTextString(planProto)
println(dbgStr)
}
}
func TestExprFieldCompare_Str(t *testing.T) {