Skip to content

Commit

Permalink
Add Timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
chmp committed Oct 8, 2024
1 parent d64db75 commit ba182fb
Showing 1 changed file with 275 additions and 1 deletion.
276 changes: 275 additions & 1 deletion marrow/src/_with_latest_arrow/test/arrays.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use super::super::arrow;
use crate::{
array::{
Array, BooleanArray, BytesArray, DenseUnionArray, FixedSizeBinaryArray, FixedSizeListArray,
ListArray, NullArray, PrimitiveArray, TimeArray,
ListArray, NullArray, PrimitiveArray, TimeArray, TimestampArray,
},
datatypes::{FieldMeta, TimeUnit},
testing::{view_as, PanicOnError},
Expand Down Expand Up @@ -782,6 +782,280 @@ mod duration_nanosecond {
}
}

mod timestamp_second {
use super::*;

#[test]
fn not_nullable() -> PanicOnError<()> {
assert_arrays_eq(
as_array_ref::<arrow::array::TimestampSecondArray>(vec![1, 2, 3]),
Array::Timestamp(TimestampArray {
unit: TimeUnit::Second,
timezone: None,
validity: None,
values: vec![1, 2, 3],
}),
)
}

#[test]
fn nullable() -> PanicOnError<()> {
assert_arrays_eq(
as_array_ref::<arrow::array::TimestampSecondArray>(vec![None, None, Some(3), Some(4)]),
Array::Timestamp(TimestampArray {
unit: TimeUnit::Second,
timezone: None,
validity: Some(vec![0b_1100]),
values: vec![0, 0, 3, 4],
}),
)
}
}

mod timestamp_second_utc {
use super::*;

#[test]
fn not_nullable() -> PanicOnError<()> {
assert_arrays_eq(
Arc::new(arrow::array::TimestampSecondArray::from(vec![1, 2, 3]).with_timezone("UTC"))
as arrow::array::ArrayRef,
Array::Timestamp(TimestampArray {
unit: TimeUnit::Second,
timezone: Some(String::from("UTC")),
validity: None,
values: vec![1, 2, 3],
}),
)
}

#[test]
fn nullable() -> PanicOnError<()> {
assert_arrays_eq(
Arc::new(
arrow::array::TimestampSecondArray::from(vec![None, None, Some(3), Some(4)])
.with_timezone("UTC"),
) as arrow::array::ArrayRef,
Array::Timestamp(TimestampArray {
unit: TimeUnit::Second,
timezone: Some(String::from("UTC")),
validity: Some(vec![0b_1100]),
values: vec![0, 0, 3, 4],
}),
)
}
}

mod timestamp_millisecond {
use super::*;

#[test]
fn not_nullable() -> PanicOnError<()> {
assert_arrays_eq(
as_array_ref::<arrow::array::TimestampMillisecondArray>(vec![1, 2, 3]),
Array::Timestamp(TimestampArray {
unit: TimeUnit::Millisecond,
timezone: None,
validity: None,
values: vec![1, 2, 3],
}),
)
}

#[test]
fn nullable() -> PanicOnError<()> {
assert_arrays_eq(
as_array_ref::<arrow::array::TimestampMillisecondArray>(vec![
None,
None,
Some(3),
Some(4),
]),
Array::Timestamp(TimestampArray {
unit: TimeUnit::Millisecond,
timezone: None,
validity: Some(vec![0b_1100]),
values: vec![0, 0, 3, 4],
}),
)
}
}

mod timestamp_millisecond_utc {
use super::*;

#[test]
fn not_nullable() -> PanicOnError<()> {
assert_arrays_eq(
Arc::new(
arrow::array::TimestampMillisecondArray::from(vec![1, 2, 3]).with_timezone("UTC"),
) as arrow::array::ArrayRef,
Array::Timestamp(TimestampArray {
unit: TimeUnit::Millisecond,
timezone: Some(String::from("UTC")),
validity: None,
values: vec![1, 2, 3],
}),
)
}

#[test]
fn nullable() -> PanicOnError<()> {
assert_arrays_eq(
Arc::new(
arrow::array::TimestampMillisecondArray::from(vec![None, None, Some(3), Some(4)])
.with_timezone("UTC"),
) as arrow::array::ArrayRef,
Array::Timestamp(TimestampArray {
unit: TimeUnit::Millisecond,
timezone: Some(String::from("UTC")),
validity: Some(vec![0b_1100]),
values: vec![0, 0, 3, 4],
}),
)
}
}

