You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "chenkovsky (via GitHub)" <gi...@apache.org> on 2025/08/03 13:59:13 UTC

[PR] feat(spark): implement spark datetime function date_add/date_sub [datafusion]

chenkovsky opened a new pull request, #17024:
URL: https://github.com/apache/datafusion/pull/17024

   ## Which issue does this PR close?
   
   - Closes #.
   
   ## Rationale for this change
   
   
   ## What changes are included in this PR?
   
   implement spark function date_add/date_sub
   
   ## Are these changes tested?
   
   UT
   
   ## Are there any user-facing changes?
   
   No


-- 
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@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] feat(spark): implement spark datetime function date_add/date_sub [datafusion]

Posted by "2010YOUY01 (via GitHub)" <gi...@apache.org>.
2010YOUY01 commented on PR #17024:
URL: https://github.com/apache/datafusion/pull/17024#issuecomment-3149103950

   This CI failure is not related to the change, and it should be fixed now.
   
   I've triggered re-run for this CI job.


-- 
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@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] feat(spark): implement spark datetime function date_add/date_sub [datafusion]

Posted by "andygrove (via GitHub)" <gi...@apache.org>.
andygrove commented on code in PR #17024:
URL: https://github.com/apache/datafusion/pull/17024#discussion_r2260609924


##########
datafusion/spark/src/function/datetime/date_add.rs:
##########
@@ -0,0 +1,95 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use std::any::Any;
+use std::sync::Arc;
+
+use arrow::array::ArrayRef;
+use arrow::compute;
+use arrow::datatypes::{DataType, Date32Type};
+use datafusion_common::cast::{as_date32_array, as_int32_array};
+use datafusion_common::{internal_err, Result};
+use datafusion_expr::{
+    ColumnarValue, ScalarFunctionArgs, ScalarUDFImpl, Signature, Volatility,
+};
+use datafusion_functions::utils::make_scalar_function;
+
+#[derive(Debug)]
+pub struct SparkDateAdd {
+    signature: Signature,
+    aliases: Vec<String>,
+}
+
+impl Default for SparkDateAdd {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
+impl SparkDateAdd {
+    pub fn new() -> Self {
+        Self {
+            signature: Signature::exact(
+                vec![DataType::Date32, DataType::Int32],

Review Comment:
   Spark accepts Int8, Int16, and Int32 for the second argument
   
   ```scala
     override def inputTypes: Seq[AbstractDataType] =
       Seq(DateType, TypeCollection(IntegerType, ShortType, ByteType))
   ```
   
   In the Comet implementation of date_add/date_sub, we support all three as well:
   
   https://github.com/apache/datafusion-comet/blob/main/native/spark-expr/src/datetime_funcs/date_arithmetic.rs#L53



-- 
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@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] feat(spark): implement spark datetime function date_add/date_sub [datafusion]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb merged PR #17024:
URL: https://github.com/apache/datafusion/pull/17024


-- 
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@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org