0

I have two columns Id and Name in Hive table, and I want to delete the Name column. I have used following command:

ALTER TABLE TableName REPLACE COLUMNS(id string);

The result was that the Name column values were assigned to the Id column.

How can I drop a specific column of the table and is there any other command in Hive to achieve my goal?

SiHa
  • 7,830
  • 13
  • 34
  • 43
Anand K
  • 1
  • 1
  • 1
  • 2
    [same Q](http://stackoverflow.com/questions/34198114/alter-hive-table-add-or-drop-column) You can get help from this Q and Answer – MD Ashik Nov 01 '16 at 12:37

2 Answers2

0

In addition to the existing answers to the question : Alter hive table add or drop column

As per Hive documentation,

REPLACE COLUMNS removes all existing columns and adds the new set of columns.

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.

Community
  • 1
  • 1
Dev
  • 13,492
  • 19
  • 81
  • 174
0

The query you are using is right. But this will modify only schema i.e, the metastore. This will not modify anything on data side.

So, before you are dropping the column you should make sure that you hav correct data file.

In your case the data file should not contain name values.

If you don't want to modify the file then create another table with only specific column that you need.

Create table tablename as select id from already_existing_table

let me know if this helps.

Sathiyan S
  • 1,013
  • 6
  • 13