chenzhx commented on code in PR #36663:
URL: https://github.com/apache/spark/pull/36663#discussion_r908011517


##########
sql/core/src/main/scala/org/apache/spark/sql/catalyst/util/V2ExpressionBuilder.scala:
##########
@@ -254,6 +254,55 @@ class V2ExpressionBuilder(e: Expression, isPredicate: 
Boolean = false) {
       } else {
         None
       }
+    case date: DateAdd =>
+      val childrenExpressions = date.children.flatMap(generateExpression(_))
+      if (childrenExpressions.length == date.children.length) {
+        Some(new GeneralScalarExpression("DATE_ADD", 
childrenExpressions.toArray[V2Expression]))
+      } else {
+        None
+      }
+    case date: DateDiff =>
+      val childrenExpressions = date.children.flatMap(generateExpression(_))
+      if (childrenExpressions.length == date.children.length) {
+        Some(new GeneralScalarExpression("DATE_DIFF", 
childrenExpressions.toArray[V2Expression]))
+      } else {
+        None
+      }
+    case date: TruncDate =>
+      val childrenExpressions = date.children.flatMap(generateExpression(_))
+      if (childrenExpressions.length == date.children.length) {
+        Some(new GeneralScalarExpression("TRUNC", 
childrenExpressions.toArray[V2Expression]))
+      } else {
+        None
+      }
+    case Second(child, _) =>
+      generateExpression(child).map(v => new V2Extract("SECOND", v))
+    case Minute(child, _) =>
+      generateExpression(child).map(v => new V2Extract("MINUTE", v))
+    case Hour(child, _) =>
+      generateExpression(child).map(v => new V2Extract("HOUR", v))
+    case Month(child) =>
+      generateExpression(child).map(v => new V2Extract("MONTH", v))
+    case Quarter(child) =>
+      generateExpression(child).map(v => new V2Extract("QUARTER", v))
+    case Year(child) =>
+      generateExpression(child).map(v => new V2Extract("YEAR", v))
+    // The DAY_OF_WEEK function in Spark returns the day of the week for 
date/timestamp.
+    // Database dialects should avoid to follow ISO semantics when handling 
DAY_OF_WEEK.
+    case DayOfWeek(child) =>
+      generateExpression(child).map(v => new V2Extract("DAY_OF_WEEK", v))
+    case DayOfMonth(child) =>
+      generateExpression(child).map(v => new V2Extract("DAY_OF_MONTH", v))
+    case DayOfYear(child) =>
+      generateExpression(child).map(v => new V2Extract("DAY_OF_YEAR", v))
+    // The WEEK_OF_YEAR function in Spark returns the ISO week from a 
date/timestamp.
+    // Database dialects need to follow ISO semantics when handling 
WEEK_OF_YEAR.
+    case WeekOfYear(child) =>
+      generateExpression(child).map(v => new V2Extract("WEEK_OF_YEAR", v))
+    // The YEAR_OF_WEEK function in Spark returns the ISO week year from a 
date/timestamp.
+    // Database dialects need to follow ISO semantics when handling 
YEAR_OF_WEEK.
+    case YearOfWeek(child) =>
+      generateExpression(child).map(v => new V2Extract("YEAR_OF_WEEK", v))

Review Comment:
   But in spark 
   WeekDay is (0 = Monday, 1 = Tuesday, ..., 6 = Sunday).
   DayOfWeek is  (1 = Sunday, 2 = Monday, ..., 7 = Saturday).
   
   It seem like:
   Spark DayOfWeek -> (EXTACT(ISO_DOW FROM ...) % 7)+ 1
   Spark WeekDay -> EXTACT(ISO_DOW FROM ...) -1



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

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


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

Reply via email to