Skip to content

Commit 5415281

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

23 files changed

Lines changed: 1162 additions & 27 deletions

File tree

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,24 @@ pub fn write_file(path: &Path, chunk: ArrayRef) -> VortexResult<()> {
5252
})
5353
}
5454

55+
/// Write a sequence of array chunks to an in-memory `.vortex` byte buffer with no compression.
56+
pub fn write_file_to_bytes(chunk: ArrayRef) -> VortexResult<ByteBuffer> {
57+
let stream = ArrayStreamAdapter::new(chunk.dtype().clone(), stream::iter([Ok(chunk)]));
58+
59+
let strategy: Arc<dyn LayoutStrategy> = Arc::new(FlatLayoutStrategy::default());
60+
61+
runtime()?.block_on(async {
62+
let session = VortexSession::default().with_tokio();
63+
let mut bytes = Vec::new();
64+
let _summary = session
65+
.write_options()
66+
.with_strategy(strategy)
67+
.write(&mut bytes, stream)
68+
.await?;
69+
Ok(ByteBuffer::from(bytes))
70+
})
71+
}
72+
5573
/// Write a `.vortex` file using a caller-provided layout strategy (compressor pipeline).
5674
pub fn write_compressed(
5775
path: &Path,
@@ -74,6 +92,25 @@ pub fn write_compressed(
7492
})
7593
}
7694

