GitHub user vidma opened a pull request:
https://github.com/apache/spark/pull/9451
WIP: Optimize Inner joins with skewed null values
Draft of first step in optimizing skew in joins (it is quite common to have
skew in data, and lots of `nulls` on either side of join is quite common (for
us), especially with left join, say when joining `dimensions` to `fact` tables)
feel free to propose a better approach / add commits.
any ideas for an easy way to check if the rule was already applied? After
adding a `isNotNull` filter `someAttribute.nullable` still returns `true`. I
couldn't come up with anything better than simply doing a separate batch of 1
iteration.
@marmbrus (as discussed at Spark Summit EU)
---
going more serious, a draft for fighting skew in left join is [rather
simple with DataFrames](https://gist.github.com/vidma/98332db0f82e7e5b09e5),
solves the null skew, and don't seem to add lots of overhead (though tried only
on subset of all our joins which used another abstraction of ours).
however this, so far, seems harder to express in optimizer rules:
- need to add "fake" colums. no idea yet how to do this to be able to refer
to the added column in join conditions
```scala
val leftNullsSprayValue = CaseWhen(
Seq(
nullableJoinKeys(left).map(IsNull).reduceLeft(Or), // if any join
keys are null
Cast(Multiply(new Rand(), Literal(100000)), IntegerType),
Literal(0) // otherwise
))
// but how to add this column to left & right relations?
// e.g. this fails, saying it's not `resolved`
Alias(leftNullsSprayValue)("leftNullsSprayKey")()
```
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/vidma/spark feature/fight-skew-in-inner-join
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/spark/pull/9451.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #9451
----
commit 214deeae2d4c634536df0d9bd6c2ffcfc573ce7b
Author: vidmantas zemleris <[email protected]>
Date: 2015-11-03T22:38:08Z
Optimize Inner joins with skewed null values
----
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]