Support Questions
Find answers, ask questions, and share your expertise

Question on HIVE touch command

Expert Contributor

We have daily jobs that loads data into HIVE from MS SQL. Small tables are TRUNCATED and LOADED everyday.

Can someone explain what the following command does ?

hive -e 'alter table $db_name.$subject touch'"

Please let me know if you need more details.

Thanks

Kumar

1 REPLY 1

TOUCH reads the metadata, and writes it back. During the process, it updates the "Last Updated Timestamp" for the respective metadata. Follows a quick example using a table called "test"

describe formatted test;

From the pool of the metadata listed checkout for transient_lastDdlTime. It will look something like below.

transient_lastDdlTime | 1519679120 

Now use touch command.

alter table test touch;

Describe the table again.

describe formatted test;

Check transient_lastDdlTime. This will be a recent timestamp compared to the older timestamp.

transient_lastDdlTime | 1519686268         // More recent to previous timestamp

Why? As mentioned, touch read the metadata and wrote it back. When it wrote it back, it updated the metadata creation timestamp.

In your use case, as you mentioned, the tables are TRUNCATED and RELOADED. Most probably that is done outside Hive. Hence the touch command has been used to update the metadata timestamp so that it is in sync with your data load operations.

Hope that helps!

; ;