GitHub user maropu opened a pull request:
https://github.com/apache/spark/pull/11997
[SPARK-14193][SQL] Skip unnecessary sorts if input data have been already
ordered in InMemoryRelation
## What changes were proposed in this pull request?
This pr is to skip unnecessary sorts if input data have been already
ordered in InMemoryRelation.
Let's say we have a cached table with column 'a' sorted;
```
val df1 = Seq((1, 0), (3, 0), (2, 0), (1, 0)).toDF("a", "b")
val df2 = df1.sort("a").cache
df2.show // just cache data
```
If you say `df2.sort("a")`, the current spark generates a plan like;
```
== Physical Plan ==
Sort [a#13 ASC], true, 0
+- InMemoryColumnarTableScan [a#13,b#14], InMemoryRelation [a#13,b#14],
true, 10000, StorageLevel(true, true, false, true, 1), Sort [a#13 ASC], true,
0, None
```
This pr removes this unnecessary sort.
## How was this patch tested?
Add tests to check this kind of sort operators is removed in an optimizer.
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/maropu/spark SortAttr
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/spark/pull/11997.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 #11997
----
commit a035564be6a11566149e7a121e46843dcb826bfc
Author: Takeshi YAMAMURO <[email protected]>
Date: 2016-03-28T09:41:19Z
Skip unnecessary sorts if input data have been already ordered
----
---
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]