mirror of
https://gitee.com/milvus-io/milvus.git
synced 2024-12-02 11:59:00 +08:00
fix: comparision operations between incompatible operands (#35264)
fix: #34139 Signed-off-by: longjiquan <jiquan.long@zilliz.com>
This commit is contained in:
parent
885d891106
commit
976ceb4a46
@ -334,14 +334,19 @@ func (v *ParserVisitor) VisitEquality(ctx *parser.EqualityContext) interface{} {
|
|||||||
|
|
||||||
leftValue, rightValue := getGenericValue(left), getGenericValue(right)
|
leftValue, rightValue := getGenericValue(left), getGenericValue(right)
|
||||||
if leftValue != nil && rightValue != nil {
|
if leftValue != nil && rightValue != nil {
|
||||||
|
var ret *ExprWithType
|
||||||
switch ctx.GetOp().GetTokenType() {
|
switch ctx.GetOp().GetTokenType() {
|
||||||
case parser.PlanParserEQ:
|
case parser.PlanParserEQ:
|
||||||
return Equal(leftValue, rightValue)
|
ret = Equal(leftValue, rightValue)
|
||||||
case parser.PlanParserNE:
|
case parser.PlanParserNE:
|
||||||
return NotEqual(leftValue, rightValue)
|
ret = NotEqual(leftValue, rightValue)
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("unexpected op: %s", ctx.GetOp().GetText())
|
return fmt.Errorf("unexpected op: %s", ctx.GetOp().GetText())
|
||||||
}
|
}
|
||||||
|
if ret == nil {
|
||||||
|
return fmt.Errorf("comparison operations cannot be applied to two incompatible operands: %s", ctx.GetText())
|
||||||
|
}
|
||||||
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
var leftExpr *ExprWithType
|
var leftExpr *ExprWithType
|
||||||
@ -383,18 +388,23 @@ func (v *ParserVisitor) VisitRelational(ctx *parser.RelationalContext) interface
|
|||||||
leftValue, rightValue := getGenericValue(left), getGenericValue(right)
|
leftValue, rightValue := getGenericValue(left), getGenericValue(right)
|
||||||
|
|
||||||
if leftValue != nil && rightValue != nil {
|
if leftValue != nil && rightValue != nil {
|
||||||
|
var ret *ExprWithType
|
||||||
switch ctx.GetOp().GetTokenType() {
|
switch ctx.GetOp().GetTokenType() {
|
||||||
case parser.PlanParserLT:
|
case parser.PlanParserLT:
|
||||||
return Less(leftValue, rightValue)
|
ret = Less(leftValue, rightValue)
|
||||||
case parser.PlanParserLE:
|
case parser.PlanParserLE:
|
||||||
return LessEqual(leftValue, rightValue)
|
ret = LessEqual(leftValue, rightValue)
|
||||||
case parser.PlanParserGT:
|
case parser.PlanParserGT:
|
||||||
return Greater(leftValue, rightValue)
|
ret = Greater(leftValue, rightValue)
|
||||||
case parser.PlanParserGE:
|
case parser.PlanParserGE:
|
||||||
return GreaterEqual(leftValue, rightValue)
|
ret = GreaterEqual(leftValue, rightValue)
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("unexpected op: %s", ctx.GetOp().GetText())
|
return fmt.Errorf("unexpected op: %s", ctx.GetOp().GetText())
|
||||||
}
|
}
|
||||||
|
if ret == nil {
|
||||||
|
return fmt.Errorf("comparison operations cannot be applied to two incompatible operands: %s", ctx.GetText())
|
||||||
|
}
|
||||||
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
var leftExpr *ExprWithType
|
var leftExpr *ExprWithType
|
||||||
|
@ -500,6 +500,15 @@ func TestExpr_Invalid(t *testing.T) {
|
|||||||
//`1 < JSONField`,
|
//`1 < JSONField`,
|
||||||
`ArrayField > 2`,
|
`ArrayField > 2`,
|
||||||
`2 < ArrayField`,
|
`2 < ArrayField`,
|
||||||
|
// https://github.com/milvus-io/milvus/issues/34139
|
||||||
|
"\"Int64Field\" > 500 && \"Int64Field\" < 1000",
|
||||||
|
"\"Int64Field\" == 500 || \"Int64Field\" != 1000",
|
||||||
|
`"str" < 100`,
|
||||||
|
`"str" <= 100`,
|
||||||
|
`"str" > 100`,
|
||||||
|
`"str" >= 100`,
|
||||||
|
`"str" == 100`,
|
||||||
|
`"str" != 100`,
|
||||||
// ------------------------ like ------------------------
|
// ------------------------ like ------------------------
|
||||||
`(VarCharField % 2) like "prefix%"`,
|
`(VarCharField % 2) like "prefix%"`,
|
||||||
`FloatField like "prefix%"`,
|
`FloatField like "prefix%"`,
|
||||||
|
Loading…
Reference in New Issue
Block a user