You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iceberg.apache.org by li...@apache.org on 2025/07/01 10:34:30 UTC

(iceberg-rust) branch main updated: fix: fix batch transform modify schema (#1483)

This is an automated email from the ASF dual-hosted git repository.

liurenjie1024 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/iceberg-rust.git


The following commit(s) were added to refs/heads/main by this push:
     new 8edd7087 fix: fix batch transform modify schema (#1483)
8edd7087 is described below

commit 8edd7087bc982bfeca71a167c2f74b45720170b8
Author: Dylan <zi...@singularity-data.com>
AuthorDate: Tue Jul 1 18:34:25 2025 +0800

    fix: fix batch transform modify schema (#1483)
    
    ## Which issue does this PR close?
    
    - Previously, we used `record_batch.with_schema(target_schema.clone())`
    to change the schema name of a record batch, but unfortunately,
    `with_schema` would check the schema name and throw an error. So I think
    we should convert the RecordBatch like how `BatchTransform::Modify`
    does, but keep the same columns.
    
    ```rust
        pub fn with_schema(self, schema: SchemaRef) -> Result<Self, ArrowError> {
            if !schema.contains(self.schema.as_ref()) {
                return Err(ArrowError::SchemaError(format!(
                    "target schema is not superset of current schema target={schema} current={}",
                    self.schema
                )));
            }
    
            Ok(Self {
                schema,
                columns: self.columns,
                row_count: self.row_count,
            })
        }
    ```
    
    - Closes #.
    
    ## What changes are included in this PR?
    
    
    ## Are these changes tested?
---
 crates/iceberg/src/arrow/record_batch_transformer.rs | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/crates/iceberg/src/arrow/record_batch_transformer.rs b/crates/iceberg/src/arrow/record_batch_transformer.rs
index f231e0f2..779f1cc6 100644
--- a/crates/iceberg/src/arrow/record_batch_transformer.rs
+++ b/crates/iceberg/src/arrow/record_batch_transformer.rs
@@ -153,7 +153,14 @@ impl RecordBatchTransformer {
                 )?
             }
             Some(BatchTransform::ModifySchema { target_schema }) => {
-                record_batch.with_schema(target_schema.clone())?
+                let options = RecordBatchOptions::default()
+                    .with_match_field_names(false)
+                    .with_row_count(Some(record_batch.num_rows()));
+                RecordBatch::try_new_with_options(
+                    target_schema.clone(),
+                    record_batch.columns().to_vec(),
+                    &options,
+                )?
             }
             None => {
                 self.batch_transform = Some(Self::generate_batch_transform(