MaxGekk commented on a change in pull request #27876: [SPARK-31119][SQL] Add 
interval value support for extract expression as extract source
URL: https://github.com/apache/spark/pull/27876#discussion_r391440960
 
 

 ##########
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/datetimeExpressions.scala
 ##########
 @@ -2038,32 +2038,60 @@ case class Epoch(child: Expression, timeZoneId: 
Option[String] = None)
 
 object DatePart {
 
-  def parseExtractField(
-      extractField: String,
-      source: Expression,
-      errorHandleFunc: => Nothing): Expression = 
extractField.toUpperCase(Locale.ROOT) match {
-    case "MILLENNIUM" | "MILLENNIA" | "MIL" | "MILS" => Millennium(source)
-    case "CENTURY" | "CENTURIES" | "C" | "CENT" => Century(source)
-    case "DECADE" | "DECADES" | "DEC" | "DECS" => Decade(source)
-    case "YEAR" | "Y" | "YEARS" | "YR" | "YRS" => Year(source)
-    case "ISOYEAR" => IsoYear(source)
-    case "QUARTER" | "QTR" => Quarter(source)
-    case "MONTH" | "MON" | "MONS" | "MONTHS" => Month(source)
-    case "WEEK" | "W" | "WEEKS" => WeekOfYear(source)
-    case "DAY" | "D" | "DAYS" => DayOfMonth(source)
-    case "DAYOFWEEK" => DayOfWeek(source)
-    case "DOW" => Subtract(DayOfWeek(source), Literal(1))
-    case "ISODOW" => Add(WeekDay(source), Literal(1))
-    case "DOY" => DayOfYear(source)
-    case "HOUR" | "H" | "HOURS" | "HR" | "HRS" => Hour(source)
-    case "MINUTE" | "M" | "MIN" | "MINS" | "MINUTES" => Minute(source)
-    case "SECOND" | "S" | "SEC" | "SECONDS" | "SECS" => 
SecondWithFraction(source)
-    case "MILLISECONDS" | "MSEC" | "MSECS" | "MILLISECON" | "MSECONDS" | "MS" 
=>
-      Milliseconds(source)
-    case "MICROSECONDS" | "USEC" | "USECS" | "USECONDS" | "MICROSECON" | "US" 
=>
-      Microseconds(source)
-    case "EPOCH" => Epoch(source)
-    case _ => errorHandleFunc
+  def parseExtractField(extractField: String, source: Expression): Expression 
= {
+    val ef = extractField
+    val dt = source.dataType
+    (dt, ef) match {
+      case (_, null) => Literal(null, DoubleType)
+      case (CalendarIntervalType, "MILLENNIUM" | "MILLENNIA" | "MIL" | "MILS") 
=>
 
 Review comment:
   We have separate file `intervalExpressions.scala` for interval related 
expressions. Could you move the code related to interval to there. 
`datetimeExpressions.scala` has been already big enough, and highly likely will 
grow in the future.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to