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.
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) empty. 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.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.Tests
PartialUpdateFirstRetractTest(merge-function level):UPDATE_BEFOREorDELETEfollowed by+U, then compaction with the old value;ignore-retractfields;ignore-deletewith historical retractions, including a key with only retractions;remove-record-on-deletepayloads.PartialUpdateFirstRetractTableTest(table level): commits+I(90)and then-U(90), +U(90 | 60). It checks the data read and the changelog forchangelog-producer=none,inputandlookup.Results on JDK 11:
df565c64f7without the main-code change, 14 of the 16 new cases fail. The table test readsamount = 180instead of90with all three changelog producers. The other 2 cases pass on master too; they are compatibility controls for the DELETE-only payload andremove-record-on-delete.PartialUpdateFirstRetractTest,PartialUpdateFirstRetractTableTest,PartialUpdateMergeFunctionTestandLookupChangelogMergeFunctionWrapperTestpass: 94 tests. The run used Mavenverifywith-pl paimon-core -am, which also passed Checkstyle, Spotless, Enforcer and RAT.