fix: modulo op with negative zero divisor produces Nan#585
fix: modulo op with negative zero divisor produces Nan#585vaibhawvipul wants to merge 22 commits intoapache:mainfrom
Conversation
comphead
left a comment
There was a problem hiding this comment.
imho it has to be fixed on DataFusion side. I can see it returns NaN
> select 1 % -0.0;
+------------------------+
| Int64(1) % Float64(-0) |
+------------------------+
| NaN |
+------------------------+
PG, Trino fails on such query,
DuckDB, Spark returns NULL
I'll start a ticket in DF, if community supports to go with NULL, so no action needed for this ticket, if they decide to fail the query we might need some custom handling
|
Filed apache/datafusion#11051 lets see |
Make sense. I will keep my PR as it then until we get some resolution on the datafusion ticket. Thank you @comphead |
|
The direct reason why DataFusion changed their behavior several versions ago, to fail for dividing by zero. The DataFusion community recommendation to keep old behavior was to put if condition such as I would say we should do something like
|
makes a lot of sense. I have made a fix as per your comments. please review @kazuyukitanimura |
|
can someone please re-run the CI? It seems like a task failed because of network error. |
kazuyukitanimura
left a comment
There was a problem hiding this comment.
Thank you @vaibhawvipul
|
@kazuyukitanimura ready for review |
| (-1.0, 0.0), | ||
| (0.0, -1.0)), | ||
| "t") { | ||
| checkSparkAnswerAndOperator("SELECT _1 == _2 FROM t") |
There was a problem hiding this comment.
We may need to test != and <=>as well, but can be a separate PR
There was a problem hiding this comment.
sure, I will create a different PR for it.
|
@kazuyukitanimura ready for review. |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #585 +/- ##
============================================
- Coverage 34.13% 34.08% -0.06%
+ Complexity 809 796 -13
============================================
Files 106 108 +2
Lines 38586 38767 +181
Branches 8566 8581 +15
============================================
+ Hits 13172 13212 +40
- Misses 22674 22799 +125
- Partials 2740 2756 +16 ☔ View full report in Codecov by Sentry. |
|
@kazuyukitanimura could you please review once? CI passed. |
|
@vaibhawvipul Sorry, I got busy with something else. I may be unable to review or work on OSS a week or two. |
| builder.setRight(rightExpr.get) | ||
| val leftExpr = | ||
| if (left.dataType == DoubleType || left.dataType == FloatType) { | ||
| exprToProtoInternal(If(EqualTo(left, negZeroLeft), leftZero, left), inputs) |
There was a problem hiding this comment.
Hmm exprToProtoInternal recursively gets executed and EqualTo(left, negZeroLeft) will match the above case-match and gets converted at
case (_, `negZeroRight`) =>
return buildEqualExpr(
exprToProtoInternal(left, inputs),
exprToProtoInternal(Abs(right).child, inputs))
??
There was a problem hiding this comment.
Hmmm still trying to understand how this recursion works...
|
@andygrove / @kazuyukitanimura can we please get CI triggered? and also a review? |
| case (_, `negZeroRight`) => | ||
| return buildEqualExpr( | ||
| exprToProtoInternal(left, inputs), | ||
| exprToProtoInternal(Abs(right).child, inputs)) |
There was a problem hiding this comment.
Do you mind explaining why we need Abs(right).child? I thought Abs(right).child == right
| // also return none if one side is nullable and the other is not | ||
| if ((left.nullable && !right.nullable) && |
There was a problem hiding this comment.
What is the reason of the left.nullable && !right.nullable requirement?
| builder.setRight(rightExpr.get) | ||
| val leftExpr = | ||
| if (left.dataType == DoubleType || left.dataType == FloatType) { | ||
| exprToProtoInternal(If(EqualTo(left, negZeroLeft), leftZero, left), inputs) |
There was a problem hiding this comment.
Hmmm still trying to understand how this recursion works...
|
The main issue was fixed by #953 |
|
Please never mind my comment above, I posted a workaroud PR #960 |
|
@kazuyukitanimura can we close it? |
## Which issue does this PR close? Image builds weren't kicked off for the last release ## Rationale for this change The `ARTIFACT_VERSION` is extracted as part of the environment setup, but was not passed along as intended. ## What changes are included in this PR? Image builds weren't called automatically for the last release build (`0.8.0.0-apple`) because the `build-artifacts` job prior to the image builds did not include passing the `ARTIFACT_VERSION` ## How are these changes tested? YAML was validated by yq, and the Rio file was validated by Rio
Which issue does this PR close?
Closes #521 and #665.
Rationale for this change
What changes are included in this PR?
Improves compatibility with apache spark.
How are these changes tested?
Added a relevant test case.