Dispatch the given `op` to the appropriate specialized kernel
(op: Op, lhs: &dyn Datum, rhs: &dyn Datum)
| 218 | |
| 219 | /// Dispatch the given `op` to the appropriate specialized kernel |
| 220 | fn arithmetic_op(op: Op, lhs: &dyn Datum, rhs: &dyn Datum) -> Result<ArrayRef, ArrowError> { |
| 221 | use DataType::*; |
| 222 | use IntervalUnit::*; |
| 223 | use TimeUnit::*; |
| 224 | |
| 225 | macro_rules! integer_helper { |
| 226 | ($t:ty, $op:ident, $l:ident, $l_scalar:ident, $r:ident, $r_scalar:ident) => { |
| 227 | integer_op::<$t>($op, $l, $l_scalar, $r, $r_scalar) |
| 228 | }; |
| 229 | } |
| 230 | |
| 231 | let (l, l_scalar) = lhs.get(); |
| 232 | let (r, r_scalar) = rhs.get(); |
| 233 | downcast_integer! { |
| 234 | l.data_type(), r.data_type() => (integer_helper, op, l, l_scalar, r, r_scalar), |
| 235 | (Float16, Float16) => float_op::<Float16Type>(op, l, l_scalar, r, r_scalar), |
| 236 | (Float32, Float32) => float_op::<Float32Type>(op, l, l_scalar, r, r_scalar), |
| 237 | (Float64, Float64) => float_op::<Float64Type>(op, l, l_scalar, r, r_scalar), |
| 238 | (Timestamp(Second, _), _) => timestamp_op::<TimestampSecondType>(op, l, l_scalar, r, r_scalar), |
| 239 | (Timestamp(Millisecond, _), _) => timestamp_op::<TimestampMillisecondType>(op, l, l_scalar, r, r_scalar), |
| 240 | (Timestamp(Microsecond, _), _) => timestamp_op::<TimestampMicrosecondType>(op, l, l_scalar, r, r_scalar), |
| 241 | (Timestamp(Nanosecond, _), _) => timestamp_op::<TimestampNanosecondType>(op, l, l_scalar, r, r_scalar), |
| 242 | (Duration(Second), Duration(Second)) => duration_op::<DurationSecondType>(op, l, l_scalar, r, r_scalar), |
| 243 | (Duration(Millisecond), Duration(Millisecond)) => duration_op::<DurationMillisecondType>(op, l, l_scalar, r, r_scalar), |
| 244 | (Duration(Microsecond), Duration(Microsecond)) => duration_op::<DurationMicrosecondType>(op, l, l_scalar, r, r_scalar), |
| 245 | (Duration(Nanosecond), Duration(Nanosecond)) => duration_op::<DurationNanosecondType>(op, l, l_scalar, r, r_scalar), |
| 246 | (Interval(YearMonth), Interval(YearMonth)) => interval_op::<IntervalYearMonthType>(op, l, l_scalar, r, r_scalar), |
| 247 | (Interval(DayTime), Interval(DayTime)) => interval_op::<IntervalDayTimeType>(op, l, l_scalar, r, r_scalar), |
| 248 | (Interval(MonthDayNano), Interval(MonthDayNano)) => interval_op::<IntervalMonthDayNanoType>(op, l, l_scalar, r, r_scalar), |
| 249 | (Date32, _) => date_op::<Date32Type>(op, l, l_scalar, r, r_scalar), |
| 250 | (Date64, _) => date_op::<Date64Type>(op, l, l_scalar, r, r_scalar), |
| 251 | (Decimal32(_, _), Decimal32(_, _)) => decimal_op::<Decimal32Type>(op, l, l_scalar, r, r_scalar), |
| 252 | (Decimal64(_, _), Decimal64(_, _)) => decimal_op::<Decimal64Type>(op, l, l_scalar, r, r_scalar), |
| 253 | (Decimal128(_, _), Decimal128(_, _)) => decimal_op::<Decimal128Type>(op, l, l_scalar, r, r_scalar), |
| 254 | (Decimal256(_, _), Decimal256(_, _)) => decimal_op::<Decimal256Type>(op, l, l_scalar, r, r_scalar), |
| 255 | (l_t, r_t) => match (l_t, r_t) { |
| 256 | (Duration(_) | Interval(_), Date32 | Date64 | Timestamp(_, _)) if op.commutative() => { |
| 257 | arithmetic_op(op, rhs, lhs) |
| 258 | } |
| 259 | _ => Err(ArrowError::InvalidArgumentError( |
| 260 | format!("Invalid arithmetic operation: {l_t} {op} {r_t}") |
| 261 | )) |
| 262 | } |
| 263 | } |
| 264 | } |
| 265 | |
| 266 | /// Perform an infallible binary operation on potentially scalar inputs |
| 267 | macro_rules! op { |
no test coverage detected