Hive_ modify the table

Rename Table

1. grammar

ALTER TABLE table_name RENAME TO new_table_name

2. Practical operation case

hive (default)> alter table dept_partition2 rename to dept_partition3;

Add, modify and delete the partition table

See the basic operation of the partition table.

Add / modify / replace column information

1. grammar

  Update Column

ALTER TABLE table_name CHANGE [COLUMN] col_old_name col_new_name column_type [COMMENT col_comment] [FIRST|AFTER column_name]

  Additions and substitutions column

ALTER TABLE table_name ADD|REPLACE COLUMNS (col_name data_type [COMMENT col_comment], ...) 

NOTE: ADD is representative of a new field, all fields in the position behind the column (partition before the column), the REPLACE is the substitution table showing all fields.

2. Practical operation case

(1) lookup table structure

hive> desc dept_partition;

(2) add columns

hive (default)> alter table dept_partition add columns(deptdesc string);

(3) look-up table structure

hive> desc dept_partition;

(4) Update Column

hive (default)> alter table dept_partition change column deptdesc desc int;

(5) look-up table structure

hive> desc dept_partition;

(6) Replace Column

hive (default)> alter table dept_partition replace columns(deptno string, dname
 string, loc string);

(7) lookup table structure

hive> desc dept_partition;

 

Guess you like

Origin www.cnblogs.com/Tunan-Ki/p/11795816.html