Skip to content

Commit 66a6d48

Browse files
committed
fix
Signed-off-by: Joe Isaacs <joe.isaacs@live.co.uk>
1 parent a3bf967 commit 66a6d48

5 files changed

Lines changed: 316 additions & 0 deletions

File tree

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
// SPDX-FileCopyrightText: Copyright the Vortex contributors
3+
4+
use std::sync::Arc;
5+
6+
use vortex_array::ArrayRef;
7+
use vortex_array::IntoArray;
8+
use vortex_array::arrays::Extension;
9+
use vortex_array::arrays::PrimitiveArray;
10+
use vortex_array::arrays::StructArray;
11+
use vortex_array::arrays::TemporalArray;
12+
use vortex_array::dtype::FieldNames;
13+
use vortex_array::extension::datetime::TimeUnit;
14+
use vortex_array::validity::Validity;
15+
use vortex_array::vtable::ArrayId;
16+
use vortex_buffer::buffer;
17+
use vortex_error::VortexResult;
18+
19+
use crate::fixtures::FlatLayoutFixture;
20+
21+
pub struct DateTimeFixture;
22+
23+
impl FlatLayoutFixture for DateTimeFixture {
24+
fn name(&self) -> &str {
25+
"datetime.vortex"
26+
}
27+
28+
fn description(&self) -> &str {
29+
"Temporal arrays covering timestamps, dates, and times with various units"
30+
}
31+
32+
fn expected_encodings(&self) -> Vec<ArrayId> {
33+
vec![Extension::ID]
34+
}
35+
36+
fn build(&self) -> VortexResult<ArrayRef> {
37+
// Timestamps in seconds (i64): 2024-01-01T00:00:00Z, 2024-06-15T12:30:00Z, 2024-12-31T23:59:59Z
38+
let ts_seconds = TemporalArray::new_timestamp(
39+
PrimitiveArray::new(
40+
buffer![1704067200i64, 1718451000, 1735689599],
41+
Validity::NonNullable,
42+
)
43+
.into_array(),
44+
TimeUnit::Seconds,
45+
None,
46+
);
47+
48+
// Timestamps in milliseconds with timezone (i64)
49+
let ts_millis_tz = TemporalArray::new_timestamp(
50+
PrimitiveArray::new(
51+
buffer![1704067200000i64, 1718451000000, 1735689599000],
52+
Validity::NonNullable,
53+
)
54+
.into_array(),
55+
TimeUnit::Milliseconds,
56+
Some(Arc::from("UTC")),
57+
);
58+
59+
// Nullable timestamps in microseconds (i64)
60+
let ts_nullable = TemporalArray::new_timestamp(
61+
PrimitiveArray::from_option_iter([
62+
Some(1704067200000000i64),
63+
None,
64+
Some(1735689599000000i64),
65+
])
66+
.into_array(),
67+
TimeUnit::Microseconds,
68+
None,
69+
);
70+
71+
// Date in days since epoch (i32): 2024-01-01, 2024-06-15, 2024-12-31
72+
let date_days = TemporalArray::new_date(
73+
PrimitiveArray::new(buffer![19723i32, 19889, 19723 + 365], Validity::NonNullable)
74+
.into_array(),
75+
TimeUnit::Days,
76+
);
77+
78+
// Time in seconds since midnight (i32): 00:00:00, 12:30:00, 23:59:59
79+
let time_secs = TemporalArray::new_time(
80+
PrimitiveArray::new(buffer![0i32, 45000, 86399], Validity::NonNullable).into_array(),
81+
TimeUnit::Seconds,
82+
);
83+
84+
let arr = StructArray::try_new(
85+
FieldNames::from([
86+
"ts_seconds",
87+
"ts_millis_tz",
88+
"ts_nullable_micros",
89+
"date_days",
90+
"time_seconds",
91+
]),
92+
vec![
93+
ts_seconds.into_array(),
94+
ts_millis_tz.into_array(),
95+
ts_nullable.into_array(),
96+
date_days.into_array(),
97+
time_secs.into_array(),
98+
],
99+
3,
100+
Validity::NonNullable,
101+
)?;
102+
Ok(arr.into_array())
103+
}
104+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
// SPDX-FileCopyrightText: Copyright the Vortex contributors
3+
4+
use vortex_array::ArrayRef;
5+
use vortex_array::IntoArray;
6+
use vortex_array::arrays::Decimal;
7+
use vortex_array::arrays::DecimalArray;
8+
use vortex_array::arrays::StructArray;
9+
use vortex_array::dtype::DecimalDType;
10+
use vortex_array::dtype::FieldNames;
11+
use vortex_array::validity::Validity;
12+
use vortex_array::vtable::ArrayId;
13+
use vortex_buffer::buffer;
14+
use vortex_error::VortexResult;
15+
16+
use crate::fixtures::FlatLayoutFixture;
17+
18+
pub struct DecimalFixture;
19+
20+
impl FlatLayoutFixture for DecimalFixture {
21+
fn name(&self) -> &str {
22+
"decimal.vortex"
23+
}
24+
25+
fn description(&self) -> &str {
26+
"Decimal arrays with varying precisions and scales, including nullable variants"
27+
}
28+
29+
fn expected_encodings(&self) -> Vec<ArrayId> {
30+
vec![Decimal::ID]
31+
}
32+
33+
fn build(&self) -> VortexResult<ArrayRef> {
34+
// Decimal(5,2) stored as i32: represents 123.45, -678.90, 0.01
35+
let dec_5_2 = DecimalArray::new(
36+
buffer![12345i32, -67890, 1],
37+
DecimalDType::new(5, 2),
38+
Validity::NonNullable,
39+
);
40+
41+
// Decimal(10,4) stored as i64: represents 123456.7890, -0.0001, 999999.9999
42+
let dec_10_4 = DecimalArray::new(
43+
buffer![1234567890i64, -1, 9999999999],
44+
DecimalDType::new(10, 4),
45+
Validity::NonNullable,
46+
);
47+
48+
// Decimal(18,0) stored as i64: large integers
49+
let dec_18_0 = DecimalArray::new(
50+
buffer![0i64, i64::MAX, i64::MIN],
51+
DecimalDType::new(18, 0),
52+
Validity::NonNullable,
53+
);
54+
55+
// Nullable Decimal(7,3) stored as i32
56+
let dec_nullable = DecimalArray::from_option_iter(
57+
[Some(1234567i32), None, Some(-9999999)],
58+
DecimalDType::new(7, 3),
59+
);
60+
61+
let arr = StructArray::try_new(
62+
FieldNames::from(["dec_5_2", "dec_10_4", "dec_18_0", "dec_nullable_7_3"]),
63+
vec![
64+
dec_5_2.into_array(),
65+
dec_10_4.into_array(),
66+
dec_18_0.into_array(),
67+
dec_nullable.into_array(),
68+
],
69+
3,
70+
Validity::NonNullable,
71+
)?;
72+
Ok(arr.into_array())
73+
}
74+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
// SPDX-FileCopyrightText: Copyright the Vortex contributors
3+
4+
use vortex_array::ArrayRef;
5+
use vortex_array::IntoArray;
6+
use vortex_array::arrays::ListView;
7+
use vortex_array::arrays::ListViewArray;
8+
use vortex_array::arrays::PrimitiveArray;
9+
use vortex_array::arrays::StructArray;
10+
use vortex_array::arrays::VarBinArray;
11+
use vortex_array::dtype::FieldNames;
12+
use vortex_array::validity::Validity;
13+
use vortex_array::vtable::ArrayId;
14+
use vortex_buffer::buffer;
15+
use vortex_error::VortexResult;
16+
17+
use crate::fixtures::FlatLayoutFixture;
18+
19+
pub struct ListViewFixture;
20+
21+
impl FlatLayoutFixture for ListViewFixture {
22+
fn name(&self) -> &str {
23+
"listview.vortex"
24+
}
25+
26+
fn description(&self) -> &str {
27+
"ListView arrays with integer and string elements"
28+
}
29+
30+
fn expected_encodings(&self) -> Vec<ArrayId> {
31+
vec![ListView::ID]
32+
}
33+
34+
fn build(&self) -> VortexResult<ArrayRef> {
35+
// ListView of i32: [[1,2,3], [4,5], [6], [7,8,9,10]]
36+
let int_elements = PrimitiveArray::new(
37+
buffer![1i32, 2, 3, 4, 5, 6, 7, 8, 9, 10],
38+
Validity::NonNullable,
39+
);
40+
let int_offsets = PrimitiveArray::new(buffer![0u32, 3, 5, 6], Validity::NonNullable);
41+
let int_sizes = PrimitiveArray::new(buffer![3u32, 2, 1, 4], Validity::NonNullable);
42+
let int_listview = ListViewArray::try_new(
43+
int_elements.into_array(),
44+
int_offsets.into_array(),
45+
int_sizes.into_array(),
46+
Validity::NonNullable,
47+
)?;
48+
49+
// ListView of strings: [["a","b"], ["hello"], [], ["x","y","z"]]
50+
let str_elements = VarBinArray::from(vec!["a", "b", "hello", "x", "y", "z"]);
51+
let str_offsets = PrimitiveArray::new(buffer![0u32, 2, 3, 3], Validity::NonNullable);
52+
let str_sizes = PrimitiveArray::new(buffer![2u32, 1, 0, 3], Validity::NonNullable);
53+
let str_listview = ListViewArray::try_new(
54+
str_elements.into_array(),
55+
str_offsets.into_array(),
56+
str_sizes.into_array(),
57+
Validity::NonNullable,
58+
)?;
59+
60+
let arr = StructArray::try_new(
61+
FieldNames::from(["int_listview", "str_listview"]),
62+
vec![int_listview.into_array(), str_listview.into_array()],
63+
4,
64+
Validity::NonNullable,
65+
)?;
66+
Ok(arr.into_array())
67+
}
68+
}

vortex-test/compat-gen/src/fixtures/arrays/synthetic/arrays/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@
77
88
mod bool;
99
mod chunked;
10+
mod datetime;
11+
mod decimal;
1012
mod fixed_size_list;
1113
mod list;
14+
mod listview;
1215
mod null;
1316
mod primitive;
1417
mod struct_nested;
@@ -29,5 +32,8 @@ pub fn fixtures() -> Vec<Box<dyn FlatLayoutFixture>> {
2932
Box::new(list::ListFixture),
3033
Box::new(fixed_size_list::FixedSizeListFixture),
3134
Box::new(null::NullFixture),
35+
Box::new(datetime::DateTimeFixture),
36+
Box::new(decimal::DecimalFixture),
37+
Box::new(listview::ListViewFixture),
3238
]
3339
}

vortex-test/compat-gen/src/lib.rs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,67 @@ pub mod adapter;
55
pub mod fixtures;
66
pub mod manifest;
77
pub mod validate;
8+
9+
#[cfg(test)]
10+
mod tests {
11+
use vortex_buffer::ByteBuffer;
12+
13+
use crate::adapter;
14+
use crate::fixtures::all_fixtures;
15+
16+
#[test]
17+
fn roundtrip_all_fixtures() {
18+
let tmp = tempfile::tempdir().unwrap();
19+
let fixtures = all_fixtures();
20+
21+
for fixture in &fixtures {
22+
eprintln!("--- writing {} ---", fixture.name());
23+
let entries = fixture.write(tmp.path()).unwrap();
24+
for entry in &entries {
25+
let path = tmp.path().join(&entry.name);
26+
let bytes = std::fs::read(&path).unwrap();
27+
eprintln!(" reading back {}...", entry.name);
28+
let _array = adapter::read_file(ByteBuffer::from(bytes)).unwrap();
29+
eprintln!(" OK: {}", entry.name);
30+
}
31+
}
32+
}
33+
34+
#[test]
35+
fn roundtrip_dataset_regular() {
36+
let tmp = tempfile::tempdir().unwrap();
37+
for dataset in all_fixtures()
38+
.into_iter()
39+
.filter(|f| f.name().contains(".regular."))
40+
{
41+
eprintln!("--- {} ---", dataset.name());
42+
let entries = dataset.write(tmp.path()).unwrap();
43+
for entry in &entries {
44+
let path = tmp.path().join(&entry.name);
45+
let bytes = std::fs::read(&path).unwrap();
46+
eprintln!(" reading back...");
47+
let _array = adapter::read_file(ByteBuffer::from(bytes)).unwrap();
48+
eprintln!(" OK");
49+
}
50+
}
51+
}
52+
53+
#[test]
54+
fn roundtrip_dataset_compact() {
55+
let tmp = tempfile::tempdir().unwrap();
56+
for dataset in all_fixtures()
57+
.into_iter()
58+
.filter(|f| f.name().contains(".compact."))
59+
{
60+
eprintln!("--- {} ---", dataset.name());
61+
let entries = dataset.write(tmp.path()).unwrap();
62+
for entry in &entries {
63+
let path = tmp.path().join(&entry.name);
64+
let bytes = std::fs::read(&path).unwrap();
65+
eprintln!(" reading back...");
66+
let _array = adapter::read_file(ByteBuffer::from(bytes)).unwrap();
67+
eprintln!(" OK");
68+
}
69+
}
70+
}
71+
}

0 commit comments

Comments
 (0)