95+
/// Write a `.vortex` file into an in-memory byte buffer using a caller-provided layout strategy.
96+
pub fn write_compressed_to_bytes(
97+
chunk: ArrayRef,
98+
strategy: Arc<dyn LayoutStrategy>,
99+
) -> VortexResult<ByteBuffer> {
100+
let stream = ArrayStreamAdapter::new(chunk.dtype().clone(), stream::iter([Ok(chunk)]));
101+
102+
runtime()?.block_on(async {
103+
let session = VortexSession::default().with_tokio();
104+
let mut bytes = Vec::new();
105+
let _summary = session
106+
.write_options()
107+
.with_strategy(strategy)
108+
.write(&mut bytes, stream)
109+
.await?;
110+
Ok(ByteBuffer::from(bytes))
111+
})
112+
}
113+
77114
/// Read a `.vortex` file from bytes, returning the arrays.
78115
pub fn read_file(bytes: ByteBuffer) -> VortexResult<ArrayRef> {
79116
runtime()?.block_on(async {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ impl FlatLayoutFixture for DecimalFixture {
4747

4848
// Decimal(18,0) stored as i64: large integers
4949
let dec_18_0 = DecimalArray::new(
50-
buffer![0i64, i64::MAX, i64::MIN],
50+
buffer![0i64, 999_999_999_999_999_999, -999_999_999_999_999_999],
5151
DecimalDType::new(18, 0),
5252
Validity::NonNullable,
5353
);

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

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,34 @@ use crate::fixtures::FlatLayoutFixture;
1818

1919
pub struct AlpFixture;
2020

21+
fn special_f64(i: usize) -> f64 {
22+
match i % 9 {
23+
0 => 0.0,
24+
1 => -0.0,
25+
2 => f64::from_bits(0x7ff8_0000_0000_0001),
26+
3 => f64::from_bits(0x7ff8_0000_0000_1234),
27+
4 => f64::from_bits(0xfff8_0000_0000_5678),
28+
5 => f64::INFINITY,
29+
6 => f64::NEG_INFINITY,
30+
7 => f64::MIN_POSITIVE,
31+
_ => -f64::from_bits(1),
32+
}
33+
}
34+
35+
fn special_f32(i: usize) -> f32 {
36+
match i % 9 {
37+
0 => 0.0,
38+
1 => -0.0,
39+
2 => f32::from_bits(0x7fc0_0001),
40+
3 => f32::from_bits(0x7fc0_1234),
41+
4 => f32::from_bits(0xffc0_5678),
42+
5 => f32::INFINITY,
43+
6 => f32::NEG_INFINITY,
44+
7 => f32::MIN_POSITIVE,
45+
_ => -f32::from_bits(1),
46+
}
47+
}
48+
2149
impl FlatLayoutFixture for AlpFixture {
2250
fn name(&self) -> &str {
2351
"alp.vortex"
@@ -34,6 +62,9 @@ impl FlatLayoutFixture for AlpFixture {
3462
fn build(&self) -> VortexResult<ArrayRef> {
3563
let f64_prices: Vec<f64> = (0..N).map(|i| 100.0 + (i as f64) * 0.25).collect();
3664
let f32_near_int: Vec<f32> = (0..N).map(|i| i as f32).collect();
65+
let f64_negative_near_int: Vec<f64> = (0..N)
66+
.map(|i| -(i as f64) - ((i % 7) as f64) * 0.000_1)
67+
.collect();
3768
let f64_currency: Vec<f64> = (0..N).map(|i| ((i % 10000) as f64) / 100.0).collect();
3869
let f64_nullable = PrimitiveArray::from_option_iter(
3970
(0..N as i64).map(|i| (i % 10 != 0).then_some(50.0 + (i as f64) * 0.125)),
@@ -47,14 +78,56 @@ impl FlatLayoutFixture for AlpFixture {
4778
}
4879
})
4980
.collect();
81+
let f64_patch_heavy: Vec<f64> = (0..N)
82+
.map(|i| {
83+
if i % 7 == 0 || i % 11 == 0 {
84+
10_000.0 + (i as f64).powi(2)
85+
} else {
86+
250.0 + ((i % 37) as f64) * 0.01
87+
}
88+
})
89+
.collect();
90+
let f64_special_values: Vec<f64> = (0..N).map(special_f64).collect();
91+
let f32_special_values: Vec<f32> = (0..N).map(special_f32).collect();
92+
let f64_extremes: Vec<f64> = (0..N)
93+
.map(|i| match i % 10 {
94+
0 => f64::MAX,
95+
1 => f64::MIN,
96+
2 => f64::EPSILON,
97+
3 => -f64::EPSILON,
98+
4 => f64::MIN_POSITIVE,
99+
5 => -f64::MIN_POSITIVE,
100+
6 => std::f64::consts::PI,
101+
7 => -std::f64::consts::E,
102+
8 => f64::from_bits(1),
103+
_ => -f64::from_bits(2),
104+
})
105+
.collect();
106+
let f64_boundary_specials: Vec<f64> = (0..N)
107+
.map(|i| match i {
108+
0 => f64::from_bits(0x7ff8_0000_0000_0001),
109+
1 => -0.0,
110+
511 => f64::INFINITY,
111+
512 => f64::NEG_INFINITY,
112+
513 => f64::from_bits(0xfff8_0000_0000_5678),
113+
1023 => f64::from_bits(1),
114+
_ => 12.5 + (i as f64) * 0.000_001,
115+
})
116+
.collect();
50117

51118
let arr = StructArray::try_new(
52119
FieldNames::from([
53120
"f64_prices",
54121
"f32_near_int",
122+
"f64_negative_near_int",
55123
"f64_currency",
56124
"f64_nullable",
57125
"f64_patched",
126+
"f64_patch_heavy",
127+
"f64_special_values",
128+
"f32_special_values",
129+
"f64_extremes",
130+
"f64_boundary_specials",
58131
]),
59132
vec![
60133
alp_encode(
@@ -67,6 +140,14 @@ impl FlatLayoutFixture for AlpFixture {
67140
None,
68141
)?
69142
.into_array(),
143+
alp_encode(
144+
&PrimitiveArray::new(
145+
Buffer::from(f64_negative_near_int),
146+
Validity::NonNullable,
147+
),
148+
None,
149+
)?
150+
.into_array(),
70151
alp_encode(
71152
&PrimitiveArray::new(Buffer::from(f64_currency), Validity::NonNullable),
72153
None,
@@ -78,6 +159,34 @@ impl FlatLayoutFixture for AlpFixture {
78159
None,
79160
)?
80161
.into_array(),
162+
alp_encode(
163+
&PrimitiveArray::new(Buffer::from(f64_patch_heavy), Validity::NonNullable),
164+
None,
165+
)?
166+
.into_array(),
167+
alp_encode(
168+
&PrimitiveArray::new(Buffer::from(f64_special_values), Validity::NonNullable),
169+
None,
170+
)?
171+
.into_array(),
172+
alp_encode(
173+
&PrimitiveArray::new(Buffer::from(f32_special_values), Validity::NonNullable),
174+
None,
175+
)?
176+
.into_array(),
177+
alp_encode(
178+
&PrimitiveArray::new(Buffer::from(f64_extremes), Validity::NonNullable),
179+
None,
180+
)?
181+
.into_array(),
182+
alp_encode(
183+
&PrimitiveArray::new(
184+
Buffer::from(f64_boundary_specials),
185+
Validity::NonNullable,
186+
),
187+
None,
188+
)?
189+
.into_array(),
81190
],
82191
N,
83192
Validity::NonNullable,

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

Lines changed: 105 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,20 @@ use crate::fixtures::FlatLayoutFixture;
1818

1919
pub struct AlprdFixture;
2020

21+
fn special_f64(i: usize) -> f64 {
22+
match i % 9 {
23+
0 => 0.0,
24+
1 => -0.0,
25+
2 => f64::from_bits(0x7ff8_0000_0000_0001),
26+
3 => f64::from_bits(0x7ff8_0000_0000_1234),
27+
4 => f64::from_bits(0xfff8_0000_0000_5678),
28+
5 => f64::INFINITY,
29+
6 => f64::NEG_INFINITY,
30+
7 => f64::MIN_POSITIVE,
31+
_ => -f64::from_bits(1),
32+
}
33+
}
34+
2135
impl FlatLayoutFixture for AlprdFixture {
2236
fn name(&self) -> &str {
2337
"alprd.vortex"
@@ -42,6 +56,23 @@ impl FlatLayoutFixture for AlprdFixture {
4256
let drift: Vec<f64> = (0..N)
4357
.map(|i| 1000.0 + (i as f64) * 0.001 + ((i * 3) % 7) as f64 * 0.0001)
4458
.collect();
59+
let constant_series = vec![12.125; N];
60+
let decreasing: Vec<f64> = (0..N)
61+
.map(|i| 512.0 - (i as f64) * 0.000_5 - ((i * 5 % 13) as f64) * 0.000_01)
62+
.collect();
63+
let oscillating: Vec<f64> = (0..N)
64+
.map(|i| {
65+
let phase = ((i % 9) as i32 - 4) as f64;
66+
-0.25 + phase * 0.000_1 + (i as f64) * 0.000_001
67+
})
68+
.collect();
69+
let periodic_resets: Vec<f64> = (0..N)
70+
.map(|i| {
71+
let block = i / 64;
72+
let offset = i % 64;
73+
block as f64 * 10.0 + (offset as f64) * 0.000_2
74+
})
75+
.collect();
4576

4677
let sensor_nullable_vals: Vec<f64> = (0..N)
4778
.map(|i| {
@@ -57,20 +88,93 @@ impl FlatLayoutFixture for AlprdFixture {
5788
Some(37.0 + noise)
5889
}
5990
}));
91+
let special_values: Vec<f64> = (0..N)
92+
.map(|i| {
93+
if i % 16 == 0 {
94+
special_f64(i)
95+
} else {
96+
42.125 + ((i * 5 % 17) as f64) * 0.000_01
97+
}
98+
})
99+
.collect();
100+
let boundary_specials: Vec<f64> = (0..N)
101+
.map(|i| match i {
102+
0 => f64::from_bits(0x7ff8_0000_0000_0001),
103+
1 => -0.0,
104+
511 => f64::INFINITY,
105+
512 => f64::NEG_INFINITY,
106+
513 => f64::from_bits(0xfff8_0000_0000_5678),
107+
1023 => f64::from_bits(1),
108+
_ => 9.875 + ((i * 3 % 11) as f64) * 0.000_1,
109+
})
110+
.collect();
111+
let nullable_special_vals: Vec<f64> = (0..N)
112+
.map(|i| {
113+
if i % 32 == 7 {
114+
special_f64(i)
115+
} else {
116+
11.5 + ((i * 13 % 19) as f64) * 0.000_01
117+
}
118+
})
119+
.collect();
120+
let nullable_specials = PrimitiveArray::from_option_iter((0..N).map(|i| {
121+
if i % 29 == 0 || i == 0 || i == N - 1 {
122+
None
123+
} else {
124+
Some(nullable_special_vals[i])
125+
}
126+
}));
60127

61128
let sensor_prim = PrimitiveArray::new(Buffer::from(sensor), Validity::NonNullable);
62129
let drift_prim = PrimitiveArray::new(Buffer::from(drift), Validity::NonNullable);
130+
let constant_prim =
131+
PrimitiveArray::new(Buffer::from(constant_series), Validity::NonNullable);
132+
let decreasing_prim = PrimitiveArray::new(Buffer::from(decreasing), Validity::NonNullable);
133+
let oscillating_prim =
134+
PrimitiveArray::new(Buffer::from(oscillating), Validity::NonNullable);
135+
let periodic_resets_prim =
136+
PrimitiveArray::new(Buffer::from(periodic_resets), Validity::NonNullable);
137+
let special_prim = PrimitiveArray::new(Buffer::from(special_values), Validity::NonNullable);
138+
let boundary_prim =
139+
PrimitiveArray::new(Buffer::from(boundary_specials), Validity::NonNullable);
63140

64141
let sensor_enc = RDEncoder::new::<f64>(sensor_prim.as_slice::<f64>());
65142
let drift_enc = RDEncoder::new::<f64>(drift_prim.as_slice::<f64>());
143+
let constant_enc = RDEncoder::new::<f64>(constant_prim.as_slice::<f64>());
144+
let decreasing_enc = RDEncoder::new::<f64>(decreasing_prim.as_slice::<f64>());
145+
let oscillating_enc = RDEncoder::new::<f64>(oscillating_prim.as_slice::<f64>());
146+
let periodic_resets_enc = RDEncoder::new::<f64>(periodic_resets_prim.as_slice::<f64>());
66147
let nullable_enc = RDEncoder::new::<f64>(&sensor_nullable_vals);
148+
let special_enc = RDEncoder::new::<f64>(special_prim.as_slice::<f64>());
149+
let boundary_enc = RDEncoder::new::<f64>(boundary_prim.as_slice::<f64>());
150+
let nullable_special_enc = RDEncoder::new::<f64>(&nullable_special_vals);
67151

68152
let arr = StructArray::try_new(
69-
FieldNames::from(["sensor", "drift", "sensor_nullable"]),
153+
FieldNames::from([
154+
"sensor",
155+
"drift",
156+
"constant_series",
157+
"decreasing",
158+
"oscillating",
159+
"periodic_resets",
160+
"sensor_nullable",
161+
"special_values",
162+
"boundary_specials",
163+
"nullable_specials",
164+
]),
70165
vec![
71166
sensor_enc.encode(&sensor_prim).into_array(),
72167
drift_enc.encode(&drift_prim).into_array(),
168+
constant_enc.encode(&constant_prim).into_array(),
169+
decreasing_enc.encode(&decreasing_prim).into_array(),
170+
oscillating_enc.encode(&oscillating_prim).into_array(),
171+
periodic_resets_enc
172+
.encode(&periodic_resets_prim)
173+
.into_array(),
73174
nullable_enc.encode(&sensor_nullable).into_array(),
175+
special_enc.encode(&special_prim).into_array(),
176+
boundary_enc.encode(&boundary_prim).into_array(),
177+
nullable_special_enc.encode(&nullable_specials).into_array(),
74178
],
75179
N,
76180
Validity::NonNullable,

0 commit comments

Comments
 (0)