Repository navigation
fix(arrow): map Iceberg Binary to Arrow Binary instead of LargeBinary - #2710
Conversation
`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
b442887 to
9dac295
Compare
There was a problem hiding this comment.
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::BinarytoDataType::Binaryin Arrow schema conversion. - Update Arrow schema round-trip fixtures to expect
Binaryfor binary fields and list elements. - Update writer tests to use
BinaryArrayinstead ofLargeBinaryArrayfor IcebergBinarycolumns.
| 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
| Some(b"one".as_slice()), | ||
| Some(b"".as_slice()), | ||
| Some(b"zzzz".as_slice()), |
There was a problem hiding this comment.
it seems ok to me, its consistent with the other ones. can probably remove it as another pr if its not necessary
There was a problem hiding this comment.
Dropped the .as_slice() calls in both test fixtures in 203bd70. from_opt_vec infers &[u8] without them.
| 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)), |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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)), |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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]>
|
Updated the description:
|
szehon-ho
left a comment
There was a problem hiding this comment.
looks good to me. there's some behave change, but seems a fix overall
|
Thanks @szehon-ho ! |
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.

Which issue does this PR close?
What changes are included in this PR?
type_to_arrow_typemappedPrimitiveType::BinarytoDataType::LargeBinary. This is inconsistent with:ArrowSchemaUtilmaps IcebergBinaryTypeto ArrowBinary(ArrowType.Binary.INSTANCE), andFixedTypetoFixedSizeBinary.BYTE_ARRAYcolumn (no UTF8/String logical type) is read asDataType::Binaryby default.LargeBinaryonly appears when the file's embedded Arrow schema metadata or a user-supplied schema forces it.primitive_type_to_arrow_type_with_reealready materializes IcebergBinaryconstants (e.g._partitionfields) asBinary, so the same column currently getsLargeBinaryfromschema_to_arrow_schemaandBinaryfrom 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::BinarytoDataType::Binary(crates/iceberg/src/arrow/schema.rs).Caller-visible change:
schema_to_arrow_schema/type_to_arrow_typenow returnBinaryfor Iceberg binary fields, and scan output for those columns isBinaryArrayinstead ofLargeBinaryArray. Consumers that downcast toLargeBinaryArrayor compare against the old Arrow schema need to adapt.LargeBinaryinputInput arrays that are still
LargeBinaryare handled as follows:LargeBinary(e.g. by older iceberg-rust, whose embedded Arrow schema saysLargeBinary): the record batch transformer casts them to theBinarytarget type.ParquetWriteracceptsLargeBinaryarrays for aBinarycolumn as before.RecordBatchProjector::project_columncastsLargeBinarycolumns toBinarywhen the projected field isBinary. It is shared by the equality delete writer andPartitionValueCalculator, both of which build their output against the newBinarytype and would otherwise fail onLargeBinaryinput. The cast also letstruncatepartitions on binary fields acceptLargeBinaryinput; that transform only handledBinaryarrays.arrow_schema_to_schemastill acceptsBinary | LargeBinary | BinaryView→ IcebergBinary. The arrow-to-literal path (arrow/value.rs) and the bucket transform still handle bothBinaryandLargeBinary.Not changed
Geometry/Geographystay onLargeBinary. They shared a match arm withBinaryafter 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.FixedstaysFixedSizeBinary, with the rarely-hitLargeBinaryfallback for lengths exceedingi32::MAX.LargeBinaryarm that feat: add support for _partition metadata column #2668 added for_partitionconstants is no longer hit for IcebergBinary, but is kept as a fallback.Are these changes tested?
test_schema_to_arrow_schema/test_arrow_schema_to_schemaexercise both directions of the mapping and now assertBinary. Theparquet_writerandequality_delete_writertests that fedLargeBinaryArrayfor an IcebergBinarycolumn now useBinaryArray.LargeBinaryinput: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:
Binaryarriving asLargeBinary;LargeBinary→Binarycast inproject_columnis the right place for input compatibility;LargeBinaryis the right call.This pull request and its description were written by Isaac.