Complex Datatypes in Hive

Complex Datatypes in Hive

This article takes you through three different complex data types in Hive, which are involved in the table creation.?These complex datatypes are built on primitive datatypes like numeric, date, string etc. Here the example that I have taken is of simple dataset that has information of food ordered.

  • Struct: It is similar to C struct or an object where fields are accessed using the "dot" notation. It groups several related variables into one place. Each variable in the structure is known as a?member?of the structure. It can contain many different data types (int, float, char, etc.) .
  • Map: It contains the key-value tuples where the fields are accessed using array notation. You can use key to get corresponding value.
  • Array: It is a collection of similar type of values that are indexable using zero-based integers. Ex: you have to save shoe brands we can create a array which will have all the brand names in it . brand array<string> which will have all brands name in it.

Dataset used:

Dataset used
Data related to customer order

Loading dataset into Hadoop:

No alt text provided for this image

Creating table in hive:

No alt text provided for this image

Load dataset into hive table:

No alt text provided for this image

Table after loading data:

No alt text provided for this image

Query to get table no and the respective discount given to the customer(where discount is the key in the map price):

No alt text provided for this image
No alt text provided for this image

Query to get the 2nd item ordered which is stored as array element in items_orderd:

No alt text provided for this image
No alt text provided for this image

I hope this helped you understand what the complicated datatypes in Hive are. Thanks for your time.

要查看或添加评论,请登录

社区洞察

其他会员也浏览了