2010YOUY01 commented on code in PR #16780:
URL: https://github.com/apache/datafusion/pull/16780#discussion_r2206536716


##########
datafusion/spark/src/function/datetime/next_day.rs:
##########
@@ -0,0 +1,255 @@
+// 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::{new_null_array, ArrayRef, AsArray, Date32Array, 
StringArrayType};
+use arrow::datatypes::{DataType, Date32Type};
+use chrono::{Datelike, Duration, Weekday};
+use datafusion_common::types::NativeType;
+use datafusion_common::{exec_err, plan_err, Result, ScalarValue};
+use datafusion_expr::{
+    ColumnarValue, ScalarFunctionArgs, ScalarUDFImpl, Signature, Volatility,
+};
+
+/// <https://spark.apache.org/docs/latest/api/sql/index.html#next_day>
+#[derive(Debug)]
+pub struct SparkNextDay {
+    signature: Signature,
+}
+
+impl Default for SparkNextDay {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
+impl SparkNextDay {
+    pub fn new() -> Self {
+        Self {
+            signature: Signature::user_defined(Volatility::Immutable),

Review Comment:
   We can define a specific signature here to be `(Date32, 
Utf8/Utf8View/LargeUtf8)`
   After that I think the implementation can be simplified
   - No need to implement `coerce_types()`, there are code to handle that 
automatically based on the signature.
   - We can assume the signature is valid inside `invoke_with_args()`, so there 
would be no need to check invalid input (sanity checks like `unreachable!()` or 
returning internal errors for invalid input can still be applied)



##########
datafusion/sqllogictest/test_files/spark/datetime/next_day.slt:
##########
@@ -23,5 +23,17 @@
 
 ## Original Query: SELECT next_day('2015-01-14', 'TU');
 ## PySpark 3.5.5 Result: {'next_day(2015-01-14, TU)': datetime.date(2015, 1, 
20), 'typeof(next_day(2015-01-14, TU))': 'date', 'typeof(2015-01-14)': 
'string', 'typeof(TU)': 'string'}
-#query
-#SELECT next_day('2015-01-14'::string, 'TU'::string);
+query D

Review Comment:
   I recommend to add tests for invalid inputs: 
   1. 0 or >2 inputs 
   2. Each element can be either valid input, invalid input of correct type 
like `2015-13-32`, or invalid types, and finally nulls. We want to test 
different combinations, to ensure for invalid inputs, the expected (and 
easy-to-understand) errors are returned, instead of panicking.
   
   Also here we only checked `ScalarValue()` input, let's also do the tests for 
`Array` inputs.



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

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


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

Reply via email to