Hive complex data type querying

246 Views Asked by At

I am trying to query data from source table but I am unable to see the result properly.

Source table structure

c1 string,
c2 string,
c3 string,
temp1 struct
<
s1 : string,
s2 : string,
s3 : string,
temp2 : array<struct<as1 string,as2 :string>>                 
>

I have data in JSON format.

My JSON data is in the below format

{"c1":"123","c2":"XYZ","c3":"IIK",
"temp1":{"s1":"low","s2":"45","s3":"yes"},
"temp2":[{"as1":"16-05-1992","as2":"fail"}]
}

As per my table structure, I should have array(struct) inside struct. But the data I am having is not like that. I have struct separately and array(struct) separately. Now when I query this table, I get all the records for columns c1,c2,c3,s1,s2 as expected but I am not getting as1 and as2 columns instead I am getting temp2 itself as null in the output. Am I missing anything here. Should I have the data like struct<array<struct>> or is it fine to split struct and array<struct> and json serde will take care while reading

1

There are 1 best solutions below

0
On

According to your data example it should be struct and array<struct>:

c1 string,
c2 string,
c3 string,
temp1 struct
<
s1 : string,
s2 : string,
s3 : string
>,
temp2 : array<struct<as1 string,as2 :string>> 

Single JSON object should be in one line, multiline json is not supported:

{"c1":"123","c2":"XYZ","c3":"IIK","temp1":"s1":"low","s2":"45","s3":"yes"},"temp2":[{"as1":"16-05-1992","as2":"fail"}]}