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

fix: div and rem by negative zero #960

Merged
merged 6 commits into from
Sep 24, 2024

Conversation

kazuyukitanimura
Copy link
Contributor

@kazuyukitanimura kazuyukitanimura commented Sep 23, 2024

Which issue does this PR close?

Closes #521 and #665.

Rationale for this change

What changes are included in this PR?

This PR normalize the right hand of div and rem

How are these changes tested?

Test updated

@kazuyukitanimura
Copy link
Contributor Author

Copy link
Contributor

@mbutrovich mbutrovich left a comment

Choose a reason for hiding this comment

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

Just comments and questions from me.

@@ -91,13 +91,15 @@ Comet has a plan stability testing framework that can be used to test the stabil
The plan stability testing framework is located in the `spark` module and can be run using the following command:

```sh
./mvnw -pl spark -Dsuites="org.apache.spark.sql.comet.CometTPCDSV1_4_PlanStabilitySuite" test
./mvnw -pl spark -Dsuites="org.apache.spark.sql.comet.CometTPCDSV1_4_PlanStabilitySuite" -nsu test
./mvnw -pl spark -Dsuites="org.apache.spark.sql.comet.CometTPCDSV1_4_PlanStabilitySuite" -Pspark-3.5 -nsu test
Copy link
Contributor

Choose a reason for hiding this comment

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

Since you added these steps to the testing commands, does it makes sense to duplicate them below for the generation commands?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, updated.

}
}

def normalizeNaNAndZero(expr: Expression): Expression = {
expr match {
case _: KnownFloatingPointNormalized => expr
case FloatLiteral(f) if !f.equals(-0.0f) => expr
Copy link
Contributor

Choose a reason for hiding this comment

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

Just clarifying: this is saying that as long as the literal isn't -0.0, we don't have to normalize it? And it doesn't look like there's any way to define a literal NaN, so we don't handle that case?

Copy link
Contributor Author

@kazuyukitanimura kazuyukitanimura Sep 24, 2024

Choose a reason for hiding this comment

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

Just clarifying: this is saying that as long as the literal isn't -0.0, we don't have to normalize it?

Exactly

And it doesn't look like there's any way to define a literal NaN, so we don't handle that case?

We can create a literal NaN, but Spark NormalizeNaNAndZero is not doing much for literal NaN. I think NaN normalization matters only when some expression results are NaN https://github.com/apache/spark/blob/master/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/NormalizeFloatingNumbers.scala#L194

@@ -91,27 +91,31 @@ Comet has a plan stability testing framework that can be used to test the stabil
The plan stability testing framework is located in the `spark` module and can be run using the following command:

```sh
./mvnw -pl spark -Dsuites="org.apache.spark.sql.comet.CometTPCDSV1_4_PlanStabilitySuite" test
./mvnw -pl spark -Dsuites="org.apache.spark.sql.comet.CometTPCDSV1_4_PlanStabilitySuite" -nsu test
Copy link
Member

Choose a reason for hiding this comment

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

Why add -nsu?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It helps for faster turnaround

@@ -2636,7 +2636,11 @@ object QueryPlanSerde extends Logging with ShimQueryPlanSerde with CometExprShim

def nullIfWhenPrimitive(expression: Expression): Expression = if (isPrimitive(expression)) {
val zero = Literal.default(expression.dataType)
If(EqualTo(expression, zero), Literal.create(null, expression.dataType), expression)
expression match {
case _: Literal if expression != zero => expression
Copy link
Member

Choose a reason for hiding this comment

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

Is this related?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indirectly related, this will avoid to put EqualTo for non zero literals for divisions

@kazuyukitanimura
Copy link
Contributor Author

kazuyukitanimura commented Sep 24, 2024

Closes #585

@kazuyukitanimura kazuyukitanimura merged commit 5663fc2 into apache:main Sep 24, 2024
74 checks passed
@kazuyukitanimura
Copy link
Contributor Author

Merged Thank you @mbutrovich @viirya

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.

Modulus can produce incorrect results in some cases
3 participants