How do you insert data into complex data type "Struct" in Hive How do you insert data into complex data type "Struct" in Hive hadoop hadoop

How do you insert data into complex data type "Struct" in Hive


your sql error. you should use sql:

INSERT INTO TABLE struct_test        SELECT NAMED_STRUCT('houseno','123','streetname','GoldStreet', 'town','London', 'postcode','W1a9JF') AS address            FROM dummy_table LIMIT 1;


You can not insert complex data type directly in Hive.For inserting structs you have function named_struct. You need to create a dummy table with data that you want to be inserted in Structs column of desired table.Like in your case create a dummy table

CREATE TABLE DUMMY ( houseno:    STRING           ,streetname: STRING           ,town:       STRING           ,postcode:   STRING);

Then to insert in desired table do

INSERT INTO struct_test SELECT named_struct('houseno',houseno,'streetname'                  ,streetname,'town',town,'postcode',postcode) from dummy;


No need to create any dummy table : just use command :

insert into struct_testselect named_struct("houseno","house_number","streetname","xxxy","town","town_name","postcode","postcode_name");