-
Notifications
You must be signed in to change notification settings - Fork 5.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
expression: fix out of range error for real number #5295
Conversation
Hi contributor, thanks for your PR. This patch needs to be approved by someone of admins. They should reply with "/ok-to-test" to accept this PR for running test automatically. |
/ok-to-test |
/run-all-tests |
/run-all-tests |
expression/builtin_arithmetic.go
Outdated
@@ -594,6 +603,7 @@ func (c *arithmeticIntDivideFunctionClass) getFunction(ctx context.Context, args | |||
} | |||
|
|||
type builtinArithmeticIntDivideIntSig struct{ baseBuiltinFunc } | |||
type builtinArithmeticRealDivideRealSig struct{ baseBuiltinFunc } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the IntDivide
represents the DIV
operator, so the name should be IntDivideRealSig
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right. PTAL.
return 0, isNull, errors.Trace(err) | ||
} | ||
|
||
if b == 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You may need to handle the case as follows:
mysql> select (1 div 1E-82);
+---------------+
| (1 div 1E-82) |
+---------------+
| NULL |
+---------------+
1 row in set, 1 warning (0.00 sec)
mysql> show warnings;
+---------+------+---------------+
| Level | Code | Message |
+---------+------+---------------+
| Warning | 1365 | Division by 0 |
+---------+------+---------------+
1 row in set (0.00 sec)
Or you can add a TODO
here.
expression/builtin_arithmetic.go
Outdated
@@ -594,6 +603,7 @@ func (c *arithmeticIntDivideFunctionClass) getFunction(ctx context.Context, args | |||
} | |||
|
|||
type builtinArithmeticIntDivideIntSig struct{ baseBuiltinFunc } | |||
type builtinArithmeticRealDivideRealSig struct{ baseBuiltinFunc } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/builtinArithmeticRealDivideRealSig/builtinArithmeticIntDivideRealSig
LGTM |
sc := s.ctx.GetSessionVars().StmtCtx | ||
b, isNull, err := s.args[1].EvalReal(row, sc) | ||
if isNull || err != nil { | ||
return 0, isNull, errors.Trace(err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return 0, true, errors.Trace(err)
is more specific
|
||
a, isNull, err := s.args[0].EvalReal(row, sc) | ||
if isNull || err != nil { | ||
return 0, isNull, errors.Trace(err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
func DivFloat64(a float64, b float64) (int64, error) { | ||
c := a / b | ||
if c > math.MaxInt64 || c < math.MinInt64 { | ||
return 0, ErrOverflow.GenByArgs("BIGINT", fmt.Sprintf("(%f, %f)", a, b)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add a test like "select (1 div 1E-20);" and check the error message.
maybe I will revert |
@mccxj |
@mccxj any update ? |
@zz-jason I will open another PR to continue working. |
for #4477
This change is