Skip to content

fix(arrow): map Iceberg Binary to Arrow Binary instead of LargeBinary - #2710

Merged
szehon-ho merged 3 commits into
apache:mainfrom
viirya:fix/2698-binary-to-arrow-binary
Nov 3, 2026
Merged

szehon-ho merged 3 commits into
apache:mainfrom
viirya:fix/2698-binary-to-arrow-binary

Conversation

@viirya

@viirya viirya commented Jun 25, 2026 •

Copy link
Copy Markdown
Member

Which issue does this PR close?

What changes are included in this PR?

type_to_arrow_type mapped PrimitiveType::Binary to DataType::LargeBinary. This is inconsistent with:

  1. Java: ArrowSchemaUtil maps Iceberg BinaryType to Arrow Binary (ArrowType.Binary.INSTANCE), and FixedType to FixedSizeBinary.
  2. parquet-rs: an unannotated Parquet BYTE_ARRAY column (no UTF8/String logical type) is read as DataType::Binary by default. LargeBinary only appears when the file's embedded Arrow schema metadata or a user-supplied schema forces it.
  3. This crate's constant columns: primitive_type_to_arrow_type_with_ree already materializes Iceberg Binary constants (e.g. _partition fields) as Binary, so the same column currently gets LargeBinary from schema_to_arrow_schema and Binary from the constant path.

The mismatch forces an unnecessary cast when reading Binary columns and diverges from the rest of the ecosystem.

This PR maps PrimitiveType::Binary to DataType::Binary (crates/iceberg/src/arrow/schema.rs).

Caller-visible change: schema_to_arrow_schema / type_to_arrow_type now return Binary for Iceberg binary fields, and scan output for those columns is BinaryArray instead of LargeBinaryArray. Consumers that downcast to LargeBinaryArray or compare against the old Arrow schema need to adapt.

LargeBinary input

Input arrays that are still LargeBinary are handled as follows:

  • Reading files written with LargeBinary (e.g. by older iceberg-rust, whose embedded Arrow schema says LargeBinary): the record batch transformer casts them to the Binary target type.
  • Writing:
    • ParquetWriter accepts LargeBinary arrays for a Binary column as before.
    • RecordBatchProjector::project_column casts LargeBinary columns to Binary when the projected field is Binary. It is shared by the equality delete writer and PartitionValueCalculator, both of which build their output against the new Binary type and would otherwise fail on LargeBinary input. The cast also lets truncate partitions on binary fields accept LargeBinary input; that transform only handled Binary arrays.
    • The cast fails, with an error, if a single batch's binary data exceeds the 2 GiB that 32-bit offsets can address. Such batches cannot be written through these two paths.
  • Unchanged conversions: arrow_schema_to_schema still accepts Binary | LargeBinary | BinaryView → Iceberg Binary. The arrow-to-literal path (arrow/value.rs) and the bucket transform still handle both Binary and LargeBinary.

