Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion encodings/datetime-parts/src/compute/rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ impl ArrayParentReduceRule<DateTimeParts> for DTPFilterPushDownRule {
) -> VortexResult<Option<ArrayRef>> {
debug_assert_eq!(child_idx, 0);

if !child.seconds().is::<Constant>() || !child.subseconds().is::<Constant>() {
if *child.seconds().encoding_id() != Constant::ID
|| *child.subseconds().encoding_id() != Constant::ID
{
return Ok(None);
}

Expand Down
2 changes: 1 addition & 1 deletion encodings/zstd/src/zstd_buffers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ impl ZstdBuffers {
}

pub fn compress(array: &ArrayRef, level: i32) -> VortexResult<ZstdBuffersArray> {
let encoding_id = array.encoding_id();
let metadata = array
.metadata()?
.ok_or_else(|| vortex_err!("Array does not support serialization"))?;
Expand All @@ -74,6 +73,7 @@ impl ZstdBuffers {
compressed_buffers.push(BufferHandle::new_host(ByteBuffer::from(compressed)));
}

let encoding_id = array.encoding_id().clone();
let data = ZstdBuffersData {
inner_encoding_id: encoding_id,
inner_metadata: metadata,
Expand Down
6 changes: 3 additions & 3 deletions vortex-array/public-api.lock
Original file line number Diff line number Diff line change
Expand Up @@ -21504,7 +21504,7 @@ pub fn vortex_array::Array<V>::data(&self) -> &<V as vortex_array::VTable>::Arra

pub fn vortex_array::Array<V>::dtype(&self) -> &vortex_array::dtype::DType

pub fn vortex_array::Array<V>::encoding_id(&self) -> vortex_array::ArrayId
pub fn vortex_array::Array<V>::encoding_id(&self) -> &vortex_array::ArrayId

pub fn vortex_array::Array<V>::into_data(self) -> <V as vortex_array::VTable>::ArrayData

Expand Down Expand Up @@ -21680,7 +21680,7 @@ pub fn vortex_array::ArrayRef::downcast<V: vortex_array::VTable>(self) -> vortex

pub fn vortex_array::ArrayRef::dtype(&self) -> &vortex_array::dtype::DType

pub fn vortex_array::ArrayRef::encoding_id(&self) -> vortex_array::ArrayId
pub fn vortex_array::ArrayRef::encoding_id(&self) -> &vortex_array::ArrayId

pub fn vortex_array::ArrayRef::execute_parent(&self, parent: &vortex_array::ArrayRef, child_idx: usize, ctx: &mut vortex_array::ExecutionCtx) -> vortex_error::VortexResult<core::option::Option<vortex_array::ArrayRef>>

Expand Down Expand Up @@ -22128,7 +22128,7 @@ pub fn vortex_array::ArrayView<'a, V>::data(&self) -> &'a <V as vortex_array::VT

pub fn vortex_array::ArrayView<'a, V>::dtype(&self) -> &vortex_array::dtype::DType

pub fn vortex_array::ArrayView<'a, V>::encoding_id(&self) -> vortex_array::ArrayId
pub fn vortex_array::ArrayView<'a, V>::encoding_id(&self) -> &vortex_array::ArrayId

pub fn vortex_array::ArrayView<'a, V>::into_owned(self) -> vortex_array::Array<V>

Expand Down
2 changes: 1 addition & 1 deletion vortex-array/src/aggregate_fn/accumulator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ impl<V: AggregateFnVTable> DynAccumulator for Accumulator<V> {
}

let kernels_r = kernels.read();
let batch_id = batch.encoding_id();
let batch_id = batch.encoding_id().clone();
if let Some(result) = kernels_r
.get(&(batch_id.clone(), Some(self.aggregate_fn.id())))
.or_else(|| kernels_r.get(&(batch_id, None)))
Expand Down
10 changes: 6 additions & 4 deletions vortex-array/src/aggregate_fn/accumulator_grouped.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,10 @@ impl<V: AggregateFnVTable> GroupedAccumulator<V> {
}

let kernels_r = kernels.read();
let elements_id = elements.encoding_id().clone();
if let Some(result) = kernels_r
.get(&(elements.encoding_id(), Some(self.aggregate_fn.id())))
.or_else(|| kernels_r.get(&(elements.encoding_id(), None)))
.get(&(elements_id.clone(), Some(self.aggregate_fn.id())))
.or_else(|| kernels_r.get(&(elements_id, None)))
.and_then(|kernel| {
// SAFETY: we assume that elements execution is safe
let groups = unsafe {
Expand Down Expand Up @@ -263,9 +264,10 @@ impl<V: AggregateFnVTable> GroupedAccumulator<V> {
}

let kernels_r = kernels.read();
let elements_id = elements.encoding_id().clone();
if let Some(result) = kernels_r
.get(&(elements.encoding_id(), Some(self.aggregate_fn.id())))
.or_else(|| kernels_r.get(&(elements.encoding_id(), None)))
.get(&(elements_id.clone(), Some(self.aggregate_fn.id())))
.or_else(|| kernels_r.get(&(elements_id, None)))
.and_then(|kernel| {
// SAFETY: we assume that elements execution is safe
let groups = unsafe {
Expand Down
3 changes: 2 additions & 1 deletion vortex-array/src/aggregate_fn/fns/is_constant/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ pub fn is_constant(array: &ArrayRef, ctx: &mut ExecutionCtx) -> VortexResult<boo
}

// Constant and null arrays are always constant.
if array.is::<Constant>() || array.is::<Null>() {
let id = array.encoding_id();
if *id == Constant::ID || *id == Null::ID {
array
.statistics()
.set(Stat::IsConstant, Precision::Exact(true.into()));
Expand Down
3 changes: 2 additions & 1 deletion vortex-array/src/aggregate_fn/fns/is_sorted/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ fn is_sorted_impl(array: &ArrayRef, strict: bool, ctx: &mut ExecutionCtx) -> Vor
}

// Constant and null arrays are always sorted, but not strict sorted.
if array.is::<Constant>() || array.is::<Null>() {
let id = array.encoding_id();
if *id == Constant::ID || *id == Null::ID {
let result = !strict;
cache_is_sorted(array, strict, result);
return Ok(result);
Expand Down
4 changes: 2 additions & 2 deletions vortex-array/src/array/erased.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ impl ArrayRef {

/// Returns the encoding ID of the array.
#[inline]
pub fn encoding_id(&self) -> ArrayId {
self.0.encoding_id()
pub fn encoding_id(&self) -> &ArrayId {
self.inner().encoding_id()
}

/// Performs a constant-time slice of the array.
Expand Down
10 changes: 5 additions & 5 deletions vortex-array/src/array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub(crate) trait DynArray: 'static + private::Sealed + Send + Sync + Debug {
fn slots(&self) -> &[Option<ArrayRef>];

/// Returns the encoding ID of the array.
fn encoding_id(&self) -> ArrayId;
fn encoding_id(&self) -> &ArrayId;

/// Fetch the scalar at the given index.
///
Expand Down Expand Up @@ -210,8 +210,8 @@ impl<V: VTable> DynArray for ArrayInner<V> {
&self.slots
}

fn encoding_id(&self) -> ArrayId {
self.vtable.id()
fn encoding_id(&self) -> &ArrayId {
&self.encoding_id
}

fn scalar_at(&self, this: &ArrayRef, index: usize) -> VortexResult<Scalar> {
Expand Down Expand Up @@ -367,7 +367,7 @@ impl<V: VTable> DynArray for ArrayInner<V> {
.is_some_and(|other_inner| {
self.len == other.len()
&& self.dtype == *other.dtype()
&& self.vtable.id() == other.encoding_id()
&& &self.vtable.id() == other.encoding_id()
&& self.slots.len() == other_inner.slots.len()
&& self
.slots
Expand Down Expand Up @@ -442,7 +442,7 @@ impl<V: VTable> DynArray for ArrayInner<V> {
let stats = this.statistics().to_owned();

let typed = Array::<V>::try_from_array_ref(this)
.map_err(|_| vortex_err!("Failed to downcast array for execute"))
.map_err(|_| vortex_err!(""))
.vortex_expect("Failed to downcast array for execute");
let result = V::execute(typed, ctx)?;

Expand Down
10 changes: 7 additions & 3 deletions vortex-array/src/array/typed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ impl<V: VTable> TypedArrayRef<V> for ArrayView<'_, V> {}
#[doc(hidden)]
pub(crate) struct ArrayInner<V: VTable> {
pub(crate) vtable: V,
pub(crate) encoding_id: ArrayId,
pub(crate) dtype: DType,
pub(crate) len: usize,
pub(crate) data: V::ArrayData,
Expand Down Expand Up @@ -115,8 +116,10 @@ impl<V: VTable> ArrayInner<V> {
slots: Vec<Option<ArrayRef>>,
stats: ArrayStats,
) -> Self {
let encoding_id = vtable.id();
Self {
vtable,
encoding_id,
dtype,
len,
data,
Expand All @@ -143,6 +146,7 @@ impl<V: VTable> Clone for ArrayInner<V> {
fn clone(&self) -> Self {
Self {
vtable: self.vtable.clone(),
encoding_id: self.encoding_id.clone(),
dtype: self.dtype.clone(),
len: self.len,
data: self.data.clone(),
Expand All @@ -155,7 +159,7 @@ impl<V: VTable> Clone for ArrayInner<V> {
impl<V: VTable> Debug for ArrayInner<V> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
f.debug_struct("ArrayInner")
.field("encoding", &self.vtable.id())
.field("encoding", &self.encoding_id)
.field("dtype", &self.dtype)
.field("len", &self.len)
.field("inner", &self.data)
Expand Down Expand Up @@ -265,8 +269,8 @@ impl<V: VTable> Array<V> {
}

/// Returns the encoding ID.
pub fn encoding_id(&self) -> ArrayId {
self.inner.encoding_id()
pub fn encoding_id(&self) -> &ArrayId {
&self.downcast_inner().encoding_id
}

/// Returns the statistics.
Expand Down
2 changes: 1 addition & 1 deletion vortex-array/src/array/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl<'a, V: VTable> ArrayView<'a, V> {
self.array.len() == 0
}

pub fn encoding_id(&self) -> ArrayId {
pub fn encoding_id(&self) -> &ArrayId {
self.array.encoding_id()
}

Expand Down
22 changes: 11 additions & 11 deletions vortex-array/src/canonical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -995,17 +995,17 @@ impl Matcher for AnyCanonical {
type Match<'a> = CanonicalView<'a>;

fn matches(array: &ArrayRef) -> bool {
array.is::<Null>()
|| array.is::<Bool>()
|| array.is::<Primitive>()
|| array.is::<Decimal>()
|| array.is::<Struct>()
|| array.is::<ListView>()
|| array.is::<FixedSizeList>()
|| array.is::<VarBinView>()
|| array.is::<Variant>()
|| array.is::<Extension>()
|| array.is::<Variant>()
let id = array.encoding_id();
id == &Null::ID
|| id == &Bool::ID
|| id == &Primitive::ID
|| id == &Decimal::ID
|| id == &Struct::ID
|| id == &ListView::ID
|| id == &FixedSizeList::ID
|| id == &VarBinView::ID
|| id == &Variant::ID
|| id == &Extension::ID
}

fn try_match<'a>(array: &'a ArrayRef) -> Option<Self::Match<'a>> {
Expand Down
2 changes: 1 addition & 1 deletion vortex-array/src/normalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl ArrayRef {
}

fn normalize_with_error(&self, allowed: &[Id]) -> VortexResult<()> {
if !allowed.contains(&self.encoding_id()) {
if !allowed.contains(self.encoding_id()) {
vortex_bail!(AssertionFailed: "normalize forbids encoding ({})", self.encoding_id())
}

Expand Down
4 changes: 2 additions & 2 deletions vortex-array/src/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ impl<'a> ArrayNodeFlatBuffer<'a> {
) -> VortexResult<WIPOffset<fba::ArrayNode<'fb>>> {
let encoding_idx = self
.ctx
.intern(&self.array.encoding_id())
.intern(self.array.encoding_id())
// TODO(ngates): write_flatbuffer should return a result if this can fail.
.ok_or_else(|| {
vortex_err!(
Expand Down Expand Up @@ -358,7 +358,7 @@ impl SerializedArray {
);
assert_eq!(
decoded.encoding_id(),
encoding_id,
&encoding_id,
"Array decoded from {} has incorrect encoding {}",
encoding_id,
decoded.encoding_id(),
Expand Down
36 changes: 18 additions & 18 deletions vortex-cuda/src/dynamic_dispatch/plan_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ pub struct MaterializedPlan {
/// Checks whether the encoding of an array can be fused into a dynamic-dispatch plan.
fn is_dyn_dispatch_compatible(array: &ArrayRef) -> bool {
let id = array.encoding_id();
if id == ALP::ID {
if *id == ALP::ID {
let arr = array.as_::<ALP>();
return arr.patches().is_none() && arr.dtype().as_ptype() == PType::F32;
}
if id == BitPacked::ID {
if *id == BitPacked::ID {
return array.as_::<BitPacked>().patches().is_none();
}
if id == Dict::ID {
if *id == Dict::ID {
let arr = array.as_::<Dict>();
// As of now the dict dyn dispatch kernel requires
// codes and values to have the same byte width.
Expand All @@ -72,7 +72,7 @@ fn is_dyn_dispatch_compatible(array: &ArrayRef) -> bool {
_ => false,
};
}
if id == RunEnd::ID {
if *id == RunEnd::ID {
let arr = array.as_::<RunEnd>();
// As of now the run-end dyn dispatch kernel requires
// ends and values to have the same byte width.
Expand All @@ -84,11 +84,11 @@ fn is_dyn_dispatch_compatible(array: &ArrayRef) -> bool {
_ => false,
};
}
id == FoR::ID
|| id == ZigZag::ID
|| id == Primitive::ID
|| id == Slice::ID
|| id == Sequence::ID
*id == FoR::ID
|| *id == ZigZag::ID
|| *id == Primitive::ID
|| *id == Slice::ID
|| *id == Sequence::ID
}

/// An unmaterialized stage: a source op, scalar ops, and optional source buffer reference.
Expand Down Expand Up @@ -361,23 +361,23 @@ impl FusedPlan {

let id = array.encoding_id();

if id == BitPacked::ID {
if *id == BitPacked::ID {
self.walk_bitpacked(array)
} else if id == FoR::ID {
} else if *id == FoR::ID {
self.walk_for(array, pending_subtrees)
} else if id == ZigZag::ID {
} else if *id == ZigZag::ID {
self.walk_zigzag(array, pending_subtrees)
} else if id == ALP::ID {
} else if *id == ALP::ID {
self.walk_alp(array, pending_subtrees)
} else if id == Dict::ID {
} else if *id == Dict::ID {
self.walk_dict(array, pending_subtrees)
} else if id == RunEnd::ID {
} else if *id == RunEnd::ID {
self.walk_runend(array, pending_subtrees)
} else if id == Primitive::ID {
} else if *id == Primitive::ID {
self.walk_primitive(array)
} else if id == Slice::ID {
} else if *id == Slice::ID {
self.walk_slice(array, pending_subtrees)
} else if id == Sequence::ID {
} else if *id == Sequence::ID {
self.walk_sequence(array)
} else {
vortex_bail!(
Expand Down
2 changes: 1 addition & 1 deletion vortex-cuda/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ pub trait CudaArrayExt {
impl CudaArrayExt for ArrayRef {
#[allow(clippy::unwrap_in_result, clippy::unwrap_used)]
async fn execute_cuda(self, ctx: &mut CudaExecutionCtx) -> VortexResult<Canonical> {
if self.encoding_id() == Struct::ID {
if *self.encoding_id() == Struct::ID {
let len = self.len();
let StructDataParts {
fields,
Expand Down
2 changes: 1 addition & 1 deletion vortex-cuda/src/hybrid_dispatch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ pub async fn try_gpu_dispatch(
DispatchPlan::Unfused => {
// Unfused kernel dispatch fallback.
ctx.cuda_session()
.kernel(&array.encoding_id())
.kernel(array.encoding_id())
.ok_or_else(|| {
vortex_err!("No CUDA kernel for encoding {:?}", array.encoding_id())
})?
Expand Down
2 changes: 1 addition & 1 deletion vortex-cuda/src/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ fn extract_constant_buffers(chunk: &ArrayRef) -> Vec<InlinedBuffer> {
let mut buffer_idx = 0u32;
for array in chunk.depth_first_traversal() {
let n = array.nbuffers();
if array.encoding_id() == Constant::ID {
if *array.encoding_id() == Constant::ID {
for buf in array.buffers() {
result.push(InlinedBuffer {
buffer_index: buffer_idx,
Expand Down
4 changes: 2 additions & 2 deletions vortex-test/compat-gen/src/fixtures/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ pub fn check_expected_encodings(
let mut found: Vec<ArrayId> = Vec::new();
for node in array.depth_first_traversal() {
let id = node.encoding_id();
if !found.contains(&id) {
found.push(id);
if !found.contains(id) {
found.push(id.clone());
}
}

Expand Down
Loading