← Back to Pull requests

fix(core): align collect aggregation with Java FieldCollectAgg #1352

Closed
unknown closed this pull request without merging on Nov 16, 2026 05:25 UTC
View on GitHub
unknown unknown commented on Nov 09, 2026 11:32 UTC
Author

Purpose

Linked issue: close #1351

collect ignored fields.<col>.count-limit, merged aggReversed in a different order from Java master, and checked distinct membership with a linear scan. This ports the merge logic of Java FieldCollectAgg as of apache/paimon#10540 and apache/paimon#10607.

Brief change log

  • Port of the private agg(accumulator, accumulatorHasDuplicate, input, inputHasDuplicate), including checkDuplicateUntil and backwards collection for negative limits. A DELETE value is kept as it is until the next merge.

  • count-limit is read as a 32-bit integer, like Java's intType option.

  • The ignore-retract wrapper passes agg_reversed to the wrapped function, as Java does.

  • Whether an element type uses the equaliser follows Java needsEqualiser on the Paimon type. Deciding by Arrow type put VARIANT, BLOB and VECTOR on the wrong path.

  • In distinct merges and retract, elements compare like Java: NaNs are one value, 0.0 and -0.0 are two, and map entries match by key. Types that Java keeps in a LinkedHashSet use arrow-row keys in a hash set.

  • Elements are kept in a VecDeque, so a late update through agg_reversed prepends instead of rebuilding the array, except for distinct equaliser element types with a negative limit.
  • Tests

  • count_limit_matches_java_for_scalar_and_row_elements: the cases of Java testFieldCollectAggWithCountLimit, forward and reversed.

  • agg_reversed_puts_older_input_first, ignore_retract_reversed_: reversed order, with and without the wrapper.

  • delete_value_, agg_reversed_keeps_duplicates_of_a_binary_delete_value: DELETE values per Java element type.

  • distinct_*_like_java: NaN payloads, signed zero and map entry order for scalar, ROW, ARRAY and MAP elements, including retract.
  • Benchmarks (release build, in-memory FileIO): writing 20,000 single-element rows for one key with distinct=true takes 5.6 ms (8.7 s on main). 20,000 single-element agg_reversed calls, as a sequence group makes for late updates, take 1.6 ms without distinct (1.5 ms on main) and 6.4 ms with distinct INT elements (4.4 s on main). Distinct ROW elements still compare each update with the collected elements, as Java's equaliser does.

    About 717k random steps generated by Java master's FieldCollectAgg match Rust on every step, covering INT, ROW, BYTES, DOUBLE with NaN, MAP, and ARRAY<ARRAY<MAP>> with binary inputs.

    API and Format

    No API or storage format change. Tables that set count-limit on a collect column now get capped arrays when Rust merges them. Maps nested in arrays match by key, as Java does since apache/paimon#11110.

    Documentation

    docs/src/sql.md documents count-limit for collect.

    Generated-by: Claude Opus

    Diff: 343 lines (+257 / -86) across 4 files Reviewer: LuciferYang Review duration: 9713m
    All Vouch review confidence checks passed
    Residual risk 0.17 = Change Risk (0.42) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.42 · 343 lines diff across 4 files
    0.42
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.349
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #1352"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 42.3% (MEDIUM) · Higher = larger blast radius
    42.3%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 16.7% · Safe to merge
    16.7%