Adding data to STRUCT Type

Hive supports 2 categories of data type ; Simple & Complex. In this post, we will see how to add data to STRUCT Type(Complex type). STRUCT type is populated using the built-in function named_struct()

Let us see how we can load the data into marks field which is of type STRUCT
hive> desc science;
name                 string
class                string
marks                struct<bny:string,zlgy:string>

hive> desc subjects;
OK
name                 string
class                string
history              string
geography            string
botany               string
zoology              string
algebra              string
trigonometry         string
tamil                string
english              string

hive> select * from subjects;
name1 XI 60 65 70 75 80 85 90 95
name2 XI 61 66 71 76 81 86 91 96

hive> insert overwrite table science
    > select name, class, named_struct('bny', botany, 'zlgy', zoology)
    > from subjects;
hive> select * from science;
name1 XI {"bny":"70","zlgy":"75"}
name2 XI {"bny":"71","zlgy":"76"}


No comments:

Post a Comment