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


##########
crates/fluss/src/row/column_writer.rs:
##########
@@ -0,0 +1,607 @@
+// 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.
+
+//! Typed column writers that write directly from [`InternalRow`] to concrete
+//! Arrow builders, bypassing the intermediate [`Datum`] enum and runtime
+//! `downcast_mut` dispatch.
+
+use crate::error::Error::RowConvertError;
+use crate::error::{Error, Result};
+use crate::metadata::DataType;
+use crate::row::InternalRow;
+use crate::row::datum::{
+    MICROS_PER_MILLI, MILLIS_PER_SECOND, NANOS_PER_MILLI, 
append_decimal_to_builder,
+    millis_nanos_to_micros, millis_nanos_to_nanos,
+};
+use arrow::array::{
+    ArrayBuilder, ArrayRef, BinaryBuilder, BooleanBuilder, Date32Builder, 
Decimal128Builder,
+    FixedSizeBinaryBuilder, Float32Builder, Float64Builder, Int8Builder, 
Int16Builder,
+    Int32Builder, Int64Builder, StringBuilder, Time32MillisecondBuilder, 
Time32SecondBuilder,
+    Time64MicrosecondBuilder, Time64NanosecondBuilder, 
TimestampMicrosecondBuilder,
+    TimestampMillisecondBuilder, TimestampNanosecondBuilder, 
TimestampSecondBuilder,
+};
+use arrow_schema::DataType as ArrowDataType;
+
+/// Estimated average byte size for variable-width columns (Utf8, Binary).
+/// Used to pre-allocate data buffers and avoid reallocations during batch 
building.
+const VARIABLE_WIDTH_AVG_BYTES: usize = 64;
+
+/// A typed column writer that reads one column from an [`InternalRow`] and
+/// appends directly to a concrete Arrow builder — no intermediate [`Datum`],
+/// no `as_any_mut().downcast_mut()`.
+pub struct ColumnWriter {
+    pos: usize,
+    nullable: bool,
+    inner: TypedWriter,
+}
+
+enum TypedWriter {
+    Bool(BooleanBuilder),
+    Int8(Int8Builder),
+    Int16(Int16Builder),
+    Int32(Int32Builder),
+    Int64(Int64Builder),
+    Float32(Float32Builder),
+    Float64(Float64Builder),
+    Char {
+        len: usize,
+        builder: StringBuilder,
+    },
+    String(StringBuilder),
+    Bytes(BinaryBuilder),
+    Binary {
+        len: usize,
+        builder: FixedSizeBinaryBuilder,
+    },
+    Decimal128 {
+        src_precision: usize,
+        src_scale: usize,
+        target_precision: u32,
+        target_scale: i64,
+        builder: Decimal128Builder,
+    },
+    Date32(Date32Builder),
+    Time32Second(Time32SecondBuilder),
+    Time32Millisecond(Time32MillisecondBuilder),
+    Time64Microsecond(Time64MicrosecondBuilder),
+    Time64Nanosecond(Time64NanosecondBuilder),
+    TimestampNtzSecond {
+        precision: u32,
+        builder: TimestampSecondBuilder,
+    },
+    TimestampNtzMillisecond {
+        precision: u32,
+        builder: TimestampMillisecondBuilder,
+    },
+    TimestampNtzMicrosecond {
+        precision: u32,
+        builder: TimestampMicrosecondBuilder,
+    },
+    TimestampNtzNanosecond {
+        precision: u32,
+        builder: TimestampNanosecondBuilder,
+    },
+    TimestampLtzSecond {
+        precision: u32,
+        builder: TimestampSecondBuilder,
+    },
+    TimestampLtzMillisecond {
+        precision: u32,
+        builder: TimestampMillisecondBuilder,
+    },
+    TimestampLtzMicrosecond {
+        precision: u32,
+        builder: TimestampMicrosecondBuilder,
+    },
+    TimestampLtzNanosecond {
+        precision: u32,
+        builder: TimestampNanosecondBuilder,
+    },
+}
+
+impl ColumnWriter {
+    /// Create a column writer for the given Fluss `DataType` and Arrow
+    /// `ArrowDataType` at position `pos` with the given pre-allocation
+    /// `capacity`.
+    pub fn create(
+        fluss_type: &DataType,
+        arrow_type: &ArrowDataType,
+        pos: usize,
+        capacity: usize,
+    ) -> Result<Self> {

Review Comment:
   Not applicable, The caller derives both from the same schema



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