Search code examples
hivehcatalog

Change the database's table in hive or hcatalog


Is there a way to change the database's table in hive or Hcatalog?

For instance, I have the table foo in the database default, and I want to put this table in the database bar. I try this, but it doesn't work:

ALTER TABLE foo RENAME TO bar.foo

Thanks in advance


Solution

  • AFAIK there is no way in HiveQL to do this. A ticket was raised long back though. But the issue is still open.

    An alternate could be to use the EXPORT/IMPORT feature provided by Hive. With this feature we can export the data of a table to a HDFS file along with the metadata using the EXPORT command. The data is stored in JSON format. Data once exported this way could be imported back to another database (even another hive instance) using the IMPORT command.

    More on this can be found on the IMPORT/EXPORT MANUAL.

    HTH