You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "berkaysynnada (via GitHub)" <gi...@apache.org> on 2023/05/03 16:35:14 UTC

[GitHub] [arrow-datafusion] berkaysynnada commented on a diff in pull request #6196: feat: allow scalars to appear as the LHS arg in arithmetic operations on temporal values

berkaysynnada commented on code in PR #6196:
URL: https://github.com/apache/arrow-datafusion/pull/6196#discussion_r1183937192


##########
datafusion/physical-expr/src/expressions/datetime.rs:
##########
@@ -120,16 +120,21 @@ impl PhysicalExpr for DateTimeIntervalExpr {
             (ColumnarValue::Array(array_lhs), ColumnarValue::Scalar(array_rhs)) => {
                 resolve_temporal_op_scalar(&array_lhs, sign, &array_rhs)
             }
+            // This function evaluates operations between a scalar value and an array of temporal
+            // values. One example is calculating the duration between a scalar timestamp and an
+            // array of timestamps (i.e. `now() - some_column`).
+            (ColumnarValue::Scalar(scalar_lhs), ColumnarValue::Array(array_rhs)) => {
+                let array_lhs = scalar_lhs.to_array_of_size(array_rhs.len());
+                Ok(ColumnarValue::Array(resolve_temporal_op(

Review Comment:
   The purpose of the `resolve_temporal_op` is actually to work with real array types. Otherwise, would we need specialized handlers for scalar types? I think this case can be handled in two ways:
   1) `resolve_temporal_op_scalar` is extended with a commute parameter. This pattern is applied in `impl_op_arithmetic`. The same functions should be able to handle Scalar op Array and Array op Scalar.
   2) A similar resolve_temporal_op_scalar function can be added with replaced parameters of Array and Scalar.
   Thank you for working on this issue. I can assist further if needed.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org