sweb commented on a change in pull request #9047:
URL: https://github.com/apache/arrow/pull/9047#discussion_r550975265



##########
File path: rust/parquet/src/arrow/schema.rs
##########
@@ -591,6 +591,7 @@ impl ParquetTypeConverter<'_> {
             LogicalType::INT_32 => Ok(DataType::Int32),
             LogicalType::DATE => Ok(DataType::Date32(DateUnit::Day)),
             LogicalType::TIME_MILLIS => 
Ok(DataType::Time32(TimeUnit::Millisecond)),
+            LogicalType::DECIMAL => self.to_decimal(),

Review comment:
       The cast is necessary, because downcasting an i32 array to i64 results 
in None, panicking as a result. I have removed the cast and handle the building 
of the decimal array now separately, but I do not really like my solution:
   
   ```
                   let mut builder = DecimalBuilder::new(array.len(), *p, *s);
                   match array.data_type() {
                       ArrowType::Int32 => {
                           let values = 
array.as_any().downcast_ref::<Int32Array>().unwrap();
                           for maybe_value in values.iter() {
                               match maybe_value {
                                   Some(value) => builder.append_value(value as 
i128)?,
                                   None => builder.append_null()?,
                               }
                           }
                       }
                       ArrowType::Int64 => {
                           let values = 
array.as_any().downcast_ref::<Int64Array>().unwrap();
                           for maybe_value in values.iter() {
                               match maybe_value {
                                   Some(value) => builder.append_value(value as 
i128)?,
                                   None => builder.append_null()?,
                               }
                           }
                       }
                       _ => {
                           return Err(ArrowError(format!(
                               "Cannot convert {:?} to decimal",
                               array.data_type()
                           )))
                       }
                   }
   ```
   
   At the moment, I am not able to convince the compiler to treat downcasts to 
i32 and i64 as the same primitive array and then use `as` on the resulting 
iterator to convert from types that are unknown at compile time to `i128`. I 
will probably need to spend some time figuring this out.
   
   Alternatively, we could use converters, similar to the fixed length case.




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

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to