JeelRajodiya commented on code in PR #21639: URL: https://github.com/apache/datafusion/pull/21639#discussion_r3107112011
########## datafusion/sqllogictest/test_files/spark/datetime/monthname.slt: ########## @@ -0,0 +1,110 @@ +# 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. + +# Scalar date input +query T +SELECT monthname('2024-03-15'::DATE); +---- +Mar + +# All 12 months +query T +SELECT monthname('2024-01-15'::DATE); +---- +Jan + +query T +SELECT monthname('2024-02-15'::DATE); +---- +Feb + +query T +SELECT monthname('2024-03-15'::DATE); +---- +Mar + +query T +SELECT monthname('2024-04-15'::DATE); +---- +Apr + +query T +SELECT monthname('2024-05-15'::DATE); +---- +May + +query T +SELECT monthname('2024-06-15'::DATE); +---- +Jun + +query T +SELECT monthname('2024-07-15'::DATE); +---- +Jul + +query T +SELECT monthname('2024-08-15'::DATE); +---- +Aug + +query T +SELECT monthname('2024-09-15'::DATE); +---- +Sep + +query T +SELECT monthname('2024-10-15'::DATE); +---- +Oct + +query T +SELECT monthname('2024-11-15'::DATE); +---- +Nov + +query T +SELECT monthname('2024-12-15'::DATE); +---- +Dec + +# NULL handling +query T +SELECT monthname(NULL::DATE); +---- +NULL + +# Array input +query T +SELECT monthname(d) FROM (VALUES ('2024-01-01'::DATE), ('2024-06-15'::DATE), ('2024-12-31'::DATE), (NULL::DATE)) AS t(d); +---- +Jan +Jun +Dec +NULL + +# Error: wrong argument type (string without cast) +statement error Failed to coerce arguments to satisfy a call to 'monthname' function +SELECT monthname('not-a-date'); Review Comment: `monthname` was added in spark 4.0 ([source code](https://github.com/apache/spark/blob/acfae3372874631728243ba13728f6abbf7ee07b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/datetimeExpressions.scala#L916-L930)). Should we be returning `NULL` in such cases? if yes, I'll add the ANSI mode flag so we return NULL. ```scala @ExpressionDescription( usage = "_FUNC_(date) - Returns the three-letter abbreviated month name from the given date.", examples = """ Examples: > SELECT _FUNC_('2008-02-20'); Feb """, group = "datetime_funcs", since = "4.0.0") case class MonthName(child: Expression) extends GetDateField with DefaultStringProducingExpression { override val func = DateTimeUtils.getMonthName override val funcName = "getMonthName" override protected def withNewChildInternal(newChild: Expression): MonthName = copy(child = newChild) } ``` -- 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
