Add more unittest for proxy/plan_parser (#8534)

Signed-off-by: yudong.cai <yudong.cai@zilliz.com>
pull/8535/head
Cai Yudong 2021-09-25 13:43:56 +08:00 committed by GitHub
parent 3e487bde0b
commit 9497ba5523
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 97 additions and 6 deletions

View File

@ -50,15 +50,106 @@ func newTestSchema() *schemapb.CollectionSchema {
}
}
func TestParseQueryExpr_Naive(t *testing.T) {
exprStr := "Int64Field > 3"
func TestParseExpr_Naive(t *testing.T) {
schemaPb := newTestSchema()
schema, err := typeutil.CreateSchemaHelper(schemaPb)
assert.Nil(t, err)
exprProto, err := parseExpr(schema, exprStr)
assert.Nil(t, err)
str := proto.MarshalTextString(exprProto)
println(str)
t.Run("test UnaryNode", func(t *testing.T) {
exprStrs := []string{
"Int64Field > +1",
"Int64Field > -1",
"FloatField > +1.0",
"FloatField > -1.0",
}
for _, exprStr := range exprStrs {
exprProto, err := parseExpr(schema, exprStr)
assert.Nil(t, err)
str := proto.MarshalTextString(exprProto)
println(str)
}
})
t.Run("test UnaryNode invalid", func(t *testing.T) {
exprStrs := []string{
"Int64Field > +aa",
"FloatField > -aa",
}
for _, exprStr := range exprStrs {
exprProto, err := parseExpr(schema, exprStr)
assert.Error(t, err)
assert.Nil(t, exprProto)
}
})
t.Run("test BinaryNode", func(t *testing.T) {
exprStrs := []string{
// "+"
"FloatField > 1 + 2",
"FloatField > 1 + 2.0",
"FloatField > 1.0 + 2",
"FloatField > 1.0 + 2.0",
// "-"
"FloatField > 1 - 2",
"FloatField > 1 - 2.0",
"FloatField > 1.0 - 2",
"FloatField > 1.0 - 2.0",
// "*"
"FloatField > 1 * 2",
"FloatField > 1 * 2.0",
"FloatField > 1.0 * 2",
"FloatField > 1.0 * 2.0",
// "/"
"FloatField > 1 / 2",
"FloatField > 1 / 2.0",
"FloatField > 1.0 / 2",
"FloatField > 1.0 / 2.0",
// "%"
"FloatField > 1 % 2",
// "**"
"FloatField > 1 ** 2",
"FloatField > 1 ** 2.0",
"FloatField > 1.0 ** 2",
"FloatField > 1.0 ** 2.0",
}
for _, exprStr := range exprStrs {
exprProto, err := parseExpr(schema, exprStr)
assert.Nil(t, err)
str := proto.MarshalTextString(exprProto)
println(str)
}
})
t.Run("test BinaryNode invalid", func(t *testing.T) {
exprStrs := []string{
// "+"
"FloatField > 1 + aa",
"FloatField > aa + 2.0",
// "-"
"FloatField > 1 - aa",
"FloatField > aa - 2.0",
// "*"
"FloatField > 1 * aa",
"FloatField > aa * 2.0",
// "/"
"FloatField > 1 / 0",
"FloatField > 1 / 0.0",
"FloatField > 1.0 / 0",
"FloatField > 1.0 / 0.0",
"FloatField > 1 / aa",
"FloatField > aa / 2.0",
// "%"
"FloatField > 1 % aa",
// "**"
"FloatField > 1 ** aa",
"FloatField > aa ** 2.0",
}
for _, exprStr := range exprStrs {
exprProto, err := parseExpr(schema, exprStr)
assert.Error(t, err)
assert.Nil(t, exprProto)
}
})
}
func TestParsePlanNode_Naive(t *testing.T) {