Skip to content

Commit 55800e2

Browse files
committed
Merge remote-tracking branch 'origin/develop' into ji/scalar-fn-binary-2
# Conflicts: # vortex-vector/src/binaryview/scalar.rs # vortex-vector/src/bool/scalar.rs # vortex-vector/src/datum.rs # vortex-vector/src/decimal/scalar.rs # vortex-vector/src/fixed_size_list/scalar.rs # vortex-vector/src/lib.rs # vortex-vector/src/listview/scalar.rs # vortex-vector/src/null/scalar.rs # vortex-vector/src/primitive/scalar.rs # vortex-vector/src/scalar.rs # vortex-vector/src/struct_/scalar.rs
2 parents c7188a6 + 1d907be commit 55800e2

File tree

50 files changed

+853
-190
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+853
-190
lines changed

.github/actions/setup-rust/action.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ inputs:
1515
targets:
1616
description: "optional targets override (e.g. wasm32-unknown-unknown)"
1717
required: false
18+
cache-suffix:
19+
description: "optional suffix for cache key to isolate builds with different RUSTFLAGS (e.g. 'sanitizer')"
20+
required: false
21+
default: ""
1822

1923
runs:
2024
using: "composite"
@@ -48,7 +52,7 @@ runs:
4852
uses: Swatinem/rust-cache@v2
4953
with:
5054
save-if: ${{ github.ref_name == 'develop' }}
51-
shared-key: "rust-cache-${{ runner.os }}-${{ runner.arch }}-${{ runner.environment }}-${{ steps.toolchain-config.outputs.toolchain }}-${{ steps.toolchain-config.outputs.targets }}"
55+
shared-key: "rust-cache-${{ runner.os }}-${{ runner.arch }}-${{ runner.environment }}-${{ steps.toolchain-config.outputs.toolchain }}-${{ steps.toolchain-config.outputs.targets }}${{ inputs.cache-suffix && format('-{0}', inputs.cache-suffix) || '' }}"
5256

5357
- name: Rust Compile Cache
5458
uses: mozilla-actions/[email protected]

