Skip to content
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

tree: add missing div-by-zero error for float div #37774

Merged
merged 1 commit into from May 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/sql/logictest/testdata/logic_test/order_by
Expand Up @@ -307,7 +307,7 @@ statement ok
CREATE TABLE nan (id INT PRIMARY KEY, x REAL)

statement ok
INSERT INTO nan VALUES (1, 0/0), (2, -1), (3, 1), (4, 0/0)
INSERT INTO nan VALUES (1, 'NaN'), (2, -1), (3, 1), (4, 'NaN')

query R
SELECT x FROM nan ORDER BY x
Expand Down
2 changes: 0 additions & 2 deletions pkg/sql/sem/tree/datum_test.go
Expand Up @@ -78,8 +78,6 @@ func TestDatumOrdering(t *testing.T) {
{`3.14:::float`, `3.1399999999999997`, `3.1400000000000006`, `NaN`, `+Inf`},
{`9.223372036854776e+18:::float`, `9.223372036854775e+18`, `9.223372036854778e+18`, `NaN`, `+Inf`},
{`'NaN':::float`, valIsMin, `-Inf`, `NaN`, `+Inf`},
{`-(1:::float/0)`, `NaN`, `-1.7976931348623157e+308`, `NaN`, `+Inf`},
{`(1:::float/0)`, `1.7976931348623157e+308`, valIsMax, `NaN`, `+Inf`},
{`-1.7976931348623157e+308:::float`, `-Inf`, `-1.7976931348623155e+308`, `NaN`, `+Inf`},
{`1.7976931348623157e+308:::float`, `1.7976931348623155e+308`, `+Inf`, `NaN`, `+Inf`},

Expand Down
6 changes: 5 additions & 1 deletion pkg/sql/sem/tree/eval.go
Expand Up @@ -1116,7 +1116,11 @@ var BinOps = map[BinaryOperator]binOpOverload{
RightType: types.Float,
ReturnType: types.Float,
Fn: func(_ *EvalContext, left Datum, right Datum) (Datum, error) {
return NewDFloat(*left.(*DFloat) / *right.(*DFloat)), nil
r := *right.(*DFloat)
if r == 0.0 {
return nil, ErrDivByZero
}
return NewDFloat(*left.(*DFloat) / r), nil
},
},
&BinOp{
Expand Down
1 change: 1 addition & 0 deletions pkg/sql/sem/tree/eval_test.go
Expand Up @@ -252,6 +252,7 @@ func TestEvalError(t *testing.T) {
}{
{`1 % 0`, `zero modulus`},
{`1 / 0`, `division by zero`},
{`1::float / 0::float`, `division by zero`},
{`1 // 0`, `division by zero`},
{`1.5 / 0`, `division by zero`},
{`'11h2m'::interval / 0`, `division by zero`},
Expand Down
10 changes: 0 additions & 10 deletions pkg/sql/sem/tree/testdata/eval/infinity
@@ -1,13 +1,3 @@
eval
1.0:::float / 0.0
----
+Inf

eval
-1.0:::float * (1.0:::float / 0.0)
----
-Inf

eval
power(0::decimal, -1)
----
Expand Down