-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-19352][SQL] Preserve sort order when saving dataset if data is sorted by partition columns #16724
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-19352][SQL] Preserve sort order when saving dataset if data is sorted by partition columns #16724
Changes from all commits
3c040b6
d9a067c
bafd195
b1ce030
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -487,6 +487,36 @@ class FileSourceStrategySuite extends QueryTest with SharedSQLContext with Predi | |
| } | ||
| } | ||
|
|
||
| test("SPARK-19352: Keep sort order of rows after external sorter when writing") { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. again, this is not guaranteed, we should not test it. This is an optimization and advanced users can leverage this to preserve the sort order, but it may change in the future.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. got it. |
||
| spark.stop() | ||
| // Explicitly set memory configuration to force `UnsafeKVExternalSorter` to spill to files | ||
| // when inserting data. | ||
| val newSpark = SparkSession.builder() | ||
| .master("local") | ||
| .appName("test") | ||
| .config("spark.buffer.pageSize", "16b") | ||
| .config("spark.testing.memory", "1400") | ||
| .config("spark.memory.fraction", "0.1") | ||
| .config("spark.shuffle.sort.initialBufferSize", "2") | ||
| .config("spark.memory.offHeap.enabled", "false") | ||
| .getOrCreate() | ||
| withTempPath { path => | ||
| val tempDir = path.getCanonicalPath | ||
| val df = newSpark.range(100) | ||
| .select($"id", explode(array(col("id") + 1, col("id") + 2, col("id") + 3)).as("value")) | ||
| .repartition($"id") | ||
| .sortWithinPartitions($"id", $"value".desc).toDF() | ||
|
|
||
| df.write | ||
| .partitionBy("id") | ||
| .parquet(tempDir) | ||
|
|
||
| val dfReadIn = newSpark.read.parquet(tempDir).select("id", "value") | ||
| checkAnswer(df.filter("id = 65"), dfReadIn.filter("id = 65")) | ||
| } | ||
| newSpark.stop() | ||
| } | ||
|
|
||
| // Helpers for checking the arguments passed to the FileFormat. | ||
|
|
||
| protected val checkPartitionSchema = | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this duplicates too much code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mainly is because there are two types of iterators, one is [UnsafeRow, UnsafeRow], another is just [UnsafeRow].