.github/runs-on.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
images:
2+
vortex-ci-amd64:
3+
platform: "linux"
4+
arch: "x64"
5+
name: "vortex-ci-*"
6+
owner: "375504701696"
7+
vortex-ci-arm64:
8+
platform: "linux"
9+
arch: "arm64"
10+
name: "vortex-ci-*"
11+
owner: "375504701696"

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,7 @@ jobs:
421421
repo-token: ${{ secrets.GITHUB_TOKEN }}
422422
toolchain: nightly
423423
components: "rust-src, rustfmt, clippy, llvm-tools-preview"
424+
cache-suffix: "sanitizer"
424425
- name: Install build dependencies
425426
run: |
426427
sudo apt-get update
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
// SPDX-FileCopyrightText: Copyright the Vortex contributors
3+
4+
use vortex_mask::Mask;
5+
6+
use crate::ArrayRef;
7+
use crate::stats::ArrayStats;
8+
9+
#[derive(Clone, Debug)]
10+
pub struct FilterArray {
11+
pub(super) child: ArrayRef,
12+
pub(super) mask: Mask,
13+
pub(super) stats: ArrayStats,
14+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
// SPDX-FileCopyrightText: Copyright the Vortex contributors
3+
4+
mod array;
5+
mod vtable;
6+
7+
pub use vtable::*;
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
// SPDX-FileCopyrightText: Copyright the Vortex contributors
3+
4+
use std::hash::Hasher;
5+
6+
use vortex_buffer::BufferHandle;
7+
use vortex_dtype::DType;
8+
use vortex_error::VortexResult;
9+
use vortex_error::vortex_bail;
10+
use vortex_mask::Mask;
11+
use vortex_vector::Vector;
12+
13+
use crate::Array;
14+
use crate::ArrayBufferVisitor;
15+
use crate::ArrayChildVisitor;
16+
use crate::ArrayEq;
17+
use crate::ArrayHash;
18+
use crate::Precision;
19+
use crate::arrays::filter::array::FilterArray;
20+
use crate::execution::ExecutionCtx;
21+
use crate::serde::ArrayChildren;
22+
use crate::stats::StatsSetRef;
23+
use crate::vtable;
24+
use crate::vtable::ArrayId;
25+
use crate::vtable::ArrayVTable;
26+
use crate::vtable::ArrayVTableExt;
27+
use crate::vtable::BaseArrayVTable;
28+
use crate::vtable::NotSupported;
29+
use crate::vtable::VTable;
30+
use crate::vtable::VisitorVTable;
31+
32+
vtable!(Filter);
33+
34+
#[derive(Debug)]
35+
pub struct FilterVTable;
36+
37+
impl VTable for FilterVTable {
38+
type Array = FilterArray;
39+
type Metadata = Mask;
40+
type ArrayVTable = Self;
41+
type CanonicalVTable = NotSupported;
42+
type OperationsVTable = NotSupported;
43+
type ValidityVTable = NotSupported;
44+
type VisitorVTable = Self;
45+
type ComputeVTable = NotSupported;
46+
type EncodeVTable = NotSupported;
47+
48+
fn id(&self) -> ArrayId {
49+
ArrayId::from("vortex.filter")
50+
}
51+
52+
fn encoding(_array: &Self::Array) -> ArrayVTable {
53+
FilterVTable.as_vtable()
54+
}
55+
56+
fn metadata(array: &Self::Array) -> VortexResult<Self::Metadata> {
57+
Ok(array.mask.clone())
58+
}
59+
60+
fn serialize(_metadata: Self::Metadata) -> VortexResult<Option<Vec<u8>>> {
61+
Ok(None)
62+
}
63+
64+
fn deserialize(_bytes: &[u8]) -> VortexResult<Self::Metadata> {
65+
vortex_bail!("Filter array is not serializable")
66+
}
67+
68+
fn build(
69+
&self,
70+
dtype: &DType,
71+
len: usize,
72+
metadata: &Self::Metadata,
73+
_buffers: &[BufferHandle],
74+
children: &dyn ArrayChildren,
75+
) -> VortexResult<Self::Array> {
76+
let child = children.get(0, dtype, len)?;
77+
Ok(FilterArray {
78+
child,
79+
mask: metadata.clone(),
80+
stats: Default::default(),
81+
})
82+
}
83+
84+
fn batch_execute(array: &Self::Array, ctx: &mut ExecutionCtx) -> VortexResult<Vector> {
85+
let child = array.child.batch_execute(ctx)?;
86+
Ok(vortex_compute::filter::Filter::filter(&child, &array.mask))
87+
}
88+
}
89+
90+
impl BaseArrayVTable<FilterVTable> for FilterVTable {
91+
fn len(array: &FilterArray) -> usize {
92+
array.mask.true_count()
93+
}
94+
95+
fn dtype(array: &FilterArray) -> &DType {
96+
array.child.dtype()
97+
}
98+
99+
fn stats(array: &FilterArray) -> StatsSetRef<'_> {
100+
array.stats.to_ref(array.as_ref())
101+
}
102+
103+
fn array_hash<H: Hasher>(array: &FilterArray, state: &mut H, precision: Precision) {
104+
array.child.array_hash(state, precision);
105+
array.mask.array_hash(state, precision);
106+
}
107+
108+
fn array_eq(array: &FilterArray, other: &FilterArray, precision: Precision) -> bool {
109+
array.child.array_eq(&other.child, precision) && array.mask.array_eq(&other.mask, precision)
110+
}
111+
}
112+
113+
impl VisitorVTable<FilterVTable> for FilterVTable {
114+
fn visit_buffers(_array: &FilterArray, _visitor: &mut dyn ArrayBufferVisitor) {}
115+
116+
fn visit_children(array: &FilterArray, visitor: &mut dyn ArrayChildVisitor) {
117+
visitor.visit_child("child", &array.child);
118+
}
119+
}

