MCPcopy Create free account
hub / github.com/apache/arrow-rs / test_decimal

Function test_decimal

arrow-json/src/reader/mod.rs:1404–1452  ·  view source on GitHub ↗
(data_type: DataType)

Source from the content-addressed store, hash-verified

1402 }
1403
1404 fn test_decimal<T: DecimalType>(data_type: DataType) {
1405 let buf = r#"
1406 {"a": 1, "b": 2, "c": 38.30}
1407 {"a": 2, "b": 4, "c": 123.456}
1408
1409 {"b": 1337, "a": "2.0452"}
1410 {"b": "5", "a": "11034.2"}
1411 {"b": 40}
1412 {"b": 1234, "a": null}
1413 "#;
1414
1415 let schema = Arc::new(Schema::new(vec![
1416 Field::new("a", data_type.clone(), true),
1417 Field::new("b", data_type.clone(), true),
1418 Field::new("c", data_type, true),
1419 ]));
1420
1421 let batches = do_read(buf, 1024, true, false, schema);
1422 assert_eq!(batches.len(), 1);
1423
1424 let col1 = batches[0].column(0).as_primitive::<T>();
1425 assert_eq!(col1.null_count(), 2);
1426 assert!(col1.is_null(4));
1427 assert!(col1.is_null(5));
1428 assert_eq!(
1429 col1.values(),
1430 &[100, 200, 204, 1103420, 0, 0].map(T::Native::usize_as)
1431 );
1432
1433 let col2 = batches[0].column(1).as_primitive::<T>();
1434 assert_eq!(col2.null_count(), 0);
1435 assert_eq!(
1436 col2.values(),
1437 &[200, 400, 133700, 500, 4000, 123400].map(T::Native::usize_as)
1438 );
1439
1440 let col3 = batches[0].column(2).as_primitive::<T>();
1441 assert_eq!(col3.null_count(), 4);
1442 assert!(!col3.is_null(0));
1443 assert!(!col3.is_null(1));
1444 assert!(col3.is_null(2));
1445 assert!(col3.is_null(3));
1446 assert!(col3.is_null(4));
1447 assert!(col3.is_null(5));
1448 assert_eq!(
1449 col3.values(),
1450 &[3830, 12345, 0, 0, 0, 0].map(T::Native::usize_as)
1451 );
1452 }
1453
1454 #[test]
1455 fn test_decimals() {

Callers

nothing calls this directly

Calls 2

do_readFunction · 0.85
columnMethod · 0.45

Tested by

no test coverage detected