fix: Correctly parse the minimum value of int64 (#41009)

issue: #40729 

Current approach to parse negative numbers is first parse the numeric
part and then multiply the result by -1(mainly to distinguish the
precedence of the negative sign and the subtraction operator). However,
for the minimum value of int64(`-9223372036854775808`), the value
`9223372036854775808` already exceeds the representable range of int64.
As a result, parsing error occurs.
Therefore, use a specific rule to match `-9223372036854775808`.

---------

Signed-off-by: Cai Zhang <cai.zhang@zilliz.com>
This commit is contained in:
cai.zhang 2025-04-08 16:36:26 +08:00 committed by GitHub
parent 758cf29e77
commit a7713df18d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 329 additions and 267 deletions

View File

@ -1,8 +1,8 @@
grammar Plan;
expr:
IntegerConstant # Integer
| FloatingConstant # Floating
(ADD | SUB)? IntegerConstant # Integer
| (ADD | SUB)? FloatingConstant # Floating
| BooleanConstant # Boolean
| StringLiteral # String
| (Identifier|Meta) # Identifier

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

View File

@ -98,7 +98,7 @@ func (v *ParserVisitor) VisitBoolean(ctx *parser.BooleanContext) interface{} {
// VisitInteger translates expr to GenericValue.
func (v *ParserVisitor) VisitInteger(ctx *parser.IntegerContext) interface{} {
literal := ctx.IntegerConstant().GetText()
literal := ctx.GetText()
i, err := strconv.ParseInt(literal, 0, 64)
if err != nil {
return err
@ -118,7 +118,7 @@ func (v *ParserVisitor) VisitInteger(ctx *parser.IntegerContext) interface{} {
// VisitFloating translates expr to GenericValue.
func (v *ParserVisitor) VisitFloating(ctx *parser.FloatingContext) interface{} {
literal := ctx.FloatingConstant().GetText()
literal := ctx.GetText()
f, err := strconv.ParseFloat(literal, 64)
if err != nil {
return err

View File

@ -194,6 +194,7 @@ func TestExpr_UnaryRange(t *testing.T) {
`VarCharField <= "str7"`,
`JSONField["A"] > 10`,
`$meta["A"] > 10`,
`A == -9223372036854775808`,
}
for _, exprStr := range exprStrs {
assertValidExpr(t, helper, exprStr)