Repository navigation
Conversation
Start sequence-group aggregates from an empty accumulator so a leading retraction contributes the negative of its input. When deletes are ignored, preserve the delete payload until the first positive record starts aggregation. Cover both merge behavior and committed table reads across changelog producers.
JingsongLi
left a comment
There was a problem hiding this comment.
The new cases fix the retraction-plus-update batch from #11273, and all 84 focused merge and persisted-table tests passed. A separate persisted-table case showed that the fix still depends on where the write buffer flushes.
[P1] Keep the sign of a retraction-only buffer when its result is merged again. I used the PR's Parquet primary-key partial-update table with sum and sequence groups. I committed +I(40), +I(50), then -U(40), -U(50) in a second commit, then +U(60) in a third. The total should be 60. Master read 200, and this PR increased it to 240.
The second buffer now combines the retractions into an accumulator of -90, and getResult() emits a DELETE when there was no insert. On readback the merge treats that DELETE's negative accumulator as a raw contribution and subtracts it again, increasing the total by 90. Please preserve a representation that applies the correct sign at subsequent merge levels and test a retraction-only flush before a later positive update.
|
Thanks for the repro, @JingsongLi. I reproduced I added a table-level regression test that checks the amount after the second and third commits. It reads I also tried all 16 ways to split those five records across commits. Every split produced |
14d9f6f to
e9e9baa
Compare
| this.initialSumValues = new HashMap<>(); | ||
| fieldAggregators.forEach( | ||
| (i, aggregator) -> { | ||
| if (aggregator instanceof FieldSumAgg) { |
There was a problem hiding this comment.
This looks very bad. Put FieldSumAgg into common merge func.
There was a problem hiding this comment.
Thanks, moved it into FieldAggregator. It now has emptyAccumulator() and retractionResult(), and FieldSumAgg overrides both. PartialUpdateMergeFunction no longer checks for FieldSumAgg.
This also fixes NOT NULL ignore-retract sums. They're wrapped in FieldIgnoreRetractAgg, so the old instanceof check missed them.
Add emptyAccumulator() and retractionResult() to FieldAggregator so PartialUpdateMergeFunction no longer special-cases FieldSumAgg. FieldIgnoreRetractAgg delegates emptyAccumulator(), so NOT NULL ignore-retract sums also start from zero.
JeonDaehong
left a comment
There was a problem hiding this comment.
Thanks @houlinchn. I ran 55e140d merged with current master against random +I/+U/-U/-D sequences on one key, each written in one commit, in random commits, and in random commits with full compactions in between. It covered changelog-producer none, input and lookup, nullable and NOT NULL sums, ignore-delete, null sequence values and null amounts. All 9,000 runs read the expected sum, and the lookup changelog added up to it. Master missed it in 804 runs.
| * retractions. | ||
| */ | ||
| @Nullable | ||
| public Object retractionResult(@Nullable Object accumulator) { |
There was a problem hiding this comment.
product also implements retract but keeps these defaults, so it still starts from the retracted value. Committing +I(5) and then -U(5), +U(5) reads 25 on master and on this branch. Is product meant to stay out of scope here? A line in the description would help if so.
There was a problem hiding this comment.
Yes, product stays out of scope. Its retraction-only state can't be stored in the field type: retractionResult() would have to return 1 / acc, which truncates to 0 for integer types. retract(null, x) also returns null, so a leading retraction is dropped. +I(5) followed by -U(5), +U(5) reads 25 on master and on this branch, so this PR doesn't change it. I opened #11465 to track it and added a note to the description.
There was a problem hiding this comment.
Thanks @houlinchn, that makes sense. The note and #11465 cover it.
JingsongLi
left a comment
There was a problem hiding this comment.
Reviewed 55e140d65e. All 223 focused Core and 9 Flink 1.20.1 tests passed. I verified the ordinary sum correction across two full Parquet compactions and reader reopenings. A separate checked-overflow case still makes the result depend on the flush boundary.
|
|
||
| @Override | ||
| public Object retractionResult(Object accumulator) { | ||
| return negative(accumulator); |
There was a problem hiding this comment.
[P2] Preserve a checked sum across a retraction-only flush at the signed minimum
On a real Parquet primary-key table with amount INT NOT NULL, a sequence group, and fields.amount.sum.fail-on-overflow=true, I wrote +I(-1), +I(2147483647), +I(1), -U(2147483647), -U(1). In one commit, it succeeds and reads -1. If I commit the three inserts first, the two retractions accumulate to the representable value -2147483648, then the second commit fails in retractionResult() when it tries to negate that value into a DELETE payload. The same split succeeds with overflow checking off. Please preserve a representation for this retraction-only buffer that does not require an unrepresentable positive payload, and test it across separate commits.
|
The postpone writer hits the same overflow. With |
Purpose
Fixes #11273
A partial-update table with sequence groups and a
sumaggregate double-counts when a merge starts with a retraction. Withamount = 90committed, a later commit of-U(90), +U(90)should leave90but reads180.Since #7645,
initRowcopies every field of the first retract record. The retracted value therefore becomes the starting accumulator,retract(90, 90)cancels it, and the+Uis added on top.This change:
ignore-retract) start from an empty accumulator: null for nullable fields, andFieldAggregator#emptyAccumulator()for NOT NULL fields (0forsum). A leading-U(90)now contributes-90, as it did before [core] Fix initRow in AggregateMergeFunction and PartialUpdateMergeFunction to set all fields including nullable ones #7645.getResult()writes the retracted amount in the DELETE record, for exampleDELETE(90)instead of the internal accumulator-90. The next merge retracts this record again, so a retraction-only flush followed by a later update keeps the right sum.FieldAggregator#retractionResult()does the conversion:sumnegates the accumulator and other aggregators return it unchanged. The accumulator itself is kept for later calls toadd().FieldIgnoreRetractAggdelegatesemptyAccumulator(), so NOT NULLignore-retractsums also start from zero.ignore-delete, keeps the retract payload when a key only has retractions, so the DELETE result is unchanged, and resets the row before the first positive record so the ignored value is not aggregated.partial-update.remove-record-on-delete,partial-update.remove-record-on-sequence-group) on the fullinitRowthat [core] Fix initRow in AggregateMergeFunction and PartialUpdateMergeFunction to set all fields including nullable ones #7645 introduced.product. Its retraction-only result can't be represented in the field type (1 / acctruncates to 0 for integer types), so+I(5)followed by-U(5), +U(5)still reads 25, as on master. Tracked in [Bug] Partial-update product counts a retracted value twice when a merge starts with a retraction #11465.Tests
PartialUpdateFirstRetractTest(merge-function level):UPDATE_BEFOREorDELETEfollowed by+U, then compaction with the old value;ignore-retractfields, including anignore-retractsum;ignore-deletewith historical retractions, including a key with only retractions;remove-record-on-deletepayloads.PartialUpdateFirstRetractTableTest(table level), withchangelog-producer=none,inputandlookupwhere applicable:+I(90)and then-U(90), +U(90 | 60), and checks the data read and the changelog;+I(40), +I(50), then-U(40), -U(50), then+U(60), and checks that it reads0after the second commit and60after the third;productwith a retraction-only commit.FieldAggregatorTest:emptyAccumulator()andretractionResult()forsumandproduct.Results on JDK 11 at 55e140d:
PartialUpdateFirstRetractTestandPartialUpdateFirstRetractTableTestfail. The table tests read180instead of90, and140instead of0after the retraction-only commit. The other 3 cases pass without the change too; they are compatibility controls for the DELETE-only payload,remove-record-on-deleteand the NOT NULLproductcase.PartialUpdateFirstRetractTest,PartialUpdateFirstRetractTableTest,PartialUpdateMergeFunctionTest,LookupChangelogMergeFunctionWrapperTestandFieldAggregatorTestpass: 222 tests. The run used Mavenverifywith-pl paimon-core -am, which also passed Checkstyle, Spotless, Enforcer and RAT.