Not changed

  • Geometry / Geography stay on LargeBinary. They shared a match arm with Binary after the geospatial work, and that choice is deliberate (64-bit offsets for the array's total WKB bytes, matched by the REE constant path), so this PR splits the arm rather than moving them.
  • Fixed stays FixedSizeBinary, with the rarely-hit LargeBinary fallback for lengths exceeding i32::MAX.
  • The LargeBinary arm that feat: add support for _partition metadata column #2668 added for _partition constants is no longer hit for Iceberg Binary, but is kept as a fallback.

Are these changes tested?

  • test_schema_to_arrow_schema / test_arrow_schema_to_schema exercise both directions of the mapping and now assert Binary. The parquet_writer and equality_delete_writer tests that fed LargeBinaryArray for an Iceberg Binary column now use BinaryArray.
  • New regression tests for LargeBinary input:
    • test_equality_delete_accepts_large_binary_input: equality delete writer.
    • test_partition_calculator_binary_partition_accepts_large_binary_input: identity and truncate partitions on a binary field.

AI Disclosure

Rebased onto main, review fixes, and description updated with AI assistance. Worth a reviewer's look:

  • whether any downstream consumer relies on Iceberg Binary arriving as LargeBinary;
  • whether the narrow LargeBinary → Binary cast in project_column is the right place for input compatibility;
  • whether keeping Geometry/Geography on LargeBinary is the right call.

This pull request and its description were written by Isaac.

@viirya viirya closed this Jun 25, 2026
@viirya viirya reopened this Oct 29, 2026
`type_to_arrow_type` mapped `PrimitiveType::Binary` to `DataType::LargeBinary`,
which is inconsistent with both the Java implementation
(`ArrowSchemaUtil` maps Iceberg Binary to Arrow `Binary`) and parquet-rs,
which reads an unannotated Parquet `BYTE_ARRAY` column as `DataType::Binary`
by default. The mismatch forces an unnecessary cast when reading Binary
columns and diverges from the rest of the ecosystem.

Map `PrimitiveType::Binary` to `DataType::Binary`. The reverse conversion
(`arrow_schema_to_schema`), the arrow-to-literal path, and the bucket
transform already accept both `Binary` and `LargeBinary`, so externally
produced `LargeBinary` columns keep working.

Closes apache#2698
@viirya
viirya force-pushed the fix/2698-binary-to-arrow-binary branch from b442887 to 9dac295 Compare October 29, 2026 22:48
Copilot AI balanced review requested due to automatic review settings October 29, 2026 22:48

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

2 open issues
What changed in this PR

Aligns Iceberg → Arrow type mapping with ecosystem expectations by mapping Iceberg Binary to Arrow Binary (instead of LargeBinary), and updates affected tests/fixtures accordingly.

Changes:

  • Map PrimitiveType::Binary to DataType::Binary in Arrow schema conversion.
  • Update Arrow schema round-trip fixtures to expect Binary for binary fields and list elements.
  • Update writer tests to use BinaryArray instead of LargeBinaryArray for Iceberg Binary columns.
File Description
crates/​iceberg/​src/​arrow/​schema.rs Switches Iceberg Binary → Arrow Binary mapping and updates schema conversion fixtures.
crates/​iceberg/​src/​writer/​file_writer/​parquet_writer.rs Adjusts Parquet writer test input arrays to BinaryArray for binary columns.
crates/​iceberg/​src/​writer/​base_writer/​equality_delete_writer.rs Adjusts equality delete writer test input arrays to BinaryArray for binary columns.

Review effort: Lite

Comment on lines +767 to +769
Some(b"one".as_slice()),
Some(b"".as_slice()),
Some(b"zzzz".as_slice()),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems ok to me, its consistent with the other ones. can probably remove it as another pr if its not necessary

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dropped the .as_slice() calls in both test fixtures in 203bd70. from_opt_vec infers &[u8] without them.

Comment on lines +1380 to 1385
let col6 = Arc::new(arrow_array::BinaryArray::from_opt_vec(vec![
Some(b"one".as_slice()),
None,
Some(b""),
Some(b"zzzz"),
Some(b"".as_slice()),
Some(b"zzzz".as_slice()),
])) as ArrayRef;
.unwrap_or(DataType::LargeBinary),
)),
PrimitiveType::Binary | PrimitiveType::Geometry(_) | PrimitiveType::Geography(_) => {
PrimitiveType::Binary => Ok(ArrowSchemaOrFieldOrType::Type(DataType::Binary)),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please preserve LargeBinaryArray input support in the equality-delete writer and add a regression test. Its projector now uses a Binary schema but reuses the input arrays without casting, so previously accepted batches with LargeBinaryArray equality columns fail RecordBatch::try_new with a type mismatch.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, confirmed with a test: before the fix, a batch with a LargeBinaryArray equality column failed with expected Binary but found LargeBinary. Fixed in 203bd70: RecordBatchProjector::project_batch now casts LargeBinary columns to Binary when the projected field is Binary (other mismatches still error, and the cast errors rather than truncating if the data exceeds 32-bit offsets). Added test_equality_delete_accepts_large_binary_input.

I also checked the other paths that see the new Binary schema: ParquetWriter still accepts LargeBinary input for a Binary column, and the partition splitter/value calculator only use project_column, so they see the same arrays as before.

…ping change

With Iceberg Binary now mapped to Arrow Binary, the equality delete
projector builds its output batch against a Binary schema while reusing
the input arrays as-is, so batches carrying LargeBinaryArray equality
columns (accepted before) failed RecordBatch::try_new. Cast LargeBinary
to Binary in RecordBatchProjector::project_batch and add a regression
test. Also drop redundant `.as_slice()` in test fixtures.

Co-authored-by: Isaac <[email protected]>

@szehon-ho szehon-ho left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make the caller-visible behavior change explicit in the PR description: Iceberg binary fields now map to Arrow Binary, and ordinary read output uses BinaryArray instead of LargeBinaryArray. Consumers relying on the old Arrow type may need to adapt. Please also qualify “externally produced LargeBinary columns keep working” to account for the partition-calculator issue and the 32-bit offset limit of the new casts. The description and test section should also mention the equality-delete compatibility fix and its regression test.

.unwrap_or(DataType::LargeBinary),
)),
PrimitiveType::Binary | PrimitiveType::Geometry(_) | PrimitiveType::Geography(_) => {
PrimitiveType::Binary => Ok(ArrowSchemaOrFieldOrType::Type(DataType::Binary)),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also preserve LargeBinaryArray input in PartitionValueCalculator and add a regression test for a binary identity partition. calculate() now expects a Binary field but uses project_column(), which leaves the array as LargeBinary; the identity transform passes it through and StructArray::try_new fails. The new cast in project_batch() doesn't cover this path.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, and my earlier reply was wrong about this path: the input arrays are unchanged, but calculate() builds the struct against partition_arrow_type, which is now Binary. Reproduced with a test, then fixed in be68461 by moving the LargeBinary → Binary cast from project_batch() into project_column(), so both the equality delete writer and PartitionValueCalculator get columns matching the projected schema.

The regression test test_partition_calculator_binary_partition_accepts_large_binary_input covers identity and truncate partitions on a binary field. Truncate is included because it only handled BinaryArray, so it rejected LargeBinary input even before this PR; the cast fixes that too.

I also rechecked the read side: record_batch_transformer builds targets from type_to_arrow_type, but its PromotePlan falls back to cast on a type mismatch, so LargeBinary columns from files written by older versions are cast to Binary.

…ulation

PartitionValueCalculator builds its result struct against the partition
Arrow type, which now uses Binary for Iceberg binary fields, while the
identity transform passes the projected LargeBinary column through, so
StructArray::try_new failed. Move the LargeBinary -> Binary cast from
RecordBatchProjector::project_batch into project_column so both callers
get columns matching the projected schema. This also lets truncate
partitions on binary fields accept LargeBinary input.

Co-authored-by: Isaac <[email protected]>
@viirya

viirya commented Nov 3, 2026

Copy link
Copy Markdown
Member Author

Updated the description:

  • It states the caller-visible change: Iceberg binary fields map to Arrow Binary and scan output is BinaryArray, so consumers relying on LargeBinaryArray need to adapt.
  • It replaces "externally produced LargeBinary columns keep working" with a per-path breakdown (read, writer, projector), including the 2 GiB per-batch limit of the new cast.
  • The test section lists the equality-delete and partition-calculator regression tests.

@szehon-ho szehon-ho left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me. there's some behave change, but seems a fix overall

@szehon-ho
szehon-ho added this pull request to the merge queue Nov 3, 2026
Merged via the queue into apache:main with commit 200ee65 Nov 3, 2026
25 checks passed
@viirya
viirya deleted the fix/2698-binary-to-arrow-binary branch November 3, 2026 23:44
@viirya

viirya commented Nov 3, 2026

Copy link
Copy Markdown
Member Author

Thanks @szehon-ho !

gabotechs pushed a commit to apache/datafusion-iceberg that referenced this pull request Nov 24, 2026
b879b962 is the last iceberg-rust commit before the Arrow 60 bump, so
this stays on Arrow 59 and DataFusion 55. It includes
apache/iceberg-rust#2904 (unpinned scans project the current schema),
#3303 (strip metadata from list and map fields) and #3406
(Table::with_runtime keeps the manifest cache).

apache/iceberg-rust#2710 maps Iceberg binary to Arrow Binary instead of
LargeBinary, so the binary predicate pushdown plan now shows Binary
literals.
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.

map Iceberg Binary to Arrow Binary instead of LargeBinary

3 participants