Skip to content

RecordBatchPartitionSplitter::split returns partitions in hash order #3753

Open

Description

@CaptainAni187

Apache Iceberg Rust version

main (0.10.1)

Describe the bug

RecordBatchPartitionSplitter::split groups rows in a HashMap, so the (PartitionKey, RecordBatch) pieces come back in hash order, not in the order the partition values appear in the batch.

That breaks ClusteredWriter when its input is already sorted by partition. If a partition spans two batches, the splitter can hand back a later partition first, which closes the earlier one, and then the next batch tries to write to it again and fails with "Cannot write to partition that was previously closed".

Came across this through apache/datafusion-iceberg#39.... its fanout-disabled path feeds split straight into ClusteredWriter. There's a stopgap in apache/datafusion-iceberg#81 that sorts the pieces there, but it fits better in the splitter itself.

To Reproduce

Identity partition on an int column, sorted input written through ClusteredWriter in two batches:

  • batch 1: [1, 1, 2, 2]
  • batch 2: [2, 3]

When split returns batch 1 as (2), (1), writing 1 closes partition 2, and batch 2's 2 then fails. Which order you get changes from run to run.

Expected behavior

split returns the pieces in the order each partition value first appears in the batch, so sorted input stays sorted for the clustered writer.

Willingness to contribute

I can contribute a fix for this bug independently

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions