You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "MaxGekk (via GitHub)" <gi...@apache.org> on 2024/01/17 10:21:00 UTC

Re: [PR] [WIP][SPARK-46725][SQL] Add DAYNAME function [spark]

MaxGekk commented on code in PR #44758:
URL: https://github.com/apache/spark/pull/44758#discussion_r1455157569


##########
R/pkg/R/functions.R:
##########
@@ -1105,6 +1105,20 @@ setMethod("monthname",
             column(jc)
           })
 
+#' @details
+#' \code{dayname}: Extracts the three-letter abbreviated month name from a

Review Comment:
   ```suggestion
   #' \code{dayname}: Extracts the three-letter abbreviated day name from a
   ```



##########
python/pyspark/sql/tests/test_functions.py:
##########
@@ -421,6 +421,12 @@ def test_monthname(self):
         row = df.select(F.monthname(df.date)).first()
         self.assertEqual(row[0], "Nov")
 
+    def test_dayname(self):
+            dt = datetime.datetime(2017, 11, 6)
+            df = self.spark.createDataFrame([Row(date=dt)])
+            row = df.select(F.dayname(df.date)).first()
+            self.assertEqual(row[0], "Mon")

Review Comment:
   Please, fix indentation here.



##########
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/DateExpressionsSuite.scala:
##########
@@ -269,6 +269,17 @@ class DateExpressionsSuite extends SparkFunSuite with ExpressionEvalHelper {
     checkConsistencyBetweenInterpretedAndCodegen(MonthName, DateType)
   }
 
+  test("DayName") {
+    checkEvaluation(DayName(Literal.create(null, DateType)), null)
+    checkEvaluation(DayName(Literal(d)), "Wed")
+    checkEvaluation(DayName(Cast(Literal(date), DateType, UTC_OPT)), "Wed")
+    checkEvaluation(DayName(Cast(Literal(ts), DateType, UTC_OPT)), "Fri")
+    checkEvaluation(DayName(Cast(Literal("2011-05-06"), DateType, UTC_OPT)), "Fri")
+    checkEvaluation(DayName(Literal(new Date(toMillis("2017-05-27 13:10:15")))), "Sat")
+    checkEvaluation(DayName(Literal(new Date(toMillis("1582-10-15 13:10:15")))), "Fri")

Review Comment:
   Could you use Java 8+ datetime API, and avoud `new Date`.



##########
connector/connect/client/jvm/src/main/scala/org/apache/spark/sql/functions.scala:
##########
@@ -5960,6 +5960,15 @@ object functions {
   def monthname(timeExp: Column): Column =
     Column.fn("monthname", timeExp)
 
+  /**
+   * Extracts the three-letter abbreviated month name from a given date/timestamp/string.

Review Comment:
   `month`? Please, replace it by `day`.



##########
python/pyspark/sql/functions/builtin.py:
##########
@@ -7303,6 +7303,36 @@ def monthname(col: "ColumnOrName") -> Column:
     return _invoke_function_over_columns("monthname", col)
 
 
+@_try_remote_functions
+def dayname(col: "ColumnOrName") -> Column:
+    """
+    Returns the three-letter abbreviated day name from the given date.
+
+    .. versionadded:: 4.0.0
+
+    Parameters
+    ----------
+    col : :class:`~pyspark.sql.Column` or str
+        target date/timestamp column to work on.
+
+    Returns
+    -------
+    :class:`~pyspark.sql.Column`
+        the three-letter abbreviation of day name for date/timestamp (Mon, Tue, Wed...)
+
+    Examples
+    --------
+    >>> df = spark.createDataFrame([('2015-04-08',)], ['dt'])
+    >>> df.select(dayname('dt').alias('day')).show()
+    +-----+
+    |day|

Review Comment:
   Is it actual output? Seems like something wrong with the table formatting.



##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/datetimeExpressions.scala:
##########
@@ -909,6 +909,24 @@ case class MonthName(child: Expression) extends GetDateField {
     copy(child = newChild)
 }
 
+// scalastyle:off line.size.limit

Review Comment:
   If you disable the check, could you enable it back when it is not needed.



-- 
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: reviews-unsubscribe@spark.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org