mod timestamp_microsecond {
use super::*;

#[test]
fn not_nullable() -> PanicOnError<()> {
assert_arrays_eq(
as_array_ref::<arrow::array::TimestampMicrosecondArray>(vec![1, 2, 3]),
Array::Timestamp(TimestampArray {
unit: TimeUnit::Microsecond,
timezone: None,
validity: None,
values: vec![1, 2, 3],
}),
)
}

#[test]
fn nullable() -> PanicOnError<()> {
assert_arrays_eq(
as_array_ref::<arrow::array::TimestampMicrosecondArray>(vec![
None,
None,
Some(3),
Some(4),
]),
Array::Timestamp(TimestampArray {
unit: TimeUnit::Microsecond,
timezone: None,
validity: Some(vec![0b_1100]),
values: vec![0, 0, 3, 4],
}),
)
}
}

mod timestamp_microsecond_utc {
use super::*;

#[test]
fn not_nullable() -> PanicOnError<()> {
assert_arrays_eq(
Arc::new(
arrow::array::TimestampMicrosecondArray::from(vec![1, 2, 3]).with_timezone("UTC"),
) as arrow::array::ArrayRef,
Array::Timestamp(TimestampArray {
unit: TimeUnit::Microsecond,
timezone: Some(String::from("UTC")),
validity: None,
values: vec![1, 2, 3],
}),
)
}

#[test]
fn nullable() -> PanicOnError<()> {
assert_arrays_eq(
Arc::new(
arrow::array::TimestampMicrosecondArray::from(vec![None, None, Some(3), Some(4)])
.with_timezone("UTC"),
) as arrow::array::ArrayRef,
Array::Timestamp(TimestampArray {
unit: TimeUnit::Microsecond,
timezone: Some(String::from("UTC")),
validity: Some(vec![0b_1100]),
values: vec![0, 0, 3, 4],
}),
)
}
}

mod timestamp_nanosecond {
use super::*;

#[test]
fn not_nullable() -> PanicOnError<()> {
assert_arrays_eq(
as_array_ref::<arrow::array::TimestampNanosecondArray>(vec![1, 2, 3]),
Array::Timestamp(TimestampArray {
unit: TimeUnit::Nanosecond,
timezone: None,
validity: None,
values: vec![1, 2, 3],
}),
)
}

#[test]
fn nullable() -> PanicOnError<()> {
assert_arrays_eq(
as_array_ref::<arrow::array::TimestampNanosecondArray>(vec![
None,
None,
Some(3),
Some(4),
]),
Array::Timestamp(TimestampArray {
unit: TimeUnit::Nanosecond,
timezone: None,
validity: Some(vec![0b_1100]),
values: vec![0, 0, 3, 4],
}),
)
}
}

mod timestamp_nanosecond_utc {
use super::*;

#[test]
fn not_nullable() -> PanicOnError<()> {
assert_arrays_eq(
Arc::new(
arrow::array::TimestampNanosecondArray::from(vec![1, 2, 3]).with_timezone("UTC"),
) as arrow::array::ArrayRef,
Array::Timestamp(TimestampArray {
unit: TimeUnit::Nanosecond,
timezone: Some(String::from("UTC")),
validity: None,
values: vec![1, 2, 3],
}),
)
}

#[test]
fn nullable() -> PanicOnError<()> {
assert_arrays_eq(
Arc::new(
arrow::array::TimestampNanosecondArray::from(vec![None, None, Some(3), Some(4)])
.with_timezone("UTC"),
) as arrow::array::ArrayRef,
Array::Timestamp(TimestampArray {
unit: TimeUnit::Nanosecond,
timezone: Some(String::from("UTC")),
validity: Some(vec![0b_1100]),
values: vec![0, 0, 3, 4],
}),
)
}
}

mod utf8 {
use super::*;

Expand Down

0 comments on commit ba182fb

Please sign in to comment.