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

[SPARK-17806] [SQL] fix bug in join key rewritten in HashJoin #15390

Closed
wants to merge 2 commits into from

Conversation

davies
Copy link
Contributor

@davies davies commented Oct 7, 2016

What changes were proposed in this pull request?

In HashJoin, we try to rewrite the join key as Long to improve the performance of finding a match. The rewriting part is not well tested, has a bug that could cause wrong result when there are at least three integral columns in the joining key also the total length of the key exceed 8 bytes.

How was this patch tested?

Added unit test to covering the rewriting with different number of columns and different data types. Manually test the reported case and confirmed that this PR fix the bug.

@davies
Copy link
Contributor Author

davies commented Oct 7, 2016

cc @rxin

val bits = dt.defaultSize * 8
keyExpr = BitwiseOr(ShiftLeft(keyExpr, Literal(bits)),
BitwiseAnd(Cast(e, LongType), Literal((1L << bits) - 1)))
width += dt.defaultSize
Copy link
Contributor

Choose a reason for hiding this comment

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

This is the only change (for people also reviewing this).

@hvanhovell
Copy link
Contributor

LGTM pending Jenkins.

*
* If not, returns the original expressions.
*/
private[joins] def rewriteKeyExpr(keys: Seq[Expression]): Seq[Expression] = {
Copy link
Contributor

Choose a reason for hiding this comment

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

This will be a lot clear and less error prone if we can write the check first and go through the data twice, e.g.

if (keys.map(_.dataType.defaultSize).sum <= 8) {
  return keys
}

// do the rewrite here

@SparkQA
Copy link

SparkQA commented Oct 7, 2016

Test build #66510 has finished for PR 15390 at commit 974fadb.

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

@rxin
Copy link
Contributor

rxin commented Oct 7, 2016

LGTM, pending the new test run.

@SparkQA
Copy link

SparkQA commented Oct 7, 2016

Test build #66522 has finished for PR 15390 at commit 87f6b24.

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

@asfgit asfgit closed this in 94b24b8 Oct 7, 2016
asfgit pushed a commit that referenced this pull request Oct 7, 2016
## What changes were proposed in this pull request?

In HashJoin, we try to rewrite the join key as Long to improve the performance of finding a match. The rewriting part is not well tested, has a bug that could cause wrong result when there are at least three integral columns in the joining key also the total length of the key exceed 8 bytes.

## How was this patch tested?

Added unit test to covering the rewriting with different number of columns and different data types. Manually test the reported case and confirmed that this PR fix the bug.

Author: Davies Liu <davies@databricks.com>

Closes #15390 from davies/rewrite_key.

(cherry picked from commit 94b24b8)
Signed-off-by: Davies Liu <davies.liu@gmail.com>
@SparkQA
Copy link

SparkQA commented Oct 7, 2016

Test build #3300 has finished for PR 15390 at commit 87f6b24.

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

uzadude pushed a commit to uzadude/spark that referenced this pull request Jan 27, 2017
## What changes were proposed in this pull request?

In HashJoin, we try to rewrite the join key as Long to improve the performance of finding a match. The rewriting part is not well tested, has a bug that could cause wrong result when there are at least three integral columns in the joining key also the total length of the key exceed 8 bytes.

## How was this patch tested?

Added unit test to covering the rewriting with different number of columns and different data types. Manually test the reported case and confirmed that this PR fix the bug.

Author: Davies Liu <davies@databricks.com>

Closes apache#15390 from davies/rewrite_key.
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