@@ -1286,15 +1286,18 @@ mod tests {
1286
1286
. as_ref( )
1287
1287
) ;
1288
1288
1289
- // test max and min for scale 38
1289
+ // test max and min of rust_decimal
1290
+ let decimal_max = Decimal :: MAX ;
1291
+ let decimal_min = Decimal :: MIN ;
1292
+ assert_eq ! ( decimal_max. scale( ) , decimal_min. scale( ) ) ;
1290
1293
let schema = Arc :: new (
1291
1294
Schema :: builder ( )
1292
1295
. with_fields ( vec ! [ NestedField :: optional(
1293
1296
0 ,
1294
1297
"decimal" ,
1295
1298
Type :: Primitive ( PrimitiveType :: Decimal {
1296
1299
precision: 38 ,
1297
- scale: 0 ,
1300
+ scale: decimal_max . scale ( ) ,
1298
1301
} ) ,
1299
1302
)
1300
1303
. into( ) ] )
@@ -1313,8 +1316,8 @@ mod tests {
1313
1316
. await ?;
1314
1317
let col0 = Arc :: new (
1315
1318
Decimal128Array :: from ( vec ! [
1316
- Some ( 99999999999999999999999999999999999999_i128 ) ,
1317
- Some ( - 99999999999999999999999999999999999999_i128 ) ,
1319
+ Some ( decimal_max . mantissa ( ) ) ,
1320
+ Some ( decimal_min . mantissa ( ) ) ,
1318
1321
] )
1319
1322
. with_data_type ( DataType :: Decimal128 ( 38 , 0 ) ) ,
1320
1323
) as ArrayRef ;
@@ -1332,27 +1335,82 @@ mod tests {
1332
1335
. unwrap ( ) ;
1333
1336
assert_eq ! (
1334
1337
data_file. upper_bounds( ) . get( & 0 ) ,
1335
- Some ( Datum :: new(
1336
- PrimitiveType :: Decimal {
1337
- precision: 38 ,
1338
- scale: 0
1339
- } ,
1340
- PrimitiveLiteral :: Int128 ( 99999999999999999999999999999999999999_i128 )
1341
- ) )
1342
- . as_ref( )
1338
+ Some ( Datum :: decimal( decimal_max) . unwrap( ) ) . as_ref( )
1343
1339
) ;
1344
1340
assert_eq ! (
1345
1341
data_file. lower_bounds( ) . get( & 0 ) ,
1346
- Some ( Datum :: new(
1347
- PrimitiveType :: Decimal {
1348
- precision: 38 ,
1349
- scale: 0
1350
- } ,
1351
- PrimitiveLiteral :: Int128 ( -99999999999999999999999999999999999999_i128 )
1352
- ) )
1353
- . as_ref( )
1342
+ Some ( Datum :: decimal( decimal_min) . unwrap( ) ) . as_ref( )
1354
1343
) ;
1355
1344
1345
+ // test max and min for scale 38
1346
+ // # TODO
1347
+ // Readd this case after resolve https://github.com/apache/iceberg-rust/issues/669
1348
+ // let schema = Arc::new(
1349
+ // Schema::builder()
1350
+ // .with_fields(vec![NestedField::optional(
1351
+ // 0,
1352
+ // "decimal",
1353
+ // Type::Primitive(PrimitiveType::Decimal {
1354
+ // precision: 38,
1355
+ // scale: 0,
1356
+ // }),
1357
+ // )
1358
+ // .into()])
1359
+ // .build()
1360
+ // .unwrap(),
1361
+ // );
1362
+ // let arrow_schema: ArrowSchemaRef = Arc::new(schema_to_arrow_schema(&schema).unwrap());
1363
+ // let mut pw = ParquetWriterBuilder::new(
1364
+ // WriterProperties::builder().build(),
1365
+ // schema,
1366
+ // file_io.clone(),
1367
+ // loccation_gen,
1368
+ // file_name_gen,
1369
+ // )
1370
+ // .build()
1371
+ // .await?;
1372
+ // let col0 = Arc::new(
1373
+ // Decimal128Array::from(vec![
1374
+ // Some(99999999999999999999999999999999999999_i128),
1375
+ // Some(-99999999999999999999999999999999999999_i128),
1376
+ // ])
1377
+ // .with_data_type(DataType::Decimal128(38, 0)),
1378
+ // ) as ArrayRef;
1379
+ // let to_write = RecordBatch::try_new(arrow_schema.clone(), vec![col0]).unwrap();
1380
+ // pw.write(&to_write).await?;
1381
+ // let res = pw.close().await?;
1382
+ // assert_eq!(res.len(), 1);
1383
+ // let data_file = res
1384
+ // .into_iter()
1385
+ // .next()
1386
+ // .unwrap()
1387
+ // .content(crate::spec::DataContentType::Data)
1388
+ // .partition(Struct::empty())
1389
+ // .build()
1390
+ // .unwrap();
1391
+ // assert_eq!(
1392
+ // data_file.upper_bounds().get(&0),
1393
+ // Some(Datum::new(
1394
+ // PrimitiveType::Decimal {
1395
+ // precision: 38,
1396
+ // scale: 0
1397
+ // },
1398
+ // PrimitiveLiteral::Int128(99999999999999999999999999999999999999_i128)
1399
+ // ))
1400
+ // .as_ref()
1401
+ // );
1402
+ // assert_eq!(
1403
+ // data_file.lower_bounds().get(&0),
1404
+ // Some(Datum::new(
1405
+ // PrimitiveType::Decimal {
1406
+ // precision: 38,
1407
+ // scale: 0
1408
+ // },
1409
+ // PrimitiveLiteral::Int128(-99999999999999999999999999999999999999_i128)
1410
+ // ))
1411
+ // .as_ref()
1412
+ // );
1413
+
1356
1414
Ok ( ( ) )
1357
1415
}
1358
1416
}
0 commit comments