Skip to content

Commit 041d3ed

Browse files
committed
Flat Layout Execution
Signed-off-by: Nicholas Gates <[email protected]>
1 parent 9b9aac5 commit 041d3ed

File tree

4 files changed

+105
-24
lines changed

4 files changed

+105
-24
lines changed

vortex-array/src/expr/exprs/between.rs

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,26 @@ use std::fmt::Formatter;
66
use prost::Message;
77
use vortex_dtype::DType;
88
use vortex_dtype::DType::Bool;
9+
use vortex_error::vortex_bail;
10+
use vortex_error::vortex_err;
911
use vortex_error::VortexExpect;
1012
use vortex_error::VortexResult;
11-
use vortex_error::vortex_bail;
1213
use vortex_proto::expr as pb;
1314
use vortex_vector::Datum;
1415

15-
use crate::ArrayRef;
16-
use crate::compute::BetweenOptions;
1716
use crate::compute::between as between_compute;
17+
use crate::compute::BetweenOptions;
18+
use crate::expr::expression::Expression;
19+
use crate::expr::exprs::binary::Binary;
20+
use crate::expr::exprs::operators::Operator;
1821
use crate::expr::Arity;
1922
use crate::expr::ChildName;
2023
use crate::expr::ExecutionArgs;
2124
use crate::expr::ExprId;
2225
use crate::expr::StatsCatalog;
2326
use crate::expr::VTable;
2427
use crate::expr::VTableExt;
25-
use crate::expr::expression::Expression;
26-
use crate::expr::exprs::binary::Binary;
27-
use crate::expr::exprs::operators::Operator;
28+
use crate::ArrayRef;
2829

2930
/// An optimized scalar expression to compute whether values fall between two bounds.
3031
///
@@ -149,8 +150,39 @@ impl VTable for Between {
149150
between_compute(&arr, &lower, &upper, options)
150151
}
151152

152-
fn execute(&self, _data: &Self::Options, _args: ExecutionArgs) -> VortexResult<Datum> {
153-
todo!()
153+
fn execute(&self, options: &Self::Options, args: ExecutionArgs) -> VortexResult<Datum> {
154+
let [arr, lower, upper]: [Datum; _] = args
155+
.datums
156+
.try_into()
157+
.map_err(|_| vortex_err!("Expected 3 arguments for Between expression",))?;
158+
let [arr_dt, lower_dt, upper_dt]: [DType; _] = args
159+
.dtypes
160+
.try_into()
161+
.map_err(|_| vortex_err!("Expected 3 dtypes for Between expression",))?;
162+
163+
let lower_bound = Binary
164+
.bind(options.lower_strict.to_operator().into())
165+
.execute(ExecutionArgs {
166+
datums: vec![lower.clone(), arr.clone()],
167+
dtypes: vec![lower_dt.clone(), arr_dt.clone()],
168+
row_count: args.row_count,
169+
return_dtype: args.return_dtype.clone(),
170+
})?;
171+
let upper_bound = Binary
172+
.bind(options.upper_strict.to_operator().into())
173+
.execute(ExecutionArgs {
174+
datums: vec![arr.clone(), upper.clone()],
175+
dtypes: vec![arr_dt.clone(), upper_dt.clone()],
176+
row_count: args.row_count,
177+
return_dtype: args.return_dtype.clone(),
178+
})?;
179+
180+
Binary.bind(Operator::And).execute(ExecutionArgs {
181+
datums: vec![lower_bound, upper_bound],
182+
dtypes: vec![args.return_dtype.clone(), args.return_dtype.clone()],
183+
row_count: args.row_count,
184+
return_dtype: args.return_dtype.clone(),
185+
})
154186
}
155187

156188
fn stat_falsification(

vortex-array/src/expr/exprs/binary.rs

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,15 @@ use vortex_compute::arithmetic::Div;
1313
use vortex_compute::arithmetic::Mul;
1414
use vortex_compute::arithmetic::Sub;
1515
use vortex_dtype::DType;
16-
use vortex_error::VortexExpect;
17-
use vortex_error::VortexResult;
1816
use vortex_error::vortex_bail;
1917
use vortex_error::vortex_err;
18+
use vortex_error::VortexExpect;
19+
use vortex_error::VortexResult;
2020
use vortex_proto::expr as pb;
2121
use vortex_vector::Datum;
2222
use vortex_vector::PrimitiveDatum;
2323
use vortex_vector::Vector;
2424

25-
use crate::ArrayRef;
2625
use crate::compute;
2726
use crate::compute::add;
2827
use crate::compute::and_kleene;
@@ -31,17 +30,18 @@ use crate::compute::div;
3130
use crate::compute::mul;
3231
use crate::compute::or_kleene;
3332
use crate::compute::sub;
33+
use crate::expr::expression::Expression;
34+
use crate::expr::exprs::literal::lit;
35+
use crate::expr::exprs::operators::Operator;
36+
use crate::expr::stats::Stat;
3437
use crate::expr::Arity;
3538
use crate::expr::ChildName;
3639
use crate::expr::ExecutionArgs;
3740
use crate::expr::ExprId;
3841
use crate::expr::StatsCatalog;
3942
use crate::expr::VTable;
4043
use crate::expr::VTableExt;
41-
use crate::expr::expression::Expression;
42-
use crate::expr::exprs::literal::lit;
43-
use crate::expr::exprs::operators::Operator;
44-
use crate::expr::stats::Stat;
44+
use crate::ArrayRef;
4545

4646
pub struct Binary;
4747

@@ -140,6 +140,24 @@ impl VTable for Binary {
140140
.try_into()
141141
.map_err(|_| vortex_err!("Wrong arg count"))?;
142142

143+
match op {
144+
Operator::And => {
145+
let lhs = lhs.ensure_vector(args.row_count).into_bool().into();
146+
let rhs = rhs.ensure_vector(args.row_count).into_bool().into();
147+
return Ok(Datum::Vector(Vector::try_from(
148+
&arrow_arith::boolean::and_kleene(&lhs, &rhs)? as &dyn Array,
149+
)?));
150+
}
151+
Operator::Or => {
152+
let lhs = lhs.ensure_vector(args.row_count).into_bool().into();
153+
let rhs = rhs.ensure_vector(args.row_count).into_bool().into();
154+
return Ok(Datum::Vector(Vector::try_from(
155+
&arrow_arith::boolean::or_kleene(&lhs, &rhs)? as &dyn Array,
156+
)?));
157+
}
158+
_ => {}
159+
}
160+
143161
let lhs: Box<dyn arrow_array::Datum> = lhs.try_into()?;
144162
let rhs: Box<dyn arrow_array::Datum> = rhs.try_into()?;
145163

@@ -169,7 +187,9 @@ impl VTable for Binary {
169187
Operator::Div => {
170188
Vector::try_from(arrow_arith::numeric::div(lhs.as_ref(), rhs.as_ref())?.as_ref())?
171189
}
172-
_ => vortex_bail!("Unsupported operator in execute: {}", op),
190+
Operator::And | Operator::Or => {
191+
unreachable!("Already dealt with above")
192+
}
173193
};
174194

175195
Ok(Datum::Vector(vector))
@@ -597,10 +617,10 @@ mod tests {
597617
use super::lt_eq;
598618
use super::not_eq;
599619
use super::or;
600-
use crate::expr::Expression;
601620
use crate::expr::exprs::get_item::col;
602621
use crate::expr::exprs::literal::lit;
603622
use crate::expr::test_harness;
623+
use crate::expr::Expression;
604624

605625
#[test]
606626
fn and_collect_left_assoc() {

vortex-array/src/expr/exprs/like.rs

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,26 @@
33

44
use std::fmt::Formatter;
55

6+
use arrow_array::cast::AsArray;
67
use prost::Message;
78
use vortex_dtype::DType;
8-
use vortex_error::VortexResult;
99
use vortex_error::vortex_bail;
10+
use vortex_error::vortex_err;
11+
use vortex_error::VortexResult;
1012
use vortex_proto::expr as pb;
13+
use vortex_vector::bool::BoolVector;
1114
use vortex_vector::Datum;
1215

13-
use crate::ArrayRef;
14-
use crate::compute::LikeOptions;
1516
use crate::compute::like as like_compute;
17+
use crate::compute::LikeOptions;
1618
use crate::expr::Arity;
1719
use crate::expr::ChildName;
1820
use crate::expr::ExecutionArgs;
1921
use crate::expr::ExprId;
2022
use crate::expr::Expression;
2123
use crate::expr::VTable;
2224
use crate::expr::VTableExt;
25+
use crate::ArrayRef;
2326

2427
/// Expression that performs SQL LIKE pattern matching.
2528
pub struct Like;
@@ -109,8 +112,27 @@ impl VTable for Like {
109112
like_compute(&child, &pattern, *options)
110113
}
111114

112-
fn execute(&self, _data: &Self::Options, _args: ExecutionArgs) -> VortexResult<Datum> {
113-
todo!()
115+
fn execute(&self, options: &Self::Options, args: ExecutionArgs) -> VortexResult<Datum> {
116+
let [child, pattern]: [Datum; _] = args
117+
.datums
118+
.try_into()
119+
.map_err(|_| vortex_err!("Wrong argument count"))?;
120+
121+
let child: Box<dyn arrow_array::Datum> = child.try_into()?;
122+
let pattern: Box<dyn arrow_array::Datum> = pattern.try_into()?;
123+
124+
let array = pattern.get().0;
125+
let sv = array.as_string_view();
126+
println!("STRING VIEW PATTERN: {:?}", sv);
127+
128+
let array = match (options.negated, options.case_insensitive) {
129+
(false, false) => arrow_string::like::like(child.as_ref(), pattern.as_ref()),
130+
(false, true) => arrow_string::like::ilike(child.as_ref(), pattern.as_ref()),
131+
(true, false) => arrow_string::like::nlike(child.as_ref(), pattern.as_ref()),
132+
(true, true) => arrow_string::like::nilike(child.as_ref(), pattern.as_ref()),
133+
}?;
134+
135+
Ok(Datum::Vector(BoolVector::from(&array).into()))
114136
}
115137

116138
fn is_null_sensitive(&self, _instance: &Self::Options) -> bool {
@@ -163,14 +185,14 @@ mod tests {
163185
use vortex_dtype::DType;
164186
use vortex_dtype::Nullability;
165187

166-
use crate::ToCanonical;
167188
use crate::arrays::BoolArray;
168189
use crate::expr::exprs::get_item::get_item;
169190
use crate::expr::exprs::like::like;
170191
use crate::expr::exprs::like::not_ilike;
171192
use crate::expr::exprs::literal::lit;
172193
use crate::expr::exprs::not::not;
173194
use crate::expr::exprs::root::root;
195+
use crate::ToCanonical;
174196

175197
#[test]
176198
fn invert_booleans() {

vortex-vector/src/arrow/bool.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ use arrow_array::Array;
99
use arrow_array::ArrayRef;
1010
use arrow_array::BooleanArray;
1111
use vortex_buffer::BitBuffer;
12-
use vortex_error::VortexError;
1312
use vortex_error::vortex_err;
13+
use vortex_error::VortexError;
1414

1515
impl TryFrom<BoolVector> for ArrayRef {
1616
type Error = VortexError;
@@ -21,6 +21,13 @@ impl TryFrom<BoolVector> for ArrayRef {
2121
}
2222
}
2323

24+
impl From<BoolVector> for BooleanArray {
25+
fn from(value: BoolVector) -> Self {
26+
let (bits, validity) = value.into_parts();
27+
BooleanArray::new(bits.into(), validity.into())
28+
}
29+
}
30+
2431
impl From<&BooleanArray> for BoolVector {
2532
fn from(value: &BooleanArray) -> Self {
2633
let bits = BitBuffer::from(value.values().clone());

0 commit comments

Comments
 (0)