tustvold commented on code in PR #3431:
URL: https://github.com/apache/arrow-rs/pull/3431#discussion_r1060487459


##########
parquet/src/arrow/arrow_writer/mod.rs:
##########
@@ -129,14 +137,51 @@ impl<W: Write> ArrowWriter<W> {
     /// and drop any fully written `RecordBatch`
     pub fn write(&mut self, batch: &RecordBatch) -> Result<()> {
         // validate batch schema against writer's supplied schema
-        if self.arrow_schema != batch.schema() {
+        if self.arrow_schema != batch.schema()
+            || self.arrow_schema.fields().len() != 
self.parquet_schema.columns().len()
+        {
             return Err(ParquetError::ArrowError(
                 "Record batch schema does not match writer schema".to_string(),
             ));
         }
 
-        for (buffer, column) in self.buffer.iter_mut().zip(batch.columns()) {
-            buffer.push_back(column.clone())
+        for ((buffer, column), parquet_column_field) in self
+            .buffer
+            .iter_mut()
+            .zip(batch.columns())
+            .zip(self.parquet_schema.columns())
+        {
+            match column.data_type() {
+                // if the arrow data type is decimal
+                ArrowDataType::Decimal128(_, _) => {
+                    match parquet_column_field.as_ref().physical_type() {
+                        // the physical data type is not fixed length byte 
array
+                        // convert the decimal array to the INT32/INT64 array
+                        Type::INT32 => {
+                            let new_array = column
+                                .as_any()
+                                .downcast_ref::<Decimal128Array>()
+                                .unwrap()
+                                .iter()
+                                .map(|v| v.map(|v| v as i32))
+                                .collect::<Int32Array>();
+                            buffer.push_back(Arc::new(new_array))
+                        }
+                        Type::INT64 => {
+                            let new_array = column
+                                .as_any()
+                                .downcast_ref::<Decimal128Array>()
+                                .unwrap()
+                                .iter()
+                                .map(|v| v.map(|v| v as i64))
+                                .collect::<Int64Array>();

Review Comment:
   ```suggestion
                                   .unary::<_, Int64Array>(|v| v as i64);
   ```



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