Nickswaggy
Nickswaggy

Reputation: 1

Hive table show all fields NULL after add new columns

I have a hive table with three columns, delimited by spaces

hive (database)> describe formatted my_table;
# col_name data_type comment
field1 string 
field2 string 
field3 string
... ...
Storage Desc Params: 
input.regex (\\S+)\\s+(\\S+)\\s+(.*)

// mount dataset to table
hive (database)> ALTER TABLE lsr_staging_test SET LOCATION '/tmp/old_data.txt';
hive (database)> select * from my_table limit 2;
DataX DataX DataX
DataX DataX DataX

I want to add two new columns to the hive table schema, so I did:

// add two columns
hive (database)> alter table my_table add columns(field4 string,field5 string);
// add two more (\\S+)\\s+ for the new columns
hive (database)> alter table my_table SET SERDEPROPERTIES ("input.regex" = "(\\S+)\\s+(\\S+)\\s+(\\S+)\\s+(\\S+)\\s+(.*)");

But seems it doesn't work with the old dataset (the old data file with three columns):

hive (database)> select * from my_table limit 2;
NULL NULL NULL NULL NULL
NULL NULL NULL NULL NULL

I expected something like this:

DataX DataX DataX NULL NULL
DataX DataX DataX NULL NULL

Could someone help me understand why all the fields show NULL after adding the columns to schema? Thanks!

Upvotes: 0

Views: 92

Answers (0)

Related Questions