linhongliu-db opened a new pull request, #60404:
URL: https://github.com/apache/spark/pull/60404

   ### What changes were proposed in this pull request?
   
   `RangePartitioner` seeds the samples that pick its range bounds from the RDD 
id:
   `RangePartitioner.sketch` uses `shift = rdd.id`, and the 
imbalanced-partition re-sample uses
   `byteswap32(-rdd.id - 1)`. A global sort builds a new RDD, with a new id, on 
every execution, so the
   range bounds of the same data move between runs. A seeded `TABLESAMPLE ... 
REPEATABLE` (or a seeded
   `Dataset.sample`) over an `ORDER BY` therefore returns different rows each 
time.
   
   This derives both the sketch shift and the re-sample seed from the partition 
index only. A new conf
   `spark.rdd.rangePartitioner.legacyRddIdSeed` (default `false`) restores the 
previous behavior.
   
   ### Why are the changes needed?
   
   A seeded sample over a global sort is not reproducible, despite `REPEATABLE`.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes, documented in `docs/sql-migration-guide.md`. Range partition boundaries 
(and so which partition
   or output file a row lands in) can differ from earlier versions; seeded 
samples over `ORDER BY` are
   now reproducible when the input data, its partitioning and sort order are 
unchanged. Set
   `spark.rdd.rangePartitioner.legacyRddIdSeed=true` to restore the old 
behavior.
   
   ### How was this patch tested?
   
   New `PartitioningSuite` test (the bounds of skewed, re-sampled data no 
longer depend on the RDD id)
   and `SQLQuerySuite` tests (a `TABLESAMPLE REPEATABLE` over `ORDER BY` is 
stable across executions,
   plus a gate-off case reproducing the nondeterminism). Locally the new tests 
pass and scalastyle is
   clean on JDK 21.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   Generated-by: Claude Code (Isaac)
   
   This pull request and its description were written by Isaac.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to