-
Notifications
You must be signed in to change notification settings - Fork 29.3k
[SPARK-32272][SQL] Add SQL standard command SET TIME ZONE #29064
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 9 commits
7910c9a
13056b5
225695f
3a62ecc
ef1f3ed
95a756a
c95fa7d
5501213
b3ac6f4
e5aa3b3
11f0fed
a4c60f3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| --- | ||
| layout: global | ||
| title: SET TIME ZONE | ||
| displayTitle: SET TIME ZONE | ||
| license: | | ||
| Licensed to the Apache Software Foundation (ASF) under one or more | ||
| contributor license agreements. See the NOTICE file distributed with | ||
| this work for additional information regarding copyright ownership. | ||
| The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| (the "License"); you may not use this file except in compliance with | ||
| the License. You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| --- | ||
|
|
||
| ### Description | ||
|
|
||
| The `SET TIME ZONE` command sets the current default time zone(`spark.sql.session.timeZone`) displacement for the `SparkSession`. | ||
|
|
||
| ### Syntax | ||
|
|
||
| ```sql | ||
| SET TIME ZONE LOCAL | ||
| SET TIME ZONE 'timezone_value' | ||
| SET TIME ZONE INTERVAL interval_literal | ||
| ``` | ||
|
|
||
| ### Parameters | ||
|
|
||
| * **LOCAL** | ||
|
|
||
| Respectively set the time zone the one specified in environment variable `TZ`, or to the operating system time zone if `TZ` is undefined. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. set the time zone "to" the one specified
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, it prefers
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Respectively set -> Sets? |
||
|
|
||
| * **timezone_value** | ||
|
|
||
| The ID of session local timezone in the format of either region-based zone IDs or zone offsets. Region IDs must have the form 'area/city', such as 'America/Los_Angeles'. Zone offsets must be in the format '`(+|-)HH`', '`(+|-)HH:mm`' or '`(+|-)HH:mm:ss`', e.g '-08', '+01:00' or '-13:33:33'. Also, 'UTC' and 'Z' are supported as aliases of '+00:00'. Other short names are not recommended to use because they can be ambiguous. | ||
|
|
||
| * **interval_literal** | ||
|
|
||
| The [interval literal](sql-ref-literals.html#interval-literal) represents the displacement of time zone to the 'UTC'. It must be in the range of [-18, 18] hours and max to second precision, e.g. `INTERVAL 2 HOURS 30 MINITUES` or `INTERVAL '15:40:32' HOUR TO SECOND`. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess something like this? |
||
|
|
||
| ### Examples | ||
|
|
||
| ```sql | ||
| -- Set time zone to the system default. | ||
| SET TIME ZONE LOCAL; | ||
|
|
||
| -- Set time zone to the region-based zone ID. | ||
| SET TIME ZONE 'America/Los_Angeles' | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: |
||
|
|
||
| -- Set time zone to the Zone offset. | ||
| SET TIME ZONE '+08:00'; | ||
|
|
||
| -- Set time zone with intervals. | ||
| SET TIME ZONE INTERVAL 1 HOUR 30 MINUTES; | ||
| SET TIME ZONE INTERVAL '08:30:00' HOUR TO SECOND; | ||
| ``` | ||
|
|
||
|
cloud-fan marked this conversation as resolved.
|
||
| ### Related Statements | ||
|
|
||
| * [SET](sql-ref-syntax-aux-conf-mgmt-set.html) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -240,6 +240,9 @@ statement | |
| | MSCK REPAIR TABLE multipartIdentifier #repairTable | ||
| | op=(ADD | LIST) identifier (STRING | .*?) #manageResource | ||
| | SET ROLE .*? #failNativeCommand | ||
| | SET TIME ZONE interval #setTimeZone | ||
| | SET TIME ZONE timezone=(STRING | LOCAL) #setTimeZone | ||
| | SET TIME ZONE .*? #setTimeZone | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so we add this only for better parser message?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is used to fail invalid set time zone syntax explicitly, cuz' now we support spark-sql (default)> set time zone abcd;
key value
time zone abcd <undefined>
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It sounds like none of the systems are following ANSI SQL syntax completely.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We are close to the DB2 syntax, except that we support interval and |
||
| | SET .*? #setConfiguration | ||
| | RESET #resetConfiguration | ||
| | unsupportedHiveNativeCommands .*? #failNativeCommand | ||
|
|
@@ -1190,6 +1193,7 @@ ansiNonReserved | |
| | VIEW | ||
| | VIEWS | ||
| | WINDOW | ||
| | ZONE | ||
| //--ANSI-NON-RESERVED-END | ||
| ; | ||
|
|
||
|
|
@@ -1431,6 +1435,7 @@ nonReserved | |
| | TEMPORARY | ||
| | TERMINATED | ||
| | THEN | ||
| | TIME | ||
| | TO | ||
| | TOUCH | ||
| | TRAILING | ||
|
|
@@ -1459,6 +1464,7 @@ nonReserved | |
| | WINDOW | ||
| | WITH | ||
| | YEAR | ||
| | ZONE | ||
| ; | ||
|
|
||
| // NOTE: If you add a new token in the list below, you should update the list of keywords | ||
|
|
@@ -1690,6 +1696,7 @@ TBLPROPERTIES: 'TBLPROPERTIES'; | |
| TEMPORARY: 'TEMPORARY' | 'TEMP'; | ||
| TERMINATED: 'TERMINATED'; | ||
| THEN: 'THEN'; | ||
| TIME: 'TIME'; | ||
| TO: 'TO'; | ||
| TOUCH: 'TOUCH'; | ||
| TRAILING: 'TRAILING'; | ||
|
|
@@ -1720,6 +1727,7 @@ WHERE: 'WHERE'; | |
| WINDOW: 'WINDOW'; | ||
| WITH: 'WITH'; | ||
| YEAR: 'YEAR'; | ||
| ZONE: 'ZONE'; | ||
| //--SPARK-KEYWORD-LIST-END | ||
| //============================ | ||
| // End of the keywords list | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| -- valid time zones | ||
| SET TIME ZONE 'Asia/Hong_Kong'; | ||
| SET TIME ZONE 'GMT+1'; | ||
| SET TIME ZONE INTERVAL 10 HOURS; | ||
| SET TIME ZONE INTERVAL '15:40:32' HOUR TO SECOND; | ||
| SET TIME ZONE LOCAL; | ||
|
|
||
| -- invalid time zone | ||
| SET TIME ZONE; | ||
| SET TIME ZONE 'invalid/zone'; | ||
| SET TIME ZONE INTERVAL 3 DAYS; | ||
| SET TIME ZONE INTERVAL 24 HOURS; | ||
| SET TIME ZONE INTERVAL '19:40:32' HOUR TO SECOND; | ||
| SET TIME ZONE INTERVAL 10 HOURS 'GMT+1'; | ||
| SET TIME ZONE INTERVAL 10 HOURS 1 MILLISECOND; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,135 @@ | ||
| -- Automatically generated by SQLQueryTestSuite | ||
| -- Number of queries: 12 | ||
|
|
||
|
|
||
| -- !query | ||
| SET TIME ZONE 'Asia/Hong_Kong' | ||
| -- !query schema | ||
| struct<key:string,value:string> | ||
| -- !query output | ||
| spark.sql.session.timeZone Asia/Hong_Kong | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks like a weird output for
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do we expect as output? only keep the value
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is there any reference?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
|
|
||
| -- !query | ||
| SET TIME ZONE 'GMT+1' | ||
| -- !query schema | ||
| struct<key:string,value:string> | ||
| -- !query output | ||
| spark.sql.session.timeZone GMT+1 | ||
|
|
||
|
|
||
| -- !query | ||
| SET TIME ZONE INTERVAL 10 HOURS | ||
| -- !query schema | ||
| struct<key:string,value:string> | ||
| -- !query output | ||
| spark.sql.session.timeZone +10:00 | ||
|
|
||
|
|
||
| -- !query | ||
| SET TIME ZONE INTERVAL '15:40:32' HOUR TO SECOND | ||
| -- !query schema | ||
| struct<key:string,value:string> | ||
| -- !query output | ||
| spark.sql.session.timeZone +15:40:32 | ||
|
|
||
|
|
||
| -- !query | ||
| SET TIME ZONE LOCAL | ||
| -- !query schema | ||
| struct<key:string,value:string> | ||
| -- !query output | ||
| spark.sql.session.timeZone America/Los_Angeles | ||
|
|
||
|
|
||
| -- !query | ||
| SET TIME ZONE | ||
| -- !query schema | ||
| struct<> | ||
| -- !query output | ||
| org.apache.spark.sql.catalyst.parser.ParseException | ||
|
|
||
| Invalid time zone displacement value(line 1, pos 0) | ||
|
|
||
| == SQL == | ||
| SET TIME ZONE | ||
| ^^^ | ||
|
|
||
|
|
||
| -- !query | ||
| SET TIME ZONE 'invalid/zone' | ||
| -- !query schema | ||
| struct<> | ||
| -- !query output | ||
| java.lang.IllegalArgumentException | ||
| Cannot resolve the given timezone with ZoneId.of(_, ZoneId.SHORT_IDS) | ||
|
|
||
|
|
||
| -- !query | ||
| SET TIME ZONE INTERVAL 3 DAYS | ||
| -- !query schema | ||
| struct<> | ||
| -- !query output | ||
| org.apache.spark.sql.catalyst.parser.ParseException | ||
|
|
||
| The interval value must be in the range of [-18, +18] hours with second precision(line 1, pos 14) | ||
|
|
||
| == SQL == | ||
| SET TIME ZONE INTERVAL 3 DAYS | ||
| --------------^^^ | ||
|
|
||
|
|
||
| -- !query | ||
| SET TIME ZONE INTERVAL 24 HOURS | ||
| -- !query schema | ||
| struct<> | ||
| -- !query output | ||
| org.apache.spark.sql.catalyst.parser.ParseException | ||
|
|
||
| The interval value must be in the range of [-18, +18] hours with second precision(line 1, pos 14) | ||
|
|
||
| == SQL == | ||
| SET TIME ZONE INTERVAL 24 HOURS | ||
| --------------^^^ | ||
|
|
||
|
|
||
| -- !query | ||
| SET TIME ZONE INTERVAL '19:40:32' HOUR TO SECOND | ||
| -- !query schema | ||
| struct<> | ||
| -- !query output | ||
| org.apache.spark.sql.catalyst.parser.ParseException | ||
|
|
||
| The interval value must be in the range of [-18, +18] hours with second precision(line 1, pos 14) | ||
|
|
||
| == SQL == | ||
| SET TIME ZONE INTERVAL '19:40:32' HOUR TO SECOND | ||
| --------------^^^ | ||
|
|
||
|
|
||
| -- !query | ||
| SET TIME ZONE INTERVAL 10 HOURS 'GMT+1' | ||
| -- !query schema | ||
| struct<> | ||
| -- !query output | ||
| org.apache.spark.sql.catalyst.parser.ParseException | ||
|
|
||
| Invalid time zone displacement value(line 1, pos 0) | ||
|
|
||
| == SQL == | ||
| SET TIME ZONE INTERVAL 10 HOURS 'GMT+1' | ||
| ^^^ | ||
|
|
||
|
|
||
| -- !query | ||
| SET TIME ZONE INTERVAL 10 HOURS 1 MILLISECOND | ||
| -- !query schema | ||
| struct<> | ||
| -- !query output | ||
| org.apache.spark.sql.catalyst.parser.ParseException | ||
|
|
||
| The interval value must be in the range of [-18, +18] hours with second precision(line 1, pos 14) | ||
|
|
||
| == SQL == | ||
| SET TIME ZONE INTERVAL 10 HOURS 1 MILLISECOND | ||
| --------------^^^ | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
SET TIME ZONEcommand sets the time zone of the current session.