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


##########
datafusion/sqllogictest/test_files/spark/datetime/last_day.slt:
##########
@@ -21,7 +21,80 @@
 # For more information, please see:
 #   https://github.com/apache/datafusion/issues/15914
 
-## Original Query: SELECT last_day('2009-01-12');
-## PySpark 3.5.5 Result: {'last_day(2009-01-12)': datetime.date(2009, 1, 31), 
'typeof(last_day(2009-01-12))': 'date', 'typeof(2009-01-12)': 'string'}
-#query
-#SELECT last_day('2009-01-12'::string);
+query D
+SELECT last_day('2009-01-12'::string);
+----
+2009-01-31
+
+
+query D
+SELECT last_day('2015-02-28'::string);
+----
+2015-02-28
+
+query D
+SELECT last_day('2015-03-27'::string);
+----
+2015-03-31
+
+query D
+SELECT last_day('2015-04-26'::string);
+----
+2015-04-30
+
+query D
+SELECT last_day('2015-05-25'::string);
+----
+2015-05-31
+
+query D
+SELECT last_day('2015-06-24'::string);
+----
+2015-06-30
+
+query D
+SELECT last_day('2015-07-23'::string);
+----
+2015-07-31
+
+query D
+SELECT last_day('2015-08-01'::string);
+----
+2015-08-31
+
+query D
+SELECT last_day('2015-09-02'::string);
+----
+2015-09-30
+
+query D
+SELECT last_day('2015-10-03'::string);
+----
+2015-10-31
+
+query D
+SELECT last_day('2015-11-04'::string);
+----
+2015-11-30
+
+query D
+SELECT last_day('2015-12-05'::string);
+----
+2015-12-31
+
+
+query D
+SELECT last_day('2016-01-06'::string);
+----
+2016-01-31
+
+query D
+SELECT last_day('2016-02-07'::string);
+----
+2016-02-29
+
+
+query ?
+SELECT NULL;

Review Comment:
   Is it `select last_day(null)`?
   
   perhaps we can add more bad case tests like
   ```sql
   select last_day('foo');
   select last_day(123);
   select last_day();
   select last_day(last_day('2016-02-07'::string, 'foo');
   select last_day(last_day('2016-02-31'::string);
   ```
   And ensure it's returning expected errors.



##########
datafusion/spark/src/function/datetime/last_day.rs:
##########
@@ -0,0 +1,145 @@
+// 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, AsArray, Date32Array};
+use arrow::datatypes::{DataType, Date32Type};
+use chrono::{Datelike, Duration, NaiveDate};
+use datafusion_common::types::NativeType;
+use datafusion_common::{exec_datafusion_err, exec_err, plan_err, Result, 
ScalarValue};
+use datafusion_expr::{
+    ColumnarValue, ScalarFunctionArgs, ScalarUDFImpl, Signature, Volatility,
+};
+
+#[derive(Debug)]
+pub struct SparkLastDay {
+    signature: Signature,
+}
+
+impl Default for SparkLastDay {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
+impl SparkLastDay {
+    pub fn new() -> Self {
+        Self {
+            signature: Signature::user_defined(Volatility::Immutable),

Review Comment:
   I think you can set the signature to be taking exactly one Date32 type.
   After, the planning routine will automatically do all the validations and 
coercions, then:
   - We can assume inside `invoke_with_args()` the input must have valid type, 
so those `exec_err`s can be changed to `internal_err` just for sanity check
   - No need to implement coerce_types()



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