Friday, 10 October 2014

ALTER TABLE Statement in Hive


REPLACE COLUMNS removes all existing columns and adds the new set of columns. This can be done only for tables with native SerDe (DynamicSerDe, MetadataTypedColumnsetSerDe, LazySimpleSerDe and ColumnarSerDe). Refer to SerDe section of User Guide for more information. REPLACE COLUMNS can also be used to drop columns. For example:
"ALTER TABLE test_change REPLACE COLUMNS (a int, b int);" will remove column `c' from test_change's schema. Note that this does not delete underlying data, it just changes the schema.

Note:
Hive does not currently support dropping columns from Parquet-backed tables. You will get the following error:

hive> ALTER TABLE test REPLACE COLUMNS … ;

FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. Replace columns is not supported for table test. SerDe may be incompatible.



Reference:
http://www.cloudera.com/content/cloudera/en/documentation/cloudera-impala/v1/latest/Installing-and-Using-Impala/ciiu_alter_table.html
https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL#LanguageManualDDL-AlterColumn
https://cwiki.apache.org/confluence/display/Hive/GettingStarted#GettingStarted-AlteringandDroppingTables

No comments:

Post a Comment