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

Function test_time

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

Source from the content-addressed store, hash-verified

1550 }
1551
1552 fn test_time<T: ArrowTemporalType>() {
1553 let buf = r#"
1554 {"a": 1, "b": "09:26:56.123 AM", "c": 38.30}
1555 {"a": 2, "b": "23:59:59", "c": 123.456}
1556
1557 {"b": 1337, "b": "6:00 pm", "c": "09:26:56.123"}
1558 {"b": 40, "c": "13:42:29.190855"}
1559 {"b": 1234, "a": null, "c": "09:26:56.123"}
1560 {"c": "14:26:56.123"}
1561 "#;
1562
1563 let unit = match T::DATA_TYPE {
1564 DataType::Time32(unit) | DataType::Time64(unit) => unit,
1565 _ => unreachable!(),
1566 };
1567
1568 let unit_in_nanos = match unit {
1569 TimeUnit::Second => 1_000_000_000,
1570 TimeUnit::Millisecond => 1_000_000,
1571 TimeUnit::Microsecond => 1_000,
1572 TimeUnit::Nanosecond => 1,
1573 };
1574
1575 let schema = Arc::new(Schema::new(vec![
1576 Field::new("a", T::DATA_TYPE, true),
1577 Field::new("b", T::DATA_TYPE, true),
1578 Field::new("c", T::DATA_TYPE, true),
1579 ]));
1580
1581 let batches = do_read(buf, 1024, true, false, schema);
1582 assert_eq!(batches.len(), 1);
1583
1584 let col1 = batches[0].column(0).as_primitive::<T>();
1585 assert_eq!(col1.null_count(), 4);
1586 assert!(col1.is_null(2));
1587 assert!(col1.is_null(3));
1588 assert!(col1.is_null(4));
1589 assert!(col1.is_null(5));
1590 assert_eq!(col1.values(), &[1, 2, 0, 0, 0, 0].map(T::Native::usize_as));
1591
1592 let col2 = batches[0].column(1).as_primitive::<T>();
1593 assert_eq!(col2.null_count(), 1);
1594 assert!(col2.is_null(5));
1595 assert_eq!(
1596 col2.values(),
1597 &[
1598 34016123000000 / unit_in_nanos,
1599 86399000000000 / unit_in_nanos,
1600 64800000000000 / unit_in_nanos,
1601 40,
1602 1234,
1603 0
1604 ]
1605 .map(T::Native::usize_as)
1606 );
1607
1608 let col3 = batches[0].column(2).as_primitive::<T>();
1609 assert_eq!(col3.null_count(), 0);

Callers

nothing calls this directly

Calls 2

do_readFunction · 0.85
columnMethod · 0.45

Tested by

no test coverage detected