[common] Fix partition getter indexing in InternalRowPartitionComputer - #9513
Open
LuciferYang wants to merge 1 commit into
Open
[common] Fix partition getter indexing in InternalRowPartitionComputer#9513LuciferYang wants to merge 1 commit into
LuciferYang wants to merge 1 commit into
Conversation
The constructor sized partitionFieldGetters and partitionCastExecutors by the number of partition columns, then stored into them at the partition column's position in the full row schema. The two index spaces only coincide when the partition columns are a prefix of the row type in row order, which is what every current caller passes, so the bug is latent rather than something a deployment hits today. Constructing the computer with the full row type either throws ArrayIndexOutOfBoundsException or, when the positions happen to be in range, pairs each partition column name with another column's getter. Store each getter at its partition-column position and keep reading the type from the row-schema position. The two tests pin both halves of the contract: an out-of-range position, and a reordered subset where the old code returned crossed values without throwing. Assisted-by: GLM-5.3
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.
Purpose
close #9512
InternalRowPartitionComputer's constructor sizedpartitionFieldGettersandpartitionCastExecutorsby the number of partition columns, then stored into them at the partition column's position in the full row schema.generatePartValuesreads all three ofpartitionFieldGetters[i],partitionCastExecutors[i]andpartitionColumns[i]with one loop variable over the partition columns, so the array bound and the index expression have to agree, and they only agree when the partition columns are a prefix of the row type in row order.Each getter is now stored at its partition-column position, while the type and the field position it reads still come from the row schema.
Nothing in the constructor's signature requires the partition columns to be a row prefix, but every current caller passes a row type already projected to the partition columns in
partitionKeysorder (TableSchema.logicalPartitionType(),store().partitionType(),rowType().project(partitionKeys()),TypeUtils.project(rowType, partitionKeys)).indexOftherefore always returns the loop position, old and new code produce identical arrays at every call site, and the bug is latent rather than something a deployment hits today. It fires as soon as a caller hands over the full row type: eitherArrayIndexOutOfBoundsException, or, when the row positions happen to be in range, a partition spec in which every column name carries another column's value with no error raised.Tests
Two cases in
InternalRowPartitionComputerTest, one per failure mode.testPartitionColumnNotAtRowPrefix: row typeid, dt, region, extrawith partition columns{region, dt}.regionsits at row position 2, out of range for a two-element array. Fails on the old code withArrayIndexOutOfBoundsException: 2.testPartitionColumnsReorderedWithinRowPrefix: row typeid INT, dt STRING, region STRINGwith partition columns{dt, id}. Both row positions are in range, so the old code does not throw; it returns{dt=1, id=20240731}instead of{dt=20240731, id=1}. Mixed types make the crossed values visible rather than symmetric.Both assert with
containsExactly(entry(...), entry(...)), which pins the iteration order of the returnedLinkedHashMapas well as the pairing, since partition paths and partition specs consume that order.Verified red before the change (
ArrayIndexOutOfBoundsException: 2and crossed values respectively), and the pre-existingtestPartitionToStringstays green.mvn -pl paimon-common teston JDK 8: 12467 tests, 0 failures, 0 errors. checkstyle, spotless, enforcer and rat run clean.