alamb commented on code in PR #3110:
URL: https://github.com/apache/arrow-datafusion/pull/3110#discussion_r945992742


##########
datafusion/physical-expr/src/expressions/datetime.rs:
##########
@@ -112,71 +120,166 @@ impl PhysicalExpr for DateIntervalExpr {
             }
         };
 
-        // Unwrap days since epoch
-        let operand = match dates {
-            ColumnarValue::Scalar(scalar) => scalar,
-            _ => Err(DataFusionError::Execution(
-                "Columnar execution is not yet supported for DateIntervalExpr"
-                    .to_string(),
-            ))?,
-        };
-
-        let res = match operand {
-            ScalarValue::Date32(Some(d)) => {
-                let epoch = NaiveDate::from_ymd(1970, 1, 1);
-                let prior = epoch.add(Duration::days(d as i64));
-                let posterior = do_date_math(prior, scalar, sign)?;
-                let days = posterior.sub(epoch).num_days() as i32;
-                ColumnarValue::Scalar(ScalarValue::Date32(Some(days)))
-            }
-            ScalarValue::Date64(Some(ms)) => {
-                let epoch = NaiveDate::from_ymd(1970, 1, 1);
-                let prior = epoch.add(Duration::milliseconds(ms));
-                let posterior = do_date_math(prior, scalar, sign)?;
-                let ms = posterior.sub(epoch).num_milliseconds();
-                ColumnarValue::Scalar(ScalarValue::Date64(Some(ms)))
-            }
-            ScalarValue::TimestampSecond(Some(ts_s), zone) => {
-                let value = do_data_time_math(ts_s, 0, scalar, 
sign)?.timestamp();
-                
ColumnarValue::Scalar(ScalarValue::TimestampSecond(Some(value), zone))
-            }
-            ScalarValue::TimestampMillisecond(Some(ts_ms), zone) => {
-                let secs = ts_ms / 1000;
-                let nsecs = ((ts_ms % 1000) * 1_000_000) as u32;
-                let value =
-                    do_data_time_math(secs, nsecs, scalar, 
sign)?.timestamp_millis();
-                ColumnarValue::Scalar(ScalarValue::TimestampMillisecond(
-                    Some(value),
-                    zone,
-                ))
-            }
-            ScalarValue::TimestampMicrosecond(Some(ts_us), zone) => {
-                let secs = ts_us / 1_000_000;
-                let nsecs = ((ts_us % 1_000_000) * 1000) as u32;
-                let value = do_data_time_math(secs, nsecs, scalar, sign)?
-                    .timestamp_nanos()
-                    / 1000;
-                ColumnarValue::Scalar(ScalarValue::TimestampMicrosecond(
-                    Some(value),
-                    zone,
-                ))
-            }
-            ScalarValue::TimestampNanosecond(Some(ts_ns), zone) => {
-                let secs = ts_ns / 1_000_000_000;
-                let nsecs = (ts_ns % 1_000_000_000) as u32;
-                let value =
-                    do_data_time_math(secs, nsecs, scalar, 
sign)?.timestamp_nanos();
-                
ColumnarValue::Scalar(ScalarValue::TimestampNanosecond(Some(value), zone))
-            }
-            _ => Err(DataFusionError::Execution(format!(
-                "Invalid lhs type for DateIntervalExpr: {}",
-                scalar
-            )))?,
-        };
-        Ok(res)
+        match dates {
+            ColumnarValue::Scalar(operand) => evaluate_scalar(operand, sign, 
intervals),
+            ColumnarValue::Array(array) => evaluate_array(array, sign, 
intervals),
+        }
     }
 }
 
+pub fn evaluate_array(
+    array: ArrayRef,
+    sign: i32,
+    scalar: &ScalarValue,
+) -> Result<ColumnarValue> {
+    let ret = match array.data_type() {
+        DataType::Date32 => {
+            let array = array.as_any().downcast_ref::<Date32Array>().unwrap();

Review Comment:
   I will file a ticket as this is confusing and it would be nice to get 
DataFusion consistent
   



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to