Support Questions

Find answers, ask questions, and share your expertise

Can we change default hive/hbase timestamp from UTC to other timezone ?

avatar
New Contributor

Hadoop components are using default timestamp as UTC. Is there any way to change the default time zone from UTC.
Now only seeing option to do the shifting using  

1 ACCEPTED SOLUTION

avatar
Master Collaborator

Hi,

Hiveserver2 runs as a java process, When running timestamp-related UDF functions in Hive, the default behavior is to use the system's timezone information to convert timestamp values. PFB

 

INFO  : Executing command(queryId=hive_20220215131716_33c6c90b-207a-43fe-9bcf-4a52cd04de3e): SELECT current_timestamp()
INFO  : Completed executing command(queryId=hive_20220215131716_33c6c90b-207a-43fe-9bcf-4a52cd04de3e); Time taken: 0.092 seconds
INFO  : OK
+--------------------------+
|           _c0            |
+--------------------------+
| 2022-02-15 13:17:16.204  |
+--------------------------+
1 row selected (2.413 seconds)


[hive@c2757-node3 ~]$ date
Tue Feb 15 13:17:26 IST 2022
[hive@c2757-node3 ~]$ timedatectl | grep "Time zone"
       Time zone: Asia/Kolkata (IST, +0530)

 

To make Hive return a specific timezone with the timestamp function. please follow the steps below:

1. Go to the Cloudera Manager home page > Hive > Configuration
Under "Client Java Configuration Options", append " -Duser.timezone=UTC" in the text string (be mindful of the leading space in front, if you append to the end of existing options).
2 . Under "Java Configuration Options for HiveServer2", append the same thing to the end of the text string " -Duser.timezone=UTC".
3 . Save the configuration, then restart any HiveServer2 instances, and select Actions -> "Deploy Client Configuration" through Cloudera Manager.

To confirm the new configuration is working, see below test outputs:

Before the change (system's default timezone is IST):

 

INFO  : Executing command(queryId=hive_20220215131716_33c6c90b-207a-43fe-9bcf-4a52cd04de3e): SELECT current_timestamp()
INFO  : Completed executing command(queryId=hive_20220215131716_33c6c90b-207a-43fe-9bcf-4a52cd04de3e); Time taken: 0.092 seconds
INFO  : OK
+--------------------------+
|           _c0            |
+--------------------------+
| 2022-02-15 13:17:16.204  |
+--------------------------+
1 row selected (2.413 seconds)


[hive@c2757-node3 ~]$ date
Tue Feb 15 13:17:26 IST 2022
[hive@c2757-node3 ~]$ timedatectl | grep "Time zone"
       Time zone: Asia/Kolkata (IST, +0530)


After the change to UTC,

[hive@c2757-node3 ~]$ timedatectl | grep "Time zone"
       Time zone: Asia/Kolkata (IST, +0530)
[hive@c2757-node3 ~]$ date
Tue Feb 15 13:28:05 IST 2022

INFO  : Executing command(queryId=hive_20220215075824_6a58bdcb-b1b6-470d-9202-26ccfc60f521): SELECT current_timestamp()
INFO  : Completed executing command(queryId=hive_20220215075824_6a58bdcb-b1b6-470d-9202-26ccfc60f521); Time taken: 0.079 seconds
INFO  : OK
+--------------------------+
|           _c0            |
+--------------------------+
| 2022-02-15 07:58:24.785  |
+--------------------------+
1 row selected (2.24 seconds)


Like this, you can mention hive to use other timezones.



View solution in original post

2 REPLIES 2

avatar
Master Collaborator

Hi,

Hiveserver2 runs as a java process, When running timestamp-related UDF functions in Hive, the default behavior is to use the system's timezone information to convert timestamp values. PFB

 

INFO  : Executing command(queryId=hive_20220215131716_33c6c90b-207a-43fe-9bcf-4a52cd04de3e): SELECT current_timestamp()
INFO  : Completed executing command(queryId=hive_20220215131716_33c6c90b-207a-43fe-9bcf-4a52cd04de3e); Time taken: 0.092 seconds
INFO  : OK
+--------------------------+
|           _c0            |
+--------------------------+
| 2022-02-15 13:17:16.204  |
+--------------------------+
1 row selected (2.413 seconds)


[hive@c2757-node3 ~]$ date
Tue Feb 15 13:17:26 IST 2022
[hive@c2757-node3 ~]$ timedatectl | grep "Time zone"
       Time zone: Asia/Kolkata (IST, +0530)

 

To make Hive return a specific timezone with the timestamp function. please follow the steps below:

1. Go to the Cloudera Manager home page > Hive > Configuration
Under "Client Java Configuration Options", append " -Duser.timezone=UTC" in the text string (be mindful of the leading space in front, if you append to the end of existing options).
2 . Under "Java Configuration Options for HiveServer2", append the same thing to the end of the text string " -Duser.timezone=UTC".
3 . Save the configuration, then restart any HiveServer2 instances, and select Actions -> "Deploy Client Configuration" through Cloudera Manager.

To confirm the new configuration is working, see below test outputs:

Before the change (system's default timezone is IST):

 

INFO  : Executing command(queryId=hive_20220215131716_33c6c90b-207a-43fe-9bcf-4a52cd04de3e): SELECT current_timestamp()
INFO  : Completed executing command(queryId=hive_20220215131716_33c6c90b-207a-43fe-9bcf-4a52cd04de3e); Time taken: 0.092 seconds
INFO  : OK
+--------------------------+
|           _c0            |
+--------------------------+
| 2022-02-15 13:17:16.204  |
+--------------------------+
1 row selected (2.413 seconds)


[hive@c2757-node3 ~]$ date
Tue Feb 15 13:17:26 IST 2022
[hive@c2757-node3 ~]$ timedatectl | grep "Time zone"
       Time zone: Asia/Kolkata (IST, +0530)


After the change to UTC,

[hive@c2757-node3 ~]$ timedatectl | grep "Time zone"
       Time zone: Asia/Kolkata (IST, +0530)
[hive@c2757-node3 ~]$ date
Tue Feb 15 13:28:05 IST 2022

INFO  : Executing command(queryId=hive_20220215075824_6a58bdcb-b1b6-470d-9202-26ccfc60f521): SELECT current_timestamp()
INFO  : Completed executing command(queryId=hive_20220215075824_6a58bdcb-b1b6-470d-9202-26ccfc60f521); Time taken: 0.079 seconds
INFO  : OK
+--------------------------+
|           _c0            |
+--------------------------+
| 2022-02-15 07:58:24.785  |
+--------------------------+
1 row selected (2.24 seconds)


Like this, you can mention hive to use other timezones.



avatar
Super Collaborator

Hello @nikrahu 

 

We believe the Post by @ggangadharan answer your Queries. As such, We shall mark the Post as Resolved. If you have any concerns, Feel free to engage Cloudera Community via a Post.

 

Thanks @ggangadharan for the detailed Examples !!! 

 

Regards, Smarak