Uh oh!
There was an error while loading. Please reload this page.
[SPARK-15985][SQL] Eliminate redundant cast from an array without null or a map without null - #13704
[SPARK-15985][SQL] Eliminate redundant cast from an array without null or a map without null#13704kiszk wants to merge 22 commits into
Conversation
SparkQA
commented
Jun 16, 2016
Test build #60636 has finished for PR 13704 at commit
|
There was a problem hiding this comment.
I assume that here is a part to generate code for Java primitive arrays regarding from and to. Since Java primitive array (e.g. int[]) cannot have null value unlike SQL, I said "ensure not null in input and output arrays."
What do you think?
can you also put the plan tree of the example program in PR description? thanks! |
kiszk
commented
Jun 27, 2016
@cloud-fan I updated the PR description by adding plan trees. |
cloud-fan
commented
Jun 27, 2016
I'm wondering why we have this |
@cloud-fan I think |
cloud-fan
commented
Jun 28, 2016
Sorry I should say it more explicitly: |
I agree that What do you think? |
cloud-fan
commented
Jun 28, 2016
From the plan tree given by you, the |
kiszk
commented
Jun 28, 2016
Regarding the plan tree printout (I removed my debug information), the Regarding the generated code, we seems to be on the same page. What you said is not done in |
cloud-fan
commented
Jun 29, 2016
This is reasonable, as it needs to take care of null elements. And we do have a chance to optimize it: if the target array type's element type is primitive and the input array type's element nullability is false, we can avoid using |
Let me check which code portion inserts
I agree. This PR generates optimized code without using |
There was a problem hiding this comment.
we need to make sure the input array's element nullability is false, but primitive type array doesn't guarantee it. e.g. we can have ArrayType(ByteType, true)
There was a problem hiding this comment.
Yes, you are right. The latest code also checks ArrayType.containsNull of from and to.
kiszk
commented
Jul 1, 2016
@cloud-fan, I checked the following
IIUC, this code inserts the corresponding |
SparkQA
commented
Jul 1, 2016
Test build #61629 has finished for PR 13704 at commit
|
SparkQA
commented
Jul 1, 2016
Test build #61630 has finished for PR 13704 at commit
|
SparkQA
commented
Jul 3, 2016
Test build #61677 has finished for PR 13704 at commit
|
@cloud-fan regarding a |
SparkQA
commented
Jul 10, 2016
Test build #62050 has finished for PR 13704 at commit
|
SparkQA
commented
Jul 10, 2016
Test build #62057 has finished for PR 13704 at commit
|
kiszk
commented
Jul 10, 2016
@cloud-fan could you please review this? As you pointed, I also changed code related to |
There was a problem hiding this comment.
how about we move this into another PR? I think the main purpose of this PR is to eliminate the unnecessary Cast
There was a problem hiding this comment.
Sure, I will create another PR and update the description.
SparkQA
commented
Jul 11, 2016
Test build #62071 has finished for PR 13704 at commit
|
There was a problem hiding this comment.
how about
case c @ Cast(e, dataType) => (e.dataType, dataType) match {
case (ArrayType(from, false), ArrayType(to, true)) if from == to => e
case (MapType(fromKey, fromValue, false), ArrayType(toKey, toValue, true)) if fromKey == toKey && fromValue == toValue => e
case _ => c
}
SparkQA
commented
Jul 11, 2016
Test build #62084 has finished for PR 13704 at commit
|
SparkQA
commented
Jul 11, 2016
Test build #62087 has finished for PR 13704 at commit
|
SparkQA
commented
Jul 11, 2016
Test build #62097 has finished for PR 13704 at commit
|
SparkQA
commented
Aug 29, 2016
Test build #64594 has finished for PR 13704 at commit
|
kiszk
commented
Aug 30, 2016
@liancheng Could you please review this since I resolved conflict? |
| comparePlans(optimized, expected) | ||
| } | ||
| test("non-nullable to nullable array cast") { |
There was a problem hiding this comment.
non-nullable element array to nullable element array cast
cloud-fan
commented
Aug 30, 2016
left some comment, let's go ahead and merge it after that :) |
SparkQA
commented
Aug 30, 2016
Test build #64658 has finished for PR 13704 at commit
|
cloud-fan
commented
Aug 31, 2016
thanks, merging to master! |
What changes were proposed in this pull request?
This PR eliminates redundant cast from an
ArrayTypewithcontainsNull = falseor aMapTypewithcontainsNull = false.For example, in
ArrayTypecase, current implementation leaves a castcast(value#63 as array<double>).toDoubleArray. However, we can eliminatecast(value#63 as array<double>)if we knowvalue#63does not includenull. This PR apply this elimination forArrayTypeandMapTypeinSimplifyCastsat a plan optimization phase.In summary, we got 1.2-1.3x performance improvements over the code before applying this PR.
Here are performance results of benchmark programs:
An example program that originally caused this performance issue.
Plans before this PR
Plans after this PR
How was this patch tested?
Tested by new test cases in
SimplifyCastsSuite