Janos Kovacs created HIVE-27740:
-----------------------------------

             Summary: CREATE TABLE with timestamp with timezone fails with 
SemanticException
                 Key: HIVE-27740
                 URL: https://issues.apache.org/jira/browse/HIVE-27740
             Project: Hive
          Issue Type: Sub-task
    Affects Versions: 4.0.0-beta-1
            Reporter: Janos Kovacs
            Assignee: Zoltán Rátkai


CREATE TABLE with timestamp with timezone fails with SemanticException when 
timezone is changed in a session to another valid value.

Repro code:
{noformat}
docker rm -f hive4

export HIVE_VERSION=4.0.0-beta-2-SNAPSHOT
export HS2_ENV_TZ="Europe/Budapest"
export HS2_USER_TZ=${HS2_ENV_TZ}
export HIVE_LOCAL_TZ=${HS2_ENV_TZ}

export HS2_OPTS="-Duser.timezone=$HS2_USER_TZ 
-Dhive.local.time.zone=$HIVE_LOCAL_TZ"
export HS2_OPTS="$HS2_OPTS  
-Dhive.server2.tez.initialize.default.sessions=false"
docker run -d -p 10000:10000 -p 10001:10001 -p 10002:10002 --env 
TZ=${HS2_ENV_TZ} --env SERVICE_OPTS=${HS2_OPTS} --env SERVICE_NAME=hiveserver2 
--name hive4 apache/hive:${HIVE_VERSION}

docker exec -it hive4 beeline -u 'jdbc:hive2://localhost:10000/' -e "
SELECT '\${env:TZ}' as \`env:TZ\`,
       '\${system:user.timezone}' as \`system:user.timezone\`,
       '\${hiveconf:hive.local.time.zone}' as \`hiveconf:hive.local.time.zone\`;

DROP TABLE IF EXISTS timestamptest;
CREATE TABLE timestamptest (
  ts timestamp,
  tz timestamp with local time zone DEFAULT TIMESTAMPLOCALTZ'2016-01-03 
12:26:34 America/Los_Angeles'
) STORED AS TEXTFILE;
INSERT INTO timestamptest (ts) VALUES (TIMESTAMP'2016-01-03 20:26:34');
SELECT ts, tz from timestamptest;

SET hive.local.time.zone=Europe/Berlin;

SELECT '\${env:TZ}' as \`env:TZ\`,
       '\${system:user.timezone}' as \`system:user.timezone\`,
       '\${hiveconf:hive.local.time.zone}' as \`hiveconf:hive.local.time.zone\`;

SELECT ts, tz from timestamptest;

DROP TABLE IF EXISTS timestamptest;
CREATE TABLE timestamptest (
  ts timestamp,
  tz timestamp with local time zone DEFAULT TIMESTAMPLOCALTZ'2016-01-03 
12:26:34 America/Los_Angeles'
) STORED AS TEXTFILE;
"
{noformat}
 
Querying the data works with both timezone values:
{noformat}
+------------------+-----------------------+--------------------------------+
|      env:tz      | system:user.timezone  | hiveconf:hive.local.time.zone  |
+------------------+-----------------------+--------------------------------+
| Europe/Budapest  | Europe/Budapest       | Europe/Budapest                |
+------------------+-----------------------+--------------------------------+

+------------------------+----------------------------------------+
|           ts           |                   tz                   |
+------------------------+----------------------------------------+
| 2016-01-03 20:26:34.0  | 2016-01-03 21:26:34.0 Europe/Budapest  |
+------------------------+----------------------------------------+

+------------------+-----------------------+--------------------------------+
|      env:tz      | system:user.timezone  | hiveconf:hive.local.time.zone  |
+------------------+-----------------------+--------------------------------+
| Europe/Budapest  | Europe/Budapest       | Europe/Berlin                  |
+------------------+-----------------------+--------------------------------+

+------------------------+--------------------------------------+
|           ts           |                  tz                  |
+------------------------+--------------------------------------+
| 2016-01-03 20:26:34.0  | 2016-01-03 21:26:34.0 Europe/Berlin  |
+------------------------+--------------------------------------+
{noformat}

CREATE also work with the system set timezone value but fails when changed. The 
second CREATE TABLE statement in the above example fails with:
{noformat}
Error: Error while compiling statement: FAILED: SemanticException [Error 
10326]: Invalid Constraint syntax Invalid type: timestamp with local time zone 
for default value: TIMESTAMPLOCALTZ'2016-01-03 12:26:34 America/Los_Angeles'. 
Please make sure that the type is compatible with column type: timestamp with 
local time zone (state=42000,code=10326)
{noformat}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to