Skip to content

fix: Refactor arithmetic serde and fix correctness issues with EvalMode::TRY #2018

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

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

andygrove
Copy link
Member

@andygrove andygrove commented Jul 11, 2025

Which issue does this PR close?

Part of #2019

Partial fix for #2021

Rationale for this change

See #2019

What changes are included in this PR?

Refactor the following expressions:

  • Add
  • Subtract
  • Multiply
  • Divide
  • IntegralDivide
  • Remainder

Functional changes:

  • Implement specific version of supportedDataType for math expressions (we no longer claim to support performing math operations on complex types, for example)
  • Fall back to Spark for EvalMode:TRY because we haven't implemented support for that in native code yet and produce incorrect results in some cases

How are these changes tested?

@codecov-commenter
Copy link

codecov-commenter commented Jul 11, 2025

Codecov Report

Attention: Patch coverage is 69.56522% with 49 lines in your changes missing coverage. Please review.

Project coverage is 58.63%. Comparing base (f09f8af) to head (e86b51a).
Report is 324 commits behind head on main.

Files with missing lines Patch % Lines
...main/scala/org/apache/comet/serde/arithmetic.scala 68.38% 26 Missing and 23 partials ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #2018      +/-   ##
============================================
+ Coverage     56.12%   58.63%   +2.51%     
- Complexity      976     1237     +261     
============================================
  Files           119      135      +16     
  Lines         11743    13065    +1322     
  Branches       2251     2382     +131     
============================================
+ Hits           6591     7661    +1070     
- Misses         4012     4179     +167     
- Partials       1140     1225      +85     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@andygrove andygrove changed the title minor: Refactor arithmetic serde into separate classes fix: Refactor arithmetic serde and fix correctness issues with EvalMode::TRY Jul 11, 2025
@andygrove
Copy link
Member Author

@rishvin, This PR is still a draft, but could you review the changes to the remainder code to ensure I didn't miss anything from your changes?

@andygrove andygrove marked this pull request as ready for review July 11, 2025 21:45
@rishvin
Copy link
Contributor

rishvin commented Jul 11, 2025

@rishvin, This PR is still a draft, but could you review the changes to the remainder code to ensure I didn't miss anything from your changes?

Thanks @andygrove for the heads up. I took the look for remainder and nothing is missed out.
These changes are also looking great!

Comment on lines +88 to +95
def supportedDataType(dt: DataType): Boolean = dt match {
case _: ByteType | _: ShortType | _: IntegerType | _: LongType | _: FloatType |
_: DoubleType | _: StringType | _: BinaryType | _: TimestampType | _: TimestampNTZType |
_: DecimalType | _: DateType | _: BooleanType | _: NullType =>
true
case _ =>
false
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is copied over from QueryPlanSerde. I removed the complex types, but I am sure we could remove more types in the future.

Comment on lines +81 to +86
private def isPrimitive(expression: Expression): Boolean = expression.dataType match {
case _: ByteType | _: ShortType | _: IntegerType | _: LongType | _: FloatType |
_: DoubleType | _: TimestampType | _: DateType | _: BooleanType | _: DecimalType =>
true
case _ => false
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is moved without modification from QueryPlanSerde. I am not sure why this method is needed. I'm pretty sure that we can only perform arithmetic on primitive types?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why this is needed either, but while we are checking, should this also check for TimestampNTZ?

Copy link
Contributor

@parthchandra parthchandra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm. (one minor comment)

Comment on lines +81 to +86
private def isPrimitive(expression: Expression): Boolean = expression.dataType match {
case _: ByteType | _: ShortType | _: IntegerType | _: LongType | _: FloatType |
_: DoubleType | _: TimestampType | _: DateType | _: BooleanType | _: DecimalType =>
true
case _ => false
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why this is needed either, but while we are checking, should this also check for TimestampNTZ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants