fresh-borzoni commented on code in PR #330:
URL: https://github.com/apache/fluss-rust/pull/330#discussion_r2810120288


##########
bindings/cpp/src/lib.rs:
##########
@@ -1632,128 +1632,247 @@ mod row_reader {
 
     use crate::types;
 
-    pub fn column_type(columns: &[fcore::metadata::Column], field: usize) -> 
i32 {
-        columns
-            .get(field)
-            .map_or(0, |c| types::core_data_type_to_ffi(c.data_type()))
+    /// Get column at `field`, or error if out of bounds.
+    fn get_column(
+        columns: &[fcore::metadata::Column],
+        field: usize,
+    ) -> Result<&fcore::metadata::Column, String> {
+        columns.get(field).ok_or_else(|| {
+            format!(
+                "field index {field} out of range ({} columns)",
+                columns.len()
+            )
+        })
     }
 
-    pub fn column_name(columns: &[fcore::metadata::Column], field: usize) -> 
&str {
-        columns.get(field).map_or("", |c| c.name())
+    /// Validate bounds, null, and type compatibility in a single pass.
+    /// Returns the data type on success for callers that need to dispatch on 
it.
+    fn validate<'a>(
+        row: &dyn InternalRow,
+        columns: &'a [fcore::metadata::Column],
+        field: usize,
+        getter: &str,
+        allowed: impl FnOnce(&fcore::metadata::DataType) -> bool,
+    ) -> Result<&'a fcore::metadata::DataType, String> {
+        let col = get_column(columns, field)?;
+        if row.is_null_at(field) {
+            return Err(format!("field {field} is null"));
+        }
+        let dt = col.data_type();

Review Comment:
   Investigated this thoroughly. The current behavior matches Rust's 
InternalRow contract: callers must check is_null_at() before calling typed 
getters. The same here with isNull() check.
   
   Added examples to match Rust tests.



-- 
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