Hi, I am writing an application that insert data into Hive and it depends on the order of columns in table so I have to rearrange my columns to make work around that but I have difficulty of doing that. Could you please help?
Here is my problem: I have table 'tbl' which is created by using this statement: CREATE EXTERNAL TABLE tbl (col1 int, col3 string) PARTITIONED BY (dt string) STORED AS PARQUET LOCATION '/wh/db/tb'. Now I want to add new column 'col2' with type int to that table and I want to put it after 'col1' and before 'col3' so I use these two statements: ALTER TABLE tbl ADD COLUMNS (col2 int); ALTER TABLE tbl CHANGE col2 col2 int AFTER col1; With Hive 1.2.1, these two statements are executed successfully but I got type cast exception when I query data back. With Hive 2.x, The second alter statement failed with exception: 'Unable to alter table. The following columns have types incompatible with the existing columns in their respective positions' I could work around this by drop old table and then create a new table with new schema but this requires me to to run MSCK to update metadata for that table and this process could be very slow when I have a lot of data and a lot of partition so I am looking for a better one. Please help! Thanks -Binh