Repository navigation
Core, Spark: Introduce shared MultiColumnTerm to de-duplicate Z-order and Hilbert clustering - #17893
GGraziadei wants to merge 1 commit into
Conversation
|
Please consider GGraziadei#1 as the natural follow-up once this PR is merged. The idea is to extend the grammar to natively support transformations, improving the quality of Z-order and Hilbert clustering. E.g. |
uros-b
left a comment
There was a problem hiding this comment.
This seems like a clean mechanical refactor, so thank you @GGraziadei - let's leave up to maintainters (@RussellSpitzer, @nssalian) to take this further
|
The de-duplication looks clean, and parameterising the per-curve error strings keeps the user-facing behavior stable. One place where the refactor changes the failure mode for future extension: in Minor: |
3bb6807 to
1d53bf5
Compare
|
Hi @gimgit, thanks for your comment. Addressed in 54d5d9b (rebased on main; the Spark changes stay on 4.1).
|
… and Hilbert clustering
1d53bf5 to
54d5d9b
Compare
|
This pull request has been marked as stale due to 30 days of inactivity. It will be closed in 1 week if no further activity occurs. If you think that’s incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the PR at any time and @mention a reviewer or discuss it on the [email protected] list. Thank you for your contributions. |
|
Remove stale |
|
This pull request has been marked as stale due to 30 days of inactivity. It will be closed in 1 week if no further activity occurs. If you think that’s incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the PR at any time and @mention a reviewer or discuss it on the [email protected] list. Thank you for your contributions. |
Closes #17657.
Follow-up to #16827, which deliberately mirrored the Z-order surface to keep that diff reviewable. This PR is the deferred de-duplication, along the lines @RussellSpitzer suggested in review ("we'll probably want a
MultiColumnTermor something like that in the future").What changed
Core — new
org.apache.iceberg.expressions.MultiColumnTerm, an immutableTermover an ordered list of column references.ZorderandHilbert(previously identical apart from the class name) become two-line subclasses. Public constructors and therefs()signature are unchanged; the parsed SQL grammar is untouched. One behavioural note onrefs(): it previously returnedArrays.asListover the internal array (element-mutable viaset), it now returns anImmutableList. Callers that mutated the returned list in place would now get anUnsupportedOperationException.Spark 4.1 —
SparkZOrderFileRewriteRunnerandSparkHilbertFileRewriteRunnermove onto a new abstractSparkCurveFileRewriteRunner, parameterised by the internal value column name, the exact per-curve error messages, and the combine step. The shared pieces — internal column schema/sort order, column validation (validZOrderColNames/validHilbertColNameswere byte-for-byte the same logic),sortSchema,sortedDF, and the per-column ordered-bytes conversion — now live in one place. Each runner keeps only what is genuinely curve-specific: Z-order its two options and the interleave combine (~120 lines), Hilbert its fixed per-column bit width and the Hilbert-index combine (~75 lines). Adding a further curve is now a small, local change.Dispatch — the duplicated
zorder/hilbertbranches inSpark3Util.toIcebergTermshare one reference-extraction helper, andRewriteDataFilesProcedurecollapses its two per-curve term lists into a singleList<MultiColumnTerm>. Dispatch stays closed:applySortStrategybranches explicitly onZorderandHilbertand throws for any otherMultiColumnTerm, and the mixed-curves error names the term types actually found, so the existing message ("Cannot mix Zorder and Hilbert sort expressions") is preserved.What did not change
Engine-side behaviour is bit-for-bit identical, which the existing tests enforce: every pre-existing Z-order and Hilbert test passes unmodified (
TestSparkFileRewriteRunners, the Z-order/Hilbert cases ofTestRewriteDataFilesAction,TestRewriteDataFilesProcedure). The only test change is the newTestMultiColumnTermin core. All user-facing error messages are preserved exactly. Spark 3.5/4.0/4.2 are untouched.Out of scope
The wider "arbitrary function via
Expressions" refactor discussed in #16827 review builds naturally on this abstraction but is split out per the issue, to keep this diff mechanical and easy to verify.