Skip to content

feat(core): support sort manifest entries by partition#7866

Open
baiyangtx wants to merge 6 commits into
apache:masterfrom
baiyangtx:manifest-sort
Open

feat(core): support sort manifest entries by partition#7866
baiyangtx wants to merge 6 commits into
apache:masterfrom
baiyangtx:manifest-sort

Conversation

@baiyangtx
Copy link
Copy Markdown
Contributor

Purpose

Manifest entries are currently written in arrival order, which scatters entries belonging
to the same partition across multiple manifest files. This leads to:

  • Inefficient partition-pruning during reads — the reader must scan many manifest files
    to find all entries for a single partition.
  • Suboptimal data locality when compaction reorganizes files.

This PR introduces manifest entry sorting by partition, so that entries for the same
partition are clustered together within manifest files.

Changes

New configuration options:

Option Default Description
manifest.merge.sorted true Sort entries by partition during manifest full compaction
manifest.merge.sort-on-commit false Sort entries by partition during manifest full merge in commit
manifest.delta.sorted true Sort entries by partition when writing manifest delta

Core implementation:

  • ManifestFileMerger: Introduces mergeSortedByPartition() and mergeUnsorted().
    When manifest.merge.sorted is enabled, entries are collected into a
    BinaryExternalSortBuffer (with spill-to-disk support), then written in
    partition-major order: (partition, bucket, level).
  • ManifestFileMerger.createManifestEntryComparator(): Comparator used for
    sorting delta manifests, falling back to pure-Java comparison when codegen
    is unavailable.
  • FileStoreCommitImpl: Wires sort parameters into all three paths —
    commit manifest merge, delta file writing, and manifest compaction.

Tests

# Manifest merge with sorting
mvn -pl paimon-core -am -DfailIfNoTests=false \
    -Dtest=ManifestFileMetaTest test

# No-partition edge case
mvn -pl paimon-core -am -DfailIfNoTests=false \
    -Dtest=NoPartitionManifestFileMetaTest test

# Spark compact procedure
mvn -pl paimon-spark/paimon-spark-ut -am -DfailIfNoTests=false \
    -Dtest=CompactProcedureTestBase test

- Sort delta entries during commit
- Sort base entries via full merge

See merge request: !854
zhangyongxiang.alpha added 5 commits May 18, 2026 11:34
The manifest entry sorting feature introduced in the parent commit
used FileKind.DELETE in mergeUnsorted() and mergeSortedByPartition()
without importing org.apache.paimon.manifest.FileKind, causing all
modules that depend on paimon-core to fail compilation.
The sorting refactor eliminated the single call to sequentialBatchedExecute,
but left the static import, causing Checkstyle to fail the build.
- FileStoreCommitImpl: use options.xxx() instead of local variables
  (manifestTargetSize, manifestMergeMinCount, etc. don't exist)
- FileStoreCommitImpl: replace coreOptions with options
- ManifestFileMerger: replace entry.toBytes() with
  entrySerializer.serializeToBytes() (toBytes() doesn't exist on apache/master)
- ManifestFileMerger: extract createPartitionRecordComparator() to handle
  partition row comparison (InternalRowUtils.compare takes DataTypeRoot,
  not RowType; newRecordComparator takes boolean[], not boolean)
- Remove stale reader Function referencing deleted readForFullCompaction
- Add missing DataType import, remove unused Function/singletonList imports
createPartitionRecordComparator now returns RecordComparator instead of
Comparator<BinaryRow>, since RecordComparator extends
Comparator<InternalRow> and newRecordComparator already returns
RecordComparator. This avoids a type incompatibility at the assignment
site where the result was used as RecordComparator.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant