|
3 | 3 |
|
4 | 4 | use std::fmt::Formatter; |
5 | 5 |
|
6 | | -use arrow_array::Array; |
7 | 6 | use arrow_ord::cmp; |
8 | 7 | use prost::Message; |
9 | | -use vortex_compute::arithmetic::Add; |
10 | | -use vortex_compute::arithmetic::Arithmetic; |
11 | | -use vortex_compute::arithmetic::CheckedArithmetic; |
12 | | -use vortex_compute::arithmetic::Div; |
13 | | -use vortex_compute::arithmetic::Mul; |
14 | | -use vortex_compute::arithmetic::Sub; |
| 8 | +use vortex_compute::arrow::IntoArrow; |
| 9 | +use vortex_compute::arrow::IntoVector; |
15 | 10 | use vortex_dtype::DType; |
16 | 11 | use vortex_error::VortexExpect; |
17 | 12 | use vortex_error::VortexResult; |
18 | 13 | use vortex_error::vortex_bail; |
19 | 14 | use vortex_error::vortex_err; |
20 | 15 | use vortex_proto::expr as pb; |
21 | 16 | use vortex_vector::Datum; |
22 | | -use vortex_vector::PrimitiveDatum; |
23 | | -use vortex_vector::Vector; |
24 | 17 |
|
25 | 18 | use crate::ArrayRef; |
26 | 19 | use crate::compute; |
@@ -142,50 +135,52 @@ impl VTable for Binary { |
142 | 135 |
|
143 | 136 | match op { |
144 | 137 | 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 | | - )?)); |
| 138 | + let lhs = lhs.ensure_vector(args.row_count).into_bool().into_arrow()?; |
| 139 | + let rhs = rhs.ensure_vector(args.row_count).into_bool().into_arrow()?; |
| 140 | + return Ok(Datum::Vector( |
| 141 | + arrow_arith::boolean::and_kleene(&lhs, &rhs)? |
| 142 | + .into_vector()? |
| 143 | + .into(), |
| 144 | + )); |
150 | 145 | } |
151 | 146 | 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 | | - )?)); |
| 147 | + let lhs = lhs.ensure_vector(args.row_count).into_bool().into_arrow()?; |
| 148 | + let rhs = rhs.ensure_vector(args.row_count).into_bool().into_arrow()?; |
| 149 | + return Ok(Datum::Vector( |
| 150 | + arrow_arith::boolean::or_kleene(&lhs, &rhs)? |
| 151 | + .into_vector()? |
| 152 | + .into(), |
| 153 | + )); |
157 | 154 | } |
158 | 155 | _ => {} |
159 | 156 | } |
160 | 157 |
|
161 | | - let lhs: Box<dyn arrow_array::Datum> = lhs.try_into()?; |
162 | | - let rhs: Box<dyn arrow_array::Datum> = rhs.try_into()?; |
| 158 | + let lhs = lhs.into_arrow()?; |
| 159 | + let rhs = rhs.into_arrow()?; |
163 | 160 |
|
164 | 161 | let vector = match op { |
165 | | - Operator::Eq => Vector::try_from(&cmp::eq(lhs.as_ref(), rhs.as_ref())? as &dyn Array)?, |
166 | | - Operator::NotEq => { |
167 | | - Vector::try_from(&cmp::neq(lhs.as_ref(), rhs.as_ref())? as &dyn Array)? |
168 | | - } |
169 | | - Operator::Gt => Vector::try_from(&cmp::gt(lhs.as_ref(), rhs.as_ref())? as &dyn Array)?, |
170 | | - Operator::Gte => { |
171 | | - Vector::try_from(&cmp::gt_eq(lhs.as_ref(), rhs.as_ref())? as &dyn Array)? |
172 | | - } |
173 | | - Operator::Lt => Vector::try_from(&cmp::lt(lhs.as_ref(), rhs.as_ref())? as &dyn Array)?, |
174 | | - Operator::Lte => { |
175 | | - Vector::try_from(&cmp::lt_eq(lhs.as_ref(), rhs.as_ref())? as &dyn Array)? |
176 | | - } |
| 162 | + Operator::Eq => cmp::eq(lhs.as_ref(), rhs.as_ref())?.into_vector()?.into(), |
| 163 | + Operator::NotEq => cmp::neq(lhs.as_ref(), rhs.as_ref())?.into_vector()?.into(), |
| 164 | + Operator::Gt => cmp::gt(lhs.as_ref(), rhs.as_ref())?.into_vector()?.into(), |
| 165 | + Operator::Gte => cmp::gt_eq(lhs.as_ref(), rhs.as_ref())? |
| 166 | + .into_vector()? |
| 167 | + .into(), |
| 168 | + Operator::Lt => cmp::lt(lhs.as_ref(), rhs.as_ref())?.into_vector()?.into(), |
| 169 | + Operator::Lte => cmp::lt_eq(lhs.as_ref(), rhs.as_ref())? |
| 170 | + .into_vector()? |
| 171 | + .into(), |
177 | 172 |
|
178 | 173 | Operator::Add => { |
179 | | - Vector::try_from(arrow_arith::numeric::add(lhs.as_ref(), rhs.as_ref())?.as_ref())? |
| 174 | + arrow_arith::numeric::add(lhs.as_ref(), rhs.as_ref())?.into_vector()? |
180 | 175 | } |
181 | 176 | Operator::Sub => { |
182 | | - Vector::try_from(arrow_arith::numeric::sub(lhs.as_ref(), rhs.as_ref())?.as_ref())? |
| 177 | + arrow_arith::numeric::sub(lhs.as_ref(), rhs.as_ref())?.into_vector()? |
183 | 178 | } |
184 | 179 | Operator::Mul => { |
185 | | - Vector::try_from(arrow_arith::numeric::mul(lhs.as_ref(), rhs.as_ref())?.as_ref())? |
| 180 | + arrow_arith::numeric::mul(lhs.as_ref(), rhs.as_ref())?.into_vector()? |
186 | 181 | } |
187 | 182 | Operator::Div => { |
188 | | - Vector::try_from(arrow_arith::numeric::div(lhs.as_ref(), rhs.as_ref())?.as_ref())? |
| 183 | + arrow_arith::numeric::div(lhs.as_ref(), rhs.as_ref())?.into_vector()? |
189 | 184 | } |
190 | 185 | Operator::And | Operator::Or => { |
191 | 186 | unreachable!("Already dealt with above") |
@@ -323,35 +318,6 @@ impl VTable for Binary { |
323 | 318 | } |
324 | 319 | } |
325 | 320 |
|
326 | | -fn execute_arithmetic_primitive( |
327 | | - lhs: PrimitiveDatum, |
328 | | - rhs: PrimitiveDatum, |
329 | | - op: Operator, |
330 | | -) -> VortexResult<Datum> { |
331 | | - // Float arithmetic - no overflow checking needed |
332 | | - if lhs.ptype().is_float() && lhs.ptype() == rhs.ptype() { |
333 | | - let result: PrimitiveDatum = match op { |
334 | | - Operator::Add => Arithmetic::<Add>::eval(lhs, rhs), |
335 | | - Operator::Sub => Arithmetic::<Sub>::eval(lhs, rhs), |
336 | | - Operator::Mul => Arithmetic::<Mul>::eval(lhs, rhs), |
337 | | - Operator::Div => Arithmetic::<Div>::eval(lhs, rhs), |
338 | | - _ => unreachable!("Not an arithmetic operator"), |
339 | | - }; |
340 | | - return Ok(result.into()); |
341 | | - } |
342 | | - // Integer arithmetic - use checked operations |
343 | | - let result: Option<PrimitiveDatum> = match op { |
344 | | - Operator::Add => CheckedArithmetic::<Add>::checked_eval(lhs, rhs), |
345 | | - Operator::Sub => CheckedArithmetic::<Sub>::checked_eval(lhs, rhs), |
346 | | - Operator::Mul => CheckedArithmetic::<Mul>::checked_eval(lhs, rhs), |
347 | | - Operator::Div => CheckedArithmetic::<Div>::checked_eval(lhs, rhs), |
348 | | - _ => unreachable!("Not an arithmetic operator"), |
349 | | - }; |
350 | | - result |
351 | | - .map(|d| d.into()) |
352 | | - .ok_or_else(|| vortex_err!("Arithmetic overflow/underflow or type mismatch")) |
353 | | -} |
354 | | - |
355 | 321 | /// Create a new [`Binary`] using the [`Eq`](crate::expr::exprs::operators::Operator::Eq) operator. |
356 | 322 | /// |
357 | 323 | /// ## Example usage |
|
0 commit comments