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/24 17:43:15 UTC

[GitHub] [arrow-datafusion] berkaysynnada commented on a diff in pull request #6433: Refactor temporal arithmetic

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


##########
datafusion/physical-expr/src/expressions/binary.rs:
##########
@@ -1689,7 +1874,524 @@ pub fn interval_scalar_interval_op(
             scalar.get_datatype(),
         )))?,
     };
-    Ok(ColumnarValue::Array(ret))
+    Ok(ret)
+}
+
+/// This function handles interval +/- interval operations where the former is
+/// a scalar and the latter is an array, resulting in an interval array.
+pub fn scalar_interval_op_interval(
+    scalar: &ScalarValue,
+    sign: i32,
+    array: &ArrayRef,
+) -> Result<ArrayRef> {
+    let ret = match (scalar, array.data_type()) {
+        // YearMonth op YearMonth
+        (
+            ScalarValue::IntervalYearMonth(Some(lhs)),
+            DataType::Interval(IntervalUnit::YearMonth),
+        ) => {
+            let array = as_interval_ym_array(&array)?;
+            let ret: PrimitiveArray<IntervalYearMonthType> =
+                unary(array, |rhs| op_ym(*lhs, rhs, sign));
+            Arc::new(ret) as _

Review Comment:
   Thank you for the review. I cannot figure out getting rid of `as _ `, but your other advice of adding namespaces has significantly decreased the number of lines. 



-- 
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