-
Notifications
You must be signed in to change notification settings - Fork 173
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
fix: modulo op with negative zero divisor produces Nan #585
Conversation
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.
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. |
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.
Thank you @vaibhawvipul
spark/src/test/scala/org/apache/comet/CometExpressionSuite.scala
Outdated
Show resolved
Hide resolved
spark/src/test/scala/org/apache/comet/CometExpressionSuite.scala
Outdated
Show resolved
Hide resolved
spark/src/main/scala/org/apache/comet/serde/QueryPlanSerde.scala
Outdated
Show resolved
Hide resolved
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We may need to test !=
and <=>
as well, but can be a separate PR
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.
sure, I will create a different PR for it.
spark/src/main/scala/org/apache/comet/serde/QueryPlanSerde.scala
Outdated
Show resolved
Hide resolved
spark/src/main/scala/org/apache/comet/serde/QueryPlanSerde.scala
Outdated
Show resolved
Hide resolved
spark/src/main/scala/org/apache/comet/serde/QueryPlanSerde.scala
Outdated
Show resolved
Hide resolved
spark/src/main/scala/org/apache/comet/serde/QueryPlanSerde.scala
Outdated
Show resolved
Hide resolved
spark/src/main/scala/org/apache/comet/serde/QueryPlanSerde.scala
Outdated
Show resolved
Hide resolved
spark/src/main/scala/org/apache/comet/serde/QueryPlanSerde.scala
Outdated
Show resolved
Hide resolved
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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?
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.