Thursday, 6 August 2020

Change single / multiple columns of a table in Hive

How to change the name of column(s) of a Hive Table?

hive> describe customers;

customer_id          int                                      
customer_fname      string                                  
customer_lname      string                                  
customer_email      string                                  
customer_password    string                                  
customer_street      string                                  
customer_city        string                                  
customer_state      string                                  
customer_zipcode    string  


// Alter the single column of a table  
hive> ALTER TABLE customers change customer_id id int;
hive> ALTER TABLE customers CHANGE id customer_id int;

// Alter multiple columns in a table 
hive> use ohm;
ALTER TABLE customers REPLACE columns (id int, fname string, lname string, email string, password string, street string, city string, state string, zipcode string);

hive> describe customers;
OK
id                  int                                      
fname                string                                  
lname                string                                  
email                string                                  
password            string                                  
street              string                                  
city                string                                  
state                string                                  
zipcode              string                                  
Time taken: 0.082 seconds, Fetched: 9 row(s)

No comments:

Post a Comment

Flume - Simple Demo

// create a folder in hdfs : $ hdfs dfs -mkdir /user/flumeExa // Create a shell script which generates : Hadoop in real world <n>...