[core] Support adaptive MAP and Variant shredding across rolling files#8827
[core] Support adaptive MAP and Variant shredding across rolling files#8827lxy-9602 wants to merge 3 commits into
Conversation
Adaptive Cross-File Inference for Variant Shredding1. SummaryPaimon currently infers a Variant shredding schema independently for every data file. Each file This document proposes an adaptive inference mode with three properties:
The prior is an optimization hint, not a correctness dependency. Every file remains self-describing, The state is intentionally scoped to one 2. MotivationIndependent per-file inference has three costs. 2.1 Repeated bufferingFor a stable input stream, adjacent files often infer almost identical schemas. Buffering the same 2.2 Physical-schema churnA field whose observed cardinality is close to 2.3 Weak inference for small filesSmall files may close before enough rows have been observed. A bounded prior supplies evidence from 3. Goals
4. Non-Goals
Query-aware pinned paths and table-level schema pinning are complementary future features. 5. Current Behavior
The current selection limits are:
6. Design OverviewAdaptive inference introduces one in-memory The first file uses the existing cold-sample limit. Later files use a smaller warm-sample limit.
7. State Scope and Lifecycle7.1 ScopeThe session belongs to a single The session must not be stored in:
There is no globally meaningful "previous file" when multiple tasks write concurrently. 7.2 Lifecycle
No extra commit protocol is required because the state is ephemeral and cannot be observed by 8. Inference EvidenceThe implementation should separate analysis from schema materialization. The current A conceptual model is: final class VariantShreddingInferenceState {
private final Map<List<Integer>, VariantColumnEvidence> columns;
private final RowType previousPhysicalRowType;
private final long completedFileCount;
}
final class VariantColumnEvidence {
private final double effectiveRootValueCount;
private final Map<VariantFieldPath, FieldEvidence> fields;
}
final class FieldEvidence {
private final double effectivePresenceCount;
private final DataType previousSelectedType;
private final boolean previouslySelected;
}The actual implementation may use compact tree nodes instead of path-keyed maps. Field paths and For the first version, the reusable evidence only needs:
The current sample still supplies exact type observations. Persisting a complete type histogram or 8.1 Cardinality denominatorTo preserve current behavior, a nested field's cardinality remains relative to the number of Each Variant column maintains its own denominator. If the current prefix contains no non-null value 9. Combining Prior and Current EvidenceRaw counts from the cold sample must not dominate all future files. The prior is therefore converted Let:
For each Variant column:
Conceptually: With a full warm sample and the default equal cap, the previous evidence and the current file have The first file may analyze up to the existing 4,096-row limit, but its evidence is scaled down before 10. Hysteresis and Field SelectionLet:
The proposed default is: A field is eligible when: This gap prevents a field near 10% from alternating between shredded and unshredded layouts on 10.1 Width-budget orderingHysteresis must not allow stale fields to permanently occupy a full width budget. Eligible fields
Parent nodes required to reach a selected child are included before the child. Existing width and 11. Type Selection and CorrectionField-membership hysteresis must not make type changes unnecessarily sticky. For a path selected in the previous plan:
For a newly admitted path, infer its type from the current sample using the existing rules. This policy deliberately applies hysteresis to field membership, but immediate correction to Values after the sampled prefix may still fail to fit the selected type. They remain lossless in the A follow-up design may select the most common compatible type with a configurable fit threshold, 12. Buffer LimitsThe adaptive mode uses:
Inference should also stop at a byte limit. A row-only limit is insufficient when a small number of The writer should finalize its plan when either limit is reached: The byte estimator does not need to model Java object overhead exactly. It should conservatively 13. Writer IntegrationThe smallest integration is to create the format writer factory once per Today, inside the per-file supplier. In adaptive mode, it should happen once when the supplier is built. Per-file components must remain per-file:
Only the reusable
The factory is used sequentially by one rolling writer. It is not advertised as thread-safe and 14. ConfigurationThe following options are proposed:
The existing options continue to define:
The initial release should keep 15. Correctness and Compatibility15.1 Read correctnessEach file persists its own physical Variant shredding schema. Readers already support different Values incompatible with a typed field are encoded in 15.2 Data skippingA stale type may increase non-null Future full-file fallback metrics should be used to detect paths whose typed layout is not 15.3 Backward compatibility
16. Failure, Retry, and Concurrency Semantics
17. ObservabilityAdaptive mode should expose metrics or debug counters for:
The schema fingerprint should be deterministic and suitable for measuring churn, but it does not 18. Test Plan18.1 Unit testsAdd focused tests for:
18.2 Writer integration testsUse a small target file size to force one rolling writer to create multiple Parquet files, then
18.3 BenchmarksCompare:
Use the following workloads:
Measure:
19. Rollout Plan
20. Alternatives Considered20.1 Reuse the previous physical schema without samplingThis minimizes buffering but cannot detect new hot paths or boundary-aligned schema changes. It may 20.2 Use a smaller independent sample for every fileThis reduces buffering but loses evidence for stable sparse fields and increases threshold noise. 20.3 Read the previous file footerThe footer exposes the selected physical schema but not the observations that caused the selection, 20.4 Persist one table-wide learned schemaThis can provide stronger stability but requires coordination, evolution rules, ownership, and 20.5 Aggregate compaction input schemasThis is useful for compaction because there is no single representative previous input file. 21. Open Questions
22. References |
|
I used AI to create a design; I hope you find it useful. |
906a92a to
189a50b
Compare
Purpose
This is a subtask of MAP shared-shredding support.
This PR stabilizes shredding layouts across files created by the same rolling writer without reading historical files.
max-columnsfor the first file, then adjustsKfrom bounded statistics reported by completed files.Tests
paimon-commonandpaimon-coretests pass, together with Spotless and diff checks.