Skip to content

Commit b1a491d

Browse files
committed
fix
Signed-off-by: Joe Isaacs <joe.isaacs@live.co.uk>
1 parent 7dd87e0 commit b1a491d

1 file changed

Lines changed: 42 additions & 2 deletions

File tree

vortex-array/src/normalize.rs

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ impl ArrayRef {
3636
// Note this takes ownership so we can at a later date remove non-allowed encodings.
3737
Ok(self)
3838
}
39-
Operation::Execute(ctx) => self.normalize_with_execution(options.allowed, *ctx),
39+
Operation::Execute(ctx) => self.normalize_with_execution(options.allowed, ctx),
4040
}
4141
}
4242

@@ -75,7 +75,7 @@ impl ArrayRef {
7575
allowed,
7676
operation: Operation::Execute(ctx),
7777
})?;
78-
any_slot_changed |= !ArrayRef::ptr_eq(&child, &normalized_child);
78+
any_slot_changed |= !ArrayRef::ptr_eq(child, &normalized_child);
7979
normalized_slots.push(Some(normalized_child));
8080
}
8181
None => normalized_slots.push(None),
@@ -94,13 +94,18 @@ impl ArrayRef {
9494
mod tests {
9595
use vortex_error::VortexResult;
9696
use vortex_session::VortexSession;
97+
use vortex_utils::aliases::hash_set::HashSet;
9798

9899
use super::NormalizeOptions;
99100
use super::Operation;
100101
use crate::ArrayRef;
101102
use crate::ExecutionCtx;
102103
use crate::IntoArray;
104+
use crate::arrays::Dict;
105+
use crate::arrays::DictArray;
106+
use crate::arrays::Primitive;
103107
use crate::arrays::PrimitiveArray;
108+
use crate::arrays::Slice;
104109
use crate::arrays::SliceArray;
105110
use crate::arrays::StructArray;
106111
use crate::assert_arrays_eq;
@@ -164,4 +169,39 @@ mod tests {
164169

165170
Ok(())
166171
}
172+
173+
#[test]
174+
fn normalize_slice_of_dict_returns_dict() -> VortexResult<()> {
175+
let codes = PrimitiveArray::from_iter(vec![0u32, 1, 0, 1, 2]).into_array();
176+
let values = PrimitiveArray::from_iter(vec![10i32, 20, 30]).into_array();
177+
let dict = DictArray::try_new(codes, values)?.into_array();
178+
179+
// Slice the dict array to get a SliceArray wrapping a DictArray.
180+
let sliced = SliceArray::new(dict, 1..4).into_array();
181+
assert_eq!(sliced.encoding_id(), Slice::ID);
182+
183+
let allowed = HashSet::from_iter([Dict::ID, Primitive::ID]);
184+
let mut ctx = ExecutionCtx::new(VortexSession::empty());
185+
186+
println!("sliced {}", sliced.display_tree());
187+
188+
let normalized = sliced.normalize(&mut NormalizeOptions {
189+
allowed: &allowed,
190+
operation: Operation::Execute(&mut ctx),
191+
})?;
192+
193+
println!("after {}", normalized.display_tree());
194+
195+
// The normalized result should be a DictArray, not a SliceArray.
196+
assert_eq!(normalized.encoding_id(), Dict::ID);
197+
assert_eq!(normalized.len(), 3);
198+
199+
// Verify the data: codes [1,0,1] -> values [20, 10, 20]
200+
assert_arrays_eq!(
201+
normalized.to_canonical()?,
202+
PrimitiveArray::from_iter(vec![20i32, 10, 20])
203+
);
204+
205+
Ok(())
206+
}
167207
}

0 commit comments

Comments
 (0)