JunRuiLee commented on code in PR #420:
URL: https://github.com/apache/paimon-rust/pull/420#discussion_r3492785739


##########
bindings/python/src/write.rs:
##########
@@ -0,0 +1,184 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use std::sync::Arc;
+
+use arrow::datatypes::{DataType as ArrowDataType, Schema as ArrowSchema};
+use arrow::pyarrow::FromPyArrow;
+use arrow::record_batch::RecordBatch;
+use paimon::table::{CommitMessage, Table, TableCommit, TableWrite};
+use paimon_datafusion::runtime::runtime;
+use pyo3::exceptions::{PyTypeError, PyValueError};
+use pyo3::prelude::*;
+
+use crate::error::to_py_err;
+
+/// Validate an incoming batch schema against the table's target Arrow schema,
+/// replicating pypaimon's `_validate_pyarrow_schema` semantics (minus the
+/// projection-write branch PR1 lacks): field count, order, and names must 
match;
+/// types must match field-by-field, tolerating binary-family interchange
+/// (Binary / LargeBinary / FixedSizeBinary). The nullable flag is 
intentionally
+/// NOT compared, since `build_target_arrow_schema` derives nullability from 
the
+/// Paimon field while pyarrow-constructed batches infer nullable=true. No 
cast.
+fn validate_batch_schema(input: &ArrowSchema, target: &ArrowSchema) -> 
PyResult<()> {
+    let mismatch = || {
+        PyValueError::new_err(format!(
+            "Input schema is not consistent with the table schema. \
+             input: {input:?}, table: {target:?}"
+        ))
+    };
+    if input.fields().len() != target.fields().len() {
+        return Err(mismatch());
+    }
+    for (i, t) in input.fields().iter().zip(target.fields().iter()) {
+        if i.name() != t.name() {
+            return Err(mismatch());
+        }
+        if i.data_type() != t.data_type()
+            && !(is_binary_family(i.data_type()) && 
is_binary_family(t.data_type()))

Review Comment:
    Good catch — confirmed the lower write path downcasts binary fields to 
arrow_array::BinaryArray only, so tolerating LargeBinary/FixedSizeBinary here 
was a false positive. Made type matching strict (reject rather than cast, 
consistent with write_arrow not casting) and added a regression test. Fixed in 
2fe6b39.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to