vortex-array/src/arrays/masked/vtable/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ mod operations;
77
mod validity;
88

99
use vortex_buffer::BufferHandle;
10-
use vortex_compute::mask::MaskValidity;
1110
use vortex_dtype::DType;
1211
use vortex_error::VortexResult;
1312
use vortex_error::vortex_bail;
1413
use vortex_vector::Vector;
14+
use vortex_vector::VectorOps;
1515

1616
use crate::ArrayBufferVisitor;
1717
use crate::ArrayChildVisitor;
@@ -106,8 +106,9 @@ impl VTable for MaskedVTable {
106106
}
107107

108108
fn batch_execute(array: &Self::Array, ctx: &mut ExecutionCtx) -> VortexResult<Vector> {
109-
let vector = array.child().batch_execute(ctx)?;
110-
Ok(MaskValidity::mask_validity(vector, &array.validity_mask()))
109+
let mut vector = array.child().batch_execute(ctx)?;
110+
vector.mask_validity(&array.validity_mask());
111+
Ok(vector)
111112
}
112113
}
113114

vortex-array/src/arrays/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ mod datetime;
2222
mod decimal;
2323
mod dict;
2424
mod extension;
25+
mod filter;
2526
mod fixed_size_list;
2627
mod list;
2728
mod listview;
@@ -35,6 +36,7 @@ mod varbinview;
3536

3637
#[cfg(feature = "arbitrary")]
3738
pub mod arbitrary;
39+
// pub mod pipeline;
3840
// TODO(connor): Export exact types, not glob.
3941

4042
pub use bool::*;
@@ -44,6 +46,7 @@ pub use datetime::*;
4446
pub use decimal::*;
4547
pub use dict::*;
4648
pub use extension::*;
49+
pub use filter::*;
4750
pub use fixed_size_list::*;
4851
pub use list::*;
4952
pub use listview::*;

vortex-array/src/arrays/scalar_fn/array.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,16 @@
22
// SPDX-FileCopyrightText: Copyright the Vortex contributors
33

44
use vortex_dtype::DType;
5+
use vortex_error::VortexResult;
6+
use vortex_error::vortex_ensure;
57

8+
use crate::Array;
69
use crate::ArrayRef;
10+
use crate::arrays::ScalarFnVTable;
711
use crate::expr::functions::scalar::ScalarFn;
812
use crate::stats::ArrayStats;
913
use crate::vtable::ArrayVTable;
14+
use crate::vtable::ArrayVTableExt;
1015

1116
#[derive(Clone, Debug)]
1217
pub struct ScalarFnArray {
@@ -18,3 +23,25 @@ pub struct ScalarFnArray {
1823
pub(super) children: Vec<ArrayRef>,
1924
pub(super) stats: ArrayStats,
2025
}
26+
27+
impl ScalarFnArray {
28+
/// Create a new ScalarFnArray from a scalar function and its children.
29+
pub fn try_new(scalar_fn: ScalarFn, children: Vec<ArrayRef>, len: usize) -> VortexResult<Self> {
30+
let arg_dtypes: Vec<_> = children.iter().map(|c| c.dtype().clone()).collect();
31+
let dtype = scalar_fn.return_dtype(&arg_dtypes)?;
32+
33+
vortex_ensure!(
34+
children.iter().all(|c| c.len() == len),
35+
"ScalarFnArray must have children equal to the array length"
36+
);
37+
38+
Ok(Self {
39+
vtable: ScalarFnVTable::new(scalar_fn.vtable().clone()).into_vtable(),
40+
scalar_fn,
41+
dtype,
42+
len,
43+
children,
44+
stats: Default::default(),
45+
})
46+
}
47+
}

vortex-array/src/arrays/scalar_fn/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ mod array;
55
mod metadata;
66
mod vtable;
77

8+
pub use array::*;
89
pub use vtable::*;

0 commit comments

Comments
 (0)