qzyu999 commented on code in PR #474:
URL: https://github.com/apache/fluss-rust/pull/474#discussion_r3037536696


##########
crates/fluss/src/row/column_writer.rs:
##########
@@ -550,15 +576,507 @@ impl ColumnWriter {
                 )?);
                 Ok(())
             }
+            TypedWriter::List {
+                element_type,
+                builder,
+            } => {
+                let array = row.get_array(pos)?;
+                let values_builder = builder.values();
+                for i in 0..array.size() {
+                    append_element_to_builder(values_builder, &array, i, 
element_type)?;
+                }
+                builder.append(true);
+                Ok(())
+            }
+        }
+    }
+}
+
+fn create_builder(
+    fluss_type: &DataType,
+    arrow_type: &ArrowDataType,
+    capacity: usize,
+) -> Result<Box<dyn ArrayBuilder>> {
+    match fluss_type {
+        DataType::Boolean(_) => 
Ok(Box::new(BooleanBuilder::with_capacity(capacity))),
+        DataType::TinyInt(_) => 
Ok(Box::new(Int8Builder::with_capacity(capacity))),
+        DataType::SmallInt(_) => 
Ok(Box::new(Int16Builder::with_capacity(capacity))),
+        DataType::Int(_) => 
Ok(Box::new(Int32Builder::with_capacity(capacity))),
+        DataType::BigInt(_) => 
Ok(Box::new(Int64Builder::with_capacity(capacity))),
+        DataType::Float(_) => 
Ok(Box::new(Float32Builder::with_capacity(capacity))),
+        DataType::Double(_) => 
Ok(Box::new(Float64Builder::with_capacity(capacity))),
+        DataType::Char(_) | DataType::String(_) => 
Ok(Box::new(StringBuilder::with_capacity(
+            capacity,
+            capacity.saturating_mul(VARIABLE_WIDTH_AVG_BYTES),
+        ))),
+        DataType::Bytes(_) => Ok(Box::new(BinaryBuilder::with_capacity(
+            capacity,
+            capacity.saturating_mul(VARIABLE_WIDTH_AVG_BYTES),
+        ))),
+        DataType::Binary(t) => {
+            let arrow_len: i32 = t.length().try_into().map_err(|_| 
Error::IllegalArgument {
+                message: format!(
+                    "Binary length {} exceeds Arrow's maximum (i32::MAX)",
+                    t.length()
+                ),
+            })?;
+            Ok(Box::new(FixedSizeBinaryBuilder::with_capacity(
+                capacity, arrow_len,
+            )))
+        }
+        DataType::Decimal(_) => {
+            let (p, s) = match arrow_type {
+                ArrowDataType::Decimal128(p, s) => (*p, *s),
+                _ => {
+                    return Err(Error::IllegalArgument {
+                        message: format!(
+                            "Expected Decimal128 Arrow type for Decimal, got: 
{arrow_type:?}"
+                        ),
+                    });
+                }
+            };
+            let builder = Decimal128Builder::with_capacity(capacity)
+                .with_precision_and_scale(p, s)
+                .map_err(|e| Error::IllegalArgument {
+                    message: format!("Invalid decimal precision {p} or scale 
{s}: {e}"),
+                })?;
+            Ok(Box::new(builder))
+        }
+        DataType::Date(_) => 
Ok(Box::new(Date32Builder::with_capacity(capacity))),
+        DataType::Time(_) => match arrow_type {
+            ArrowDataType::Time32(arrow_schema::TimeUnit::Second) => {
+                Ok(Box::new(Time32SecondBuilder::with_capacity(capacity)))
+            }
+            ArrowDataType::Time32(arrow_schema::TimeUnit::Millisecond) => {
+                Ok(Box::new(Time32MillisecondBuilder::with_capacity(capacity)))
+            }
+            ArrowDataType::Time64(arrow_schema::TimeUnit::Microsecond) => {
+                Ok(Box::new(Time64MicrosecondBuilder::with_capacity(capacity)))
+            }
+            ArrowDataType::Time64(arrow_schema::TimeUnit::Nanosecond) => {
+                Ok(Box::new(Time64NanosecondBuilder::with_capacity(capacity)))
+            }
+            _ => Err(Error::IllegalArgument {
+                message: format!("Unsupported Arrow type for Time: 
{arrow_type:?}"),
+            }),
+        },
+        DataType::Timestamp(_) => match arrow_type {
+            ArrowDataType::Timestamp(arrow_schema::TimeUnit::Second, _) => {
+                Ok(Box::new(TimestampSecondBuilder::with_capacity(capacity)))
+            }
+            ArrowDataType::Timestamp(arrow_schema::TimeUnit::Millisecond, _) 
=> Ok(Box::new(
+                TimestampMillisecondBuilder::with_capacity(capacity),
+            )),
+            ArrowDataType::Timestamp(arrow_schema::TimeUnit::Microsecond, _) 
=> Ok(Box::new(
+                TimestampMicrosecondBuilder::with_capacity(capacity),
+            )),
+            ArrowDataType::Timestamp(arrow_schema::TimeUnit::Nanosecond, _) => 
Ok(Box::new(
+                TimestampNanosecondBuilder::with_capacity(capacity),
+            )),
+            _ => Err(Error::IllegalArgument {
+                message: format!("Unsupported Arrow type for Timestamp: 
{arrow_type:?}"),
+            }),
+        },
+        DataType::TimestampLTz(_) => match arrow_type {
+            ArrowDataType::Timestamp(arrow_schema::TimeUnit::Second, _) => {
+                Ok(Box::new(TimestampSecondBuilder::with_capacity(capacity)))
+            }
+            ArrowDataType::Timestamp(arrow_schema::TimeUnit::Millisecond, _) 
=> Ok(Box::new(
+                TimestampMillisecondBuilder::with_capacity(capacity),
+            )),
+            ArrowDataType::Timestamp(arrow_schema::TimeUnit::Microsecond, _) 
=> Ok(Box::new(
+                TimestampMicrosecondBuilder::with_capacity(capacity),
+            )),
+            ArrowDataType::Timestamp(arrow_schema::TimeUnit::Nanosecond, _) => 
Ok(Box::new(
+                TimestampNanosecondBuilder::with_capacity(capacity),
+            )),
+            _ => Err(Error::IllegalArgument {
+                message: format!("Unsupported Arrow type for TimestampLTz: 
{arrow_type:?}"),
+            }),
+        },
+        DataType::Array(array_type) => {
+            let element_type = array_type.get_element_type();
+            let arrow_element_type = match arrow_type {
+                ArrowDataType::List(field) | ArrowDataType::LargeList(field) 
=> field.data_type(),

Review Comment:
   Hi @leekeiabstraction, responded to this in the above reply.



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