What is an efficient way to check if a Spark DataFrame is empty?
December 29, 2021What is the difference between static partitioning and dynamic partitioning in Hive?
January 12, 2022Let’s see how to move a Hive table from one database to another in action.
We are currently inside a database named hirw. Let’s list the table under hirw.
0: jdbc:hive2://ms2.hirw.com:2181,wk1.hirw.co> show tables; +-----------+--+ | tab_name | +-----------+--+ | employee | +-----------+--+
We got one table named employee under database hirw. Let’s create a new database named hirw_2
0: jdbc:hive2://ms2.hirw.com:2181,wk1.hirw.co> create database hirw_2; No rows affected (0.275 seconds)
Move table from hirw database to hirw_2 database
Hive offers a convenient alter table..rename command to move a Hive table from one database to another.
0: jdbc:hive2://ms2.hirw.com:2181,wk1.hirw.co> alter table employee rename to hirw_2.employee; No rows affected (0.649 seconds)
We don’t see the employee table anymore when we now list the tables under hirw.
0: jdbc:hive2://ms2.hirw.com:2181,wk1.hirw.co> show tables; +-----------+--+ | tab_name | +-----------+--+ +-----------+--+ No rows selected (0.287 seconds)
Let’s switch to hirw_2 database and list the tables again. There you go, employee table is under hirw_2 which is exactly what we wanted.
0: jdbc:hive2://ms2.hirw.com:2181,wk1.hirw.co> use hirw_2 0: jdbc:hive2://ms2.hirw.com:2181,wk1.hirw.co> show tables; +-----------+--+ | tab_name | +-----------+--+ | employee | +-----------+--+