yaooqinn commented on a change in pull request #29064:
URL: https://github.com/apache/spark/pull/29064#discussion_r453527973



##########
File path: 
sql/core/src/main/scala/org/apache/spark/sql/execution/SparkSqlParser.scala
##########
@@ -90,6 +93,51 @@ class SparkSqlAstBuilder(conf: SQLConf) extends 
AstBuilder(conf) {
     ResetCommand
   }
 
+  /**
+   * Create a [[SetCommand]] logical plan to set 
[[SQLConf.SESSION_LOCAL_TIMEZONE]]
+   * Example SQL :
+   * {{{
+   *   SET TIME ZONE LOCAL;
+   *   SET TIME ZONE 'Asia/Shanghai';
+   *   SET TIME ZONE INTERVAL 10 HOURS;
+   * }}}
+   */
+  override def visitSetTimeZone(ctx: SetTimeZoneContext): LogicalPlan = 
withOrigin(ctx) {
+    val key = SQLConf.SESSION_LOCAL_TIMEZONE.key
+    if (ctx.interval != null) {
+      val interval = parseIntervalLiteral(ctx.interval)
+      if (interval.months != 0 || interval.days != 0 ||
+        math.abs(interval.microseconds) > 18 * 
DateTimeConstants.MICROS_PER_HOUR) {
+        throw new ParseException("The interval value must be in the range of 
[-18, +18] hours",
+          ctx.interval())
+      } else {
+        val seconds = (interval.microseconds / 
DateTimeConstants.MICROS_PER_SECOND).toInt
+        SetCommand(Some(key -> 
Some(ZoneOffset.ofTotalSeconds(seconds).toString)))
+      }
+    } else if (ctx.timezone != null) {
+      ctx.timezone.getType match {
+        case SqlBaseParser.LOCAL =>
+          SetCommand(Some(key -> Some(TimeZone.getDefault.getID)))

Review comment:
       This is the same as the default value of `spark.sql.session.timeZone`, 
shall I change that part too if I change it here?




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