Skip to content

Conversation

@gengliangwang
Copy link
Member

What changes were proposed in this pull request?

IntegralDivide should throw an exception on overflow in ANSI mode.
There is only one case that can cause that:

Long.MinValue div -1

Why are the changes needed?

ANSI compliance

Does this PR introduce any user-facing change?

Yes, IntegralDivide throws an exception on overflow in ANSI mode

How was this patch tested?

Unit test

@gengliangwang gengliangwang requested a review from cloud-fan April 20, 2021 15:07
@github-actions github-actions bot added the SQL label Apr 20, 2021
dataType match {
case LongType if failOnError =>
(x: Any, y: Any) => {
if (x == Long.MinValue && y == -1) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Shall we do this in DivModLike.eval?

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 not happening in Divide or Mod

Copy link
Contributor

Choose a reason for hiding this comment

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

yea, similar to the codegen path we can use if (isIntegralDivide).

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah it's tricky. It is hard to reuse thedoGenCode here so I added a new flag isIntegralDivide.
The original idea is to keep the special handling code in IntegralDivide if possible.
But now it seems asymmetric in both sides..

@SparkQA
Copy link

SparkQA commented Apr 20, 2021

Test build #137692 has finished for PR 32260 at commit 1658f5b.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Apr 20, 2021

Kubernetes integration test starting
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/42219/

@SparkQA
Copy link

SparkQA commented Apr 20, 2021

Kubernetes integration test status failure
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/42219/

@SparkQA
Copy link

SparkQA commented Apr 20, 2021

Kubernetes integration test starting
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/42222/

@SparkQA
Copy link

SparkQA commented Apr 20, 2021

Kubernetes integration test status failure
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/42222/

@SparkQA
Copy link

SparkQA commented Apr 20, 2021

Kubernetes integration test starting
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/42223/

@SparkQA
Copy link

SparkQA commented Apr 20, 2021

Kubernetes integration test status failure
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/42223/

@SparkQA
Copy link

SparkQA commented Apr 20, 2021

Kubernetes integration test starting
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/42224/

@SparkQA
Copy link

SparkQA commented Apr 20, 2021

Kubernetes integration test status failure
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/42224/

@arvindsaik
Copy link

Have we considered returning NULL in the non-ANSI mode instead of Long.MinValue?

@SparkQA
Copy link

SparkQA commented Apr 20, 2021

Test build #137695 has finished for PR 32260 at commit d91fa4e.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Apr 20, 2021

Test build #137696 has finished for PR 32260 at commit 9ade940.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Apr 20, 2021

Test build #137697 has finished for PR 32260 at commit 64f1431.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@gengliangwang
Copy link
Member Author

@arvindsaik I think we can make it in safe version functions:
https://issues.apache.org/jira/browse/SPARK-35161

Copy link
Member

@MaxGekk MaxGekk left a comment

Choose a reason for hiding this comment

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

ANSI interval division by a numeric has the same issue. I opened JIRA SPARK-35169 for that.

protected def decimalToDataTypeCodeGen(decimalResult: String): String = decimalResult

// Whether we should check overflow or not in ANSI mode.
protected def checkDivideOverflow: Boolean = false
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this simply left.dataType == LongType? For Divide, the child is either double or decimal, so won't hit this branch.

Under the hood, what we really want to handle is Long.MinValue / -1, so check left.dataType == LongType looks reasonable.

Copy link
Member Author

Choose a reason for hiding this comment

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

No, Remainder's left can be Long as well

@gengliangwang
Copy link
Member Author

Merging to master

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants