Free Online Certification Courses – Learn Today. Lead Tomorrow. › Forums › Apache Hadoop › How to Delete column from Hive table?
- This topic has 2 replies, 1 voice, and was last updated 5 years, 7 months ago by DataFlair Team.
-
AuthorPosts
-
-
September 20, 2018 at 2:42 pm #5259DataFlair TeamSpectator
how should we delete column in Hive Table? and how delete work?
-
September 20, 2018 at 2:42 pm #5262DataFlair TeamSpectator
Hive allows you to change the definition for columns, add new columns, or even replace all existing columns in a table with a new set.
ADD COLUMNS lets you add new columns to the end of the existing columns but before the partition columns.
REPLACE COLUMNS removes all existing columns and adds the new set of columns. This can be done only for tables with a native SerDe (DynamicSerDe, MetadataTypedColumnsetSerDe, LazySimpleSerDe and ColumnarSerDe).REPLACE COLUMNS can also be used to drop columns. For example,
ALTER TABLE test REPLACE COLUMNS (a int, b int);
will remove column ‘c’ from test schema.You cannot drop column directly from a table using command “ALTER TABLE table_name drop col_name;”
The only way to drop column is using replace command. Lets say, I have a table TEST with id, name and case column. We want to drop id column of table TEST. So provide all those columns which you want to be the part of table in replace columns clause. Below command will drop id column from TEST table.
ALTER TABLE TEST REPLACE COLUMNS( name string, case string);
-
September 20, 2018 at 2:43 pm #5265DataFlair TeamSpectator
There is no delete column in hive. however the below commands can work.
CREATE TABLE test_change (a int, b int, c int);
ALTER TABLE test_change REPLACE COLUMNS (a int, b int);” will remove column ‘c’ from test_change’s schema.
-
-
AuthorPosts
- You must be logged in to reply to this topic.