Alter Table
Most table properties can be altered with Alter Table statements, which change metadata about the table but not the data itself. These statements can be used to fix mistakes in schema, move partition locations and so on.
1. Renamign a Table: hive> alter table log_messages rename to logmsgs;
2. Adding, Modifying, and Dropping a Table Partition
hive> alter table log_messages add if not exists
> partition(year = 2013,month = 1,day = 1) location '/logs/2013/01/01'
> partition(year = 2013,month = 1,day = 2) location '/logs/2013/01/02';
hive> alter table log_messages partition(year = 2013, month = 2, day = 2)
> set location '/hive/ourbucket/logs/2013/02/02';
hive> alter table log_messages drop if exists partition(year = 2013, month = 2, day = 2);
For managed tables, the data for the partition is deleted, along with the metadata, even if the partition was created using alter table ... add partition. For external tables, the data is not deleted.
hive> alter table log_messages
> change column hms hours_minutes_seconds int
> comment 'hour minute second description'
> after(first) description;
hive> alter table log_messages add columns(
> app_name string comment 'the name of Application',
> session_id long comment 'the current session id');
The following example removes all the existing columns and replaces them with the new columns specified:
hive> alter table log_messages replace columns(
> hours_mins_secs int comment '......',
> severity string comment '......',
> message string comment '......');
Alter Table Properties:
hive> alter table log_messages set tblproperties(
> 'notes' = '.......');
Alter Storage Properties
Miscellaneous Alter Table Statements