diff --git a/dataframe-parquet/src/DataFrame/IO/Parquet.hs b/dataframe-parquet/src/DataFrame/IO/Parquet.hs index bbfb774d..71f1d8cf 100644 --- a/dataframe-parquet/src/DataFrame/IO/Parquet.hs +++ b/dataframe-parquet/src/DataFrame/IO/Parquet.hs @@ -674,18 +674,14 @@ applyLogicalType (Just (LT_DECIMAL f)) col = scale = unField dt.decimal_scale precision = unField dt.decimal_precision in if precision <= 9 - then case DI.toVector @Int32 @VU.Vector col of - Right xs -> - DI.fromUnboxedVector $ - VU.map (\raw -> fromIntegral @Int32 @Double raw / 10 ^ scale) xs - Left _ -> col + then + fromRight col $ + DI.mapColumn (\raw -> fromIntegral @Int32 @Double raw / 10 ^ scale) col else if precision <= 18 - then case DI.toVector @Int64 @VU.Vector col of - Right xs -> - DI.fromUnboxedVector $ - VU.map (\raw -> fromIntegral @Int64 @Double raw / 10 ^ scale) xs - Left _ -> col + then + fromRight col $ + DI.mapColumn (\raw -> fromIntegral @Int64 @Double raw / 10 ^ scale) col else col applyLogicalType _ col = col diff --git a/tests/Parquet.hs b/tests/Parquet.hs index 5e48e136..dcb2dd30 100644 --- a/tests/Parquet.hs +++ b/tests/Parquet.hs @@ -823,6 +823,19 @@ int64Decimal = ) ) +nullableIntDecimal :: Test +nullableIntDecimal = testBothReadParquetPaths $ \readParquet -> + TestCase + ( assertEqual + "nullableIntDecimal" + ( D.fromNamedColumns + [ ("int32_dec", D.fromList [Just (1 :: Double), Nothing, Just 2.5, Just 0.75]) + , ("int64_dec", D.fromList [Nothing, Just (1234.5 :: Double), Nothing, Just (-5)]) + ] + ) + (unsafePerformIO (readParquet "./tests/data/nullable_int_decimal.parquet")) + ) + byteArrayDecimal :: Test byteArrayDecimal = TestCase @@ -1394,6 +1407,7 @@ tests = , -- Group 7: decimal types int32Decimal , int64Decimal + , nullableIntDecimal , byteArrayDecimal , fixedLengthDecimal , fixedLengthDecimalLegacy diff --git a/tests/data/nullable_int_decimal.parquet b/tests/data/nullable_int_decimal.parquet new file mode 100644 index 00000000..a3daa296 Binary files /dev/null and b/tests/data/nullable_int_decimal.parquet differ