yaooqinn commented on a change in pull request #29064:
URL: https://github.com/apache/spark/pull/29064#discussion_r455577033
##########
File path:
sql/core/src/main/scala/org/apache/spark/sql/execution/SparkSqlParser.scala
##########
@@ -90,6 +92,41 @@ 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 ||
+ interval.microseconds % DateTimeConstants.MICROS_PER_SECOND != 0) {
+ throw new ParseException("The interval value must be in the range of
[-18, +18] hours" +
+ " with second precision",
+ 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:
```
kentyao@hulk ~/spark SPARK-32272 TZ="America/Los_Angeles" scala
Welcome to Scala 2.13.1 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_251).
Type in expressions for evaluation. Or try :help.
scala> java.util.TimeZone.getDefault.getID
res0: String = America/Los_Angeles
scala> %
✘ kentyao@hulk ~/spark SPARK-32272 TZ="Asia/Hong_kong" scala
Welcome to Scala 2.13.1 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_251).
Type in expressions for evaluation. Or try :help.
scala> java.util.TimeZone.getDefault.getID
res0: String = GMT+08:00
```
check on this
----------------------------------------------------------------
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]