You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2023/01/10 13:23:27 UTC

[GitHub] [arrow-rs] liukun4515 commented on a diff in pull request #3431: Support decimal int32/64 for writer

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


##########
parquet/src/arrow/schema/mod.rs:
##########
@@ -399,21 +399,32 @@ fn arrow_to_parquet_type(field: &Field) -> Result<Type> {
                 .with_length(*length)
                 .build()
         }
-        DataType::Decimal128(precision, scale)
-        | DataType::Decimal256(precision, scale) => {
+        DataType::Decimal128(precision, scale) => {
             // Decimal precision determines the Parquet physical type to use.
-            // TODO(ARROW-12018): Enable the below after ARROW-10818 Decimal support
-            //
-            // let (physical_type, length) = if *precision > 1 && *precision <= 9 {
-            //     (PhysicalType::INT32, -1)
-            // } else if *precision <= 18 {
-            //     (PhysicalType::INT64, -1)
-            // } else {
-            //     (
-            //         PhysicalType::FIXED_LEN_BYTE_ARRAY,
-            //         decimal_length_from_precision(*precision) as i32,
-            //     )
-            // };
+            // Following the: https://github.com/apache/parquet-format/blob/master/LogicalTypes.md#decimal
+            let (physical_type, length) = if *precision > 1 && *precision <= 9 {
+                (PhysicalType::INT32, -1)
+            } else if *precision <= 18 {
+                (PhysicalType::INT64, -1)
+            } else {
+                (
+                    PhysicalType::FIXED_LEN_BYTE_ARRAY,
+                    decimal_length_from_precision(*precision) as i32,
+                )
+            };
+            Type::primitive_type_builder(name, physical_type)
+                .with_repetition(repetition)
+                .with_length(length)
+                .with_logical_type(Some(LogicalType::Decimal {
+                    scale: *scale as i32,
+                    precision: *precision as i32,
+                }))
+                .with_precision(*precision as i32)
+                .with_scale(*scale as i32)
+                .build()
+        }
+        DataType::Decimal256(precision, scale) => {

Review Comment:
   Now we ignore the decimal 256



-- 
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: github-unsubscribe@arrow.apache.org

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