Repository navigation
Conversation
Contributor
No docs changes detected for 480687b |
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
A regression above Integer.MAX_VALUE is still needed to guard against cast-induced corruption, checking merged values, row keys, and an unchanged prefix in both sort directions.
1 open issue
What changed in this PR
Replaces text-based MegaMerge replication with JavaPoet generation, sharing type and ordering definitions with the engine’s timsort generator.
Changes:
- Adds
generateMegaMergeKernelstoreplicateAlland removes legacy MegaMerge replication. - Regenerates all 16 type/direction variants using shared comparison definitions.
- Removes the narrowing cast from merge-start checks to preserve bounds beyond
Integer.MAX_VALUE.
| File | Description |
|---|---|
| ReplicateSortKernel.java | Removes legacy MegaMerge replication and fixups. |
| GenerateTimsortKernels.java | Exposes type descriptors for generator reuse. |
| GenerateMegaMergeKernels.java | Generates all kernels with corrected long-position checks. |
| replication/reflective/build.gradle | Registers the new generation task. |
| ShortLongMegaMergeKernel.java | Regenerates ascending short merges with corrected bounds. |
| ShortLongMegaMergeDescendingKernel.java | Regenerates descending short merges with corrected bounds. |
| ObjectLongMegaMergeKernel.java | Regenerates ascending Object merges; parameterizes the source and corrects bounds. |
| ObjectLongMegaMergeDescendingKernel.java | Regenerates descending Object merges; parameterizes the source and corrects bounds. |
| LongLongMegaMergeKernel.java | Regenerates ascending long merges with corrected bounds. |
| LongLongMegaMergeDescendingKernel.java | Regenerates descending long merges with corrected bounds. |
| IntLongMegaMergeKernel.java | Regenerates ascending int merges with corrected bounds. |
| IntLongMegaMergeDescendingKernel.java | Regenerates descending int merges with corrected bounds. |
| FloatLongMegaMergeKernel.java | Regenerates ascending float merges with corrected bounds. |
| FloatLongMegaMergeDescendingKernel.java | Regenerates descending float merges with corrected bounds. |
| DoubleLongMegaMergeKernel.java | Regenerates ascending double merges with corrected bounds. |
| DoubleLongMegaMergeDescendingKernel.java | Regenerates descending double merges with corrected bounds. |
| CharLongMegaMergeKernel.java | Replaces the handwritten template with generated code and corrected bounds. |
| CharLongMegaMergeDescendingKernel.java | Regenerates descending char merges with corrected bounds. |
| ByteLongMegaMergeKernel.java | Regenerates ascending byte merges with corrected bounds. |
| ByteLongMegaMergeDescendingKernel.java | Regenerates descending byte merges with corrected bounds. |
Review effort: Balanced
cpwright
marked this pull request as ready for review
November 27, 2026 20:17
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Jira: DH-24543
Summary
The MegaMerge kernels are now generated with JavaPoet. Until now,
ReplicateSortKernelproduced them by replicating the text of the hand-writtenCharLongMegaMergeKerneland rewriting comparisons with regexes for the descending variants. A second commit fixes a truncatinglong-to-intcast in the merge loop.Commit 1: generate the kernels with JavaPoet
GenerateMegaMergeKernelstoreplication/reflective. It is registered asgenerateMegaMergeKernelsand runs underreplicateAll. It emits all 16 kernels (char, byte, short, int, long, float, double and Object; ascending and descending) intoengine/table/src/replicated/generateMegaMergeKernels/.GenerateTimsortKernels(chunk families, the*Comparisonsclasses, and the direction-aware comparison expressions). The merge kernels and the timsort kernels whose output they merge now share one definition of ordering. ThoseKeyKindconstants were private and are now package-private.CharLongMegaMergeKerneltemplate fromsrc/mainand the MegaMerge replication fromReplicateSortKernel.The generated kernels are behaviorally identical to the replicated ones. I stripped comments, imports, annotations and whitespace from all 16 old and new kernels and compared their members as sets: they match token for token. The only difference is
ObjectArraySource<Object>in place of the raw type. Re-runninggenerateMegaMergeKernels,generateTimsortKernelsandreplicateSortKernelreproduces the checked-in sources exactly.Commit 2: fix the truncated merge-start comparison
The destination-wins branch of
mergetested--destCursor < (int) mergeStartPosition. Both arelongpositions. For a merge start beyond 2^31, the cast produces a smaller value, so the loop runs past the merge start instead of breaking, and it reads the value just before the merge start.With
SortHelpers, which merges from offset 0, every such value is less than or equal to the chunk's smallest value. The extra iterations therefore always take from the chunk, and the result is still correct. A merge from a non-zero offset beyond 2^31, though, could copy a value from outside the destination run into the output.TestMegaMergeBeyondIntegerMaxValuemerges into a one-row destination run at(1L << 31) + 16, preceded by a value outside the run, in both directions. It checks the merged values, the row keys, and that the preceding row is unchanged. With the cast restored, both cases fail: the preceding value is merged into the run and overwritten. The test-onlySparseArraySourceBlocksfixture sets up the sources so that only the block containing the run is allocated; the cost is the block-reference array, not the 16 GB that 2^31 dense rows of long row keys would take.Layout of the generated code
The generator leaves code layout to JavaPoet: no hand-placed blank lines or line breaks, matching
GenerateTimsortKernels. JavaPoet does not wrap javadoc, so the newReplicationUtils.wrapJavadocwraps it to 120 columns.Testing
./gradlew :engine-table:test --tests "io.deephaven.engine.table.impl.sort.megamerge.*": 35 tests, all pass, including the two new beyond-Integer.MAX_VALUEcases../gradlew :engine-table:testOutOfBand --tests "*.QueryTableSortTest" --tests "*.QueryTableHugeSortTest": 35 tests, all pass.spotlessCheckon:replication-reflective,:replication-staticand:engine-table.🤖 Generated with Claude Code
https://claude.ai/code/session_01HgjU6BT2fMBP5buTa48oXP