Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions dataframe-parquet/src/DataFrame/IO/Parquet.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 14 additions & 0 deletions tests/Parquet.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1394,6 +1407,7 @@ tests =
, -- Group 7: decimal types
int32Decimal
, int64Decimal
, nullableIntDecimal
, byteArrayDecimal
, fixedLengthDecimal
, fixedLengthDecimalLegacy
Expand Down
Binary file added tests/data/nullable_int_decimal.parquet
Binary file not shown.
Loading