@@ -1286,15 +1286,18 @@ mod tests {
12861286 . as_ref( )
12871287 ) ;
12881288
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( ) ) ;
12901293 let schema = Arc :: new (
12911294 Schema :: builder ( )
12921295 . with_fields ( vec ! [ NestedField :: optional(
12931296 0 ,
12941297 "decimal" ,
12951298 Type :: Primitive ( PrimitiveType :: Decimal {
12961299 precision: 38 ,
1297- scale: 0 ,
1300+ scale: decimal_max . scale ( ) ,
12981301 } ) ,
12991302 )
13001303 . into( ) ] )
@@ -1313,8 +1316,8 @@ mod tests {
13131316 . await ?;
13141317 let col0 = Arc :: new (
13151318 Decimal128Array :: from ( vec ! [
1316- Some ( 99999999999999999999999999999999999999_i128 ) ,
1317- Some ( - 99999999999999999999999999999999999999_i128 ) ,
1319+ Some ( decimal_max . mantissa ( ) ) ,
1320+ Some ( decimal_min . mantissa ( ) ) ,
13181321 ] )
13191322 . with_data_type ( DataType :: Decimal128 ( 38 , 0 ) ) ,
13201323 ) as ArrayRef ;
@@ -1332,27 +1335,82 @@ mod tests {
13321335 . unwrap ( ) ;
13331336 assert_eq ! (
13341337 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( )
13431339 ) ;
13441340 assert_eq ! (
13451341 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( )
13541343 ) ;
13551344
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+
13561414 Ok ( ( ) )
13571415 }
13581416}
0 commit comments