What are the consequences of adding a column to an existing HIVE table?
Suppose that a couple hundred Gigs after starting to use HIVE I want to add a column. From the various articles & pages I hav开发者_如何学编程e seen, I cannot understand the consequences in terms of
- storage space required (double ?)
- blocking (can I still read the table in other processes) ?
- time (is it quick or as slow as a MysqL change ?)
- underlying storage (do I need to change all the underlying files ? How can it be done using RCFile ?)
Bonus to whoever can answer the same question on structs in a HIVE column.
If you add a column to a hive table, only the underlying metastore is updated.
- The required storage space is not increased as long as you do not add data
- The change can be made while other processes are accessing the table
- The change is very quick (only the underlying metastore is updated)
- You do not have to change the underlying files. Existing records have the value null for the new column
I hope this helps.
ALTER TABLE commands modifies the METADATA only. The underlying data remains untouched. However, it is user's responsibility to ensure that the any alteration does not break the data consistency.
Also any changes to METADATA is applied to the metastore - which is most typically MySQL - in which case the response time is comparable.
Altering the definition will only modify how the files are read, not the contents of the underlying files.
If your files were tab delimited text with 3 columns, you could create a table that references those files with a scheme like new_table(line STRING) that would read the entire line without parsing out columns based upon the tab characters.
When you add a column, since there are no more delimiters in the record, it will default to NULL, as Helmut mentioned.
精彩评论