-
Notifications
You must be signed in to change notification settings - Fork 184
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
feat: Support IntegralDivide function #1428
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1428 +/- ##
============================================
+ Coverage 56.12% 58.55% +2.43%
- Complexity 976 1015 +39
============================================
Files 119 122 +3
Lines 11743 12249 +506
Branches 2251 2304 +53
============================================
+ Hits 6591 7173 +582
+ Misses 4012 3919 -93
- Partials 1140 1157 +17 ☔ View full report in Codecov by Sentry. |
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 @wForget
Integral divide of test:
Results do not match:
This is due to the rounding behavior of datafusion-comet/native/spark-expr/src/math_funcs/div.rs Lines 72 to 76 in 58a36b6
|
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 we need to update https://github.com/apache/datafusion-comet/blob/main/spark/src/main/scala/org/apache/spark/sql/comet/DecimalPrecision.scala
?
Additionally https://github.com/apache/datafusion-comet/blob/main/spark/src/test/scala/org/apache/comet/CometExpressionSuite.scala#L1793 Decimal random number tests
is another good test to extend
@@ -922,13 +956,18 @@ impl PhysicalPlanner { | |||
Ok(DataType::Decimal128(_p2, _s2)), | |||
) => { | |||
let data_type = return_type.map(to_arrow_datatype).unwrap(); | |||
let func_name = if options.is_integral_div { |
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 just realized, we maybe able to reuse the previous case-match instead of here.
We needed to treat decimal_div
differently because we had to deal with rounding. However we just need to round down for IntegralDivide?
I.e. instead of 77digits for scale, we only need 76digits that fits into Decimal256
Will need a similar calculation to
|| (op == DataFusionOperator::Modulo
&& max(s1, s2) as u8 + max(p1 - s1 as u8, p2 - s2 as u8)
> DECIMAL128_MAX_PRECISION)
In this way, we do not need the decimal_div
change?
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.
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.
Thanks for trying, if this is too much trouble, we can file an issue ticket and can be worked on separately.
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.
This seems to be a bug in arrow, I have reported an issue: apache/arrow-rs#7216
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.
Thanks for trying, if this is too much trouble, we can file an issue ticket and can be worked on separately.
Could you please continue review this pr and let us keep changes to decimal_div
?
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, perhaps it is good to mention the ticket in a comment
Otherwise, my only comment is
Do we need to update https://github.com/apache/datafusion-comet/blob/main/spark/src/main/scala/org/apache/spark/sql/comet/DecimalPrecision.scala
?
Additionally https://github.com/apache/datafusion-comet/blob/main/spark/src/test/scala/org/apache/comet/CometExpressionSuite.scala#L1793 Decimal random number tests is another good test to extend
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.
Sorry I missed it before.
Do we need to update https://github.com/apache/datafusion-comet/blob/main/spark/src/main/scala/org/apache/spark/sql/comet/DecimalPrecision.scala
?
I guess it may not be necessary, IntegralDivide always returns a long type.
Additionally https://github.com/apache/datafusion-comet/blob/main/spark/src/test/scala/org/apache/comet/CometExpressionSuite.scala#L1793 Decimal random number tests is another good test to extend
I added div operator to this test case.
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.
LGTM pending CI
Thank you @wForget
Unrelated failure:
|
Which issue does this PR close?
Closes #1422.
Rationale for this change
Support IntegralDivide function
What changes are included in this PR?
Since datafusion div operator conforms to the logic of intergal div, we only need to convert
IntegralDivide(...)
toCast(Divide(...), LongType)
and then convert it to native.How are these changes tested?
added unit test