mirror of
https://gitee.com/milvus-io/milvus.git
synced 2024-11-30 02:48:45 +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)
|
||||
if leftValue != nil && rightValue != nil {
|
||||
var ret *ExprWithType
|
||||
switch ctx.GetOp().GetTokenType() {
|
||||
case parser.PlanParserEQ:
|
||||
return Equal(leftValue, rightValue)
|
||||
ret = Equal(leftValue, rightValue)
|
||||
case parser.PlanParserNE:
|
||||
return NotEqual(leftValue, rightValue)
|
||||
ret = NotEqual(leftValue, rightValue)
|
||||
default:
|
||||
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
|
||||
@ -383,18 +388,23 @@ func (v *ParserVisitor) VisitRelational(ctx *parser.RelationalContext) interface
|
||||
leftValue, rightValue := getGenericValue(left), getGenericValue(right)
|
||||
|
||||
if leftValue != nil && rightValue != nil {
|
||||
var ret *ExprWithType
|
||||
switch ctx.GetOp().GetTokenType() {
|
||||
case parser.PlanParserLT:
|
||||
return Less(leftValue, rightValue)
|
||||
ret = Less(leftValue, rightValue)
|
||||
case parser.PlanParserLE:
|
||||
return LessEqual(leftValue, rightValue)
|
||||
ret = LessEqual(leftValue, rightValue)
|
||||
case parser.PlanParserGT:
|
||||
return Greater(leftValue, rightValue)
|
||||
ret = Greater(leftValue, rightValue)
|
||||
case parser.PlanParserGE:
|
||||
return GreaterEqual(leftValue, rightValue)
|
||||
ret = GreaterEqual(leftValue, rightValue)
|
||||
default:
|
||||
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
|
||||
|
@ -500,6 +500,15 @@ func TestExpr_Invalid(t *testing.T) {
|
||||
//`1 < JSONField`,
|
||||
`ArrayField > 2`,
|
||||
`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 ------------------------
|
||||
`(VarCharField % 2) like "prefix%"`,
|
||||
`FloatField like "prefix%"`,
|
||||
|
Loading…
Reference in New Issue
Block a user