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

Function test_timestamp

arrow-json/src/reader/mod.rs:1462–1542  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1460 }
1461
1462 fn test_timestamp<T: ArrowTimestampType>() {
1463 let buf = r#"
1464 {"a": 1, "b": "2020-09-08T13:42:29.190855+00:00", "c": 38.30, "d": "1997-01-31T09:26:56.123"}
1465 {"a": 2, "b": "2020-09-08T13:42:29.190855Z", "c": 123.456, "d": 123.456}
1466
1467 {"b": 1337, "b": "2020-09-08T13:42:29Z", "c": "1997-01-31T09:26:56.123", "d": "1997-01-31T09:26:56.123Z"}
1468 {"b": 40, "c": "2020-09-08T13:42:29.190855+00:00", "d": "1997-01-31 09:26:56.123-05:00"}
1469 {"b": 1234, "a": null, "c": "1997-01-31 09:26:56.123Z", "d": "1997-01-31 092656"}
1470 {"c": "1997-01-31T14:26:56.123-05:00", "d": "1997-01-31"}
1471 "#;
1472
1473 let with_timezone = DataType::Timestamp(T::UNIT, Some("+08:00".into()));
1474 let schema = Arc::new(Schema::new(vec![
1475 Field::new("a", T::DATA_TYPE, true),
1476 Field::new("b", T::DATA_TYPE, true),
1477 Field::new("c", T::DATA_TYPE, true),
1478 Field::new("d", with_timezone, true),
1479 ]));
1480
1481 let batches = do_read(buf, 1024, true, false, schema);
1482 assert_eq!(batches.len(), 1);
1483
1484 let unit_in_nanos: i64 = match T::UNIT {
1485 TimeUnit::Second => 1_000_000_000,
1486 TimeUnit::Millisecond => 1_000_000,
1487 TimeUnit::Microsecond => 1_000,
1488 TimeUnit::Nanosecond => 1,
1489 };
1490
1491 let col1 = batches[0].column(0).as_primitive::<T>();
1492 assert_eq!(col1.null_count(), 4);
1493 assert!(col1.is_null(2));
1494 assert!(col1.is_null(3));
1495 assert!(col1.is_null(4));
1496 assert!(col1.is_null(5));
1497 assert_eq!(col1.values(), &[1, 2, 0, 0, 0, 0].map(T::Native::usize_as));
1498
1499 let col2 = batches[0].column(1).as_primitive::<T>();
1500 assert_eq!(col2.null_count(), 1);
1501 assert!(col2.is_null(5));
1502 assert_eq!(
1503 col2.values(),
1504 &[
1505 1599572549190855000 / unit_in_nanos,
1506 1599572549190855000 / unit_in_nanos,
1507 1599572549000000000 / unit_in_nanos,
1508 40,
1509 1234,
1510 0
1511 ]
1512 );
1513
1514 let col3 = batches[0].column(2).as_primitive::<T>();
1515 assert_eq!(col3.null_count(), 0);
1516 assert_eq!(
1517 col3.values(),
1518 &[
1519 38,

Callers

nothing calls this directly

Calls 3

TimestampClass · 0.85
do_readFunction · 0.85
columnMethod · 0.45

Tested by

no test coverage detected