Hive Complex Data Types Example

Generally in hive and other all databases almost same data types like primitive data types,string data types,Date/Time data types and Miscellaneous Data Type but in hive data types there is also an another data type feature is called complex data types.This complex data types are very useful and powerful in our is Hive Complex Data Types Example in understanding way.

Generally Hive supports 4 types of complex data types

  • MAP

Hive Complex Data Types Example

hive array data type example

Hive Array behavior is same as Java Array.It is an ordered collection of elements.The all elements in the array is must be same data type.


In the above example we are using hive array data type for storing all persons age by using that hive array in a single element.We should use only one data type in array(if data type is int all elements will int,if data type is string all elements will string).

hive map data type example

Hive Map data type  is one type of Hive complex data types example It is an unordered collection of key-value pairs.Keys must be of primitive types.Values can be of any type.

if you observed the above query in map function first element is string (that means primitive data types)  and second element is any type (here we used Boolean (Miscellaneous Data Type)) . In query we used map keys terminated by syntax.

hive struct data type example

It is similar to STRUCT in C language. It is a collection of elements of different types.we can use any data type to specify this struct data type.Elements in STRUCT type are accessed using the DOT (.) notation.

Example – For a column c of type STRUCT {a INT; b INT} the a field is accessed by the expression c.a

if you observed the above query in struct function first element is string and second element is also string (There is no restrictions we can use any type of data types for struct) . In query we used collection items terminated by terminated by syntax.

hive union data type example

UNIONTYPE is collection of Heterogeneous data types.It is similar to Unions in C. At any point of time, an Union Type can hold any one (exactly one) data type from its specified data types


UNIONTYPE<int, double, array<string>, struct<a:int,b:string>>

Hive Complex Data Types Example

Hive Complex Data Types Example

Real Time Examples for Hive complex Data types



Hive Table Describe


Hive Table Query



1000001     {"fname":"mahesh","lname":"chimmiri"}     {"city":"hyd","state":"ap"}      [40,29,39]  {"happy":true}

1000002     {"fname":"ramesh","lname":"chimmili"}     {"city":"ogl","state":"ap"}      [20,39,19]  {"sad":false}
hive> select from empmahidata;

Total MapReduce jobs = 1

Launching Job 1 out of 1

Number of reduce tasks is set to 0 since there’s no reduce operator

Starting Job = job_201312230051_0004, Tracking URL = http://localhost:50030/jobdetails.jsp?jobid=job_201312230051_0004

Kill Command = /usr/lib/hadoop/bin/hadoop job  -Dmapred.job.tracker=localhost:8021 -kill job_201312230051_0004

2013-12-25 01:36:55,425 Stage-1 map = 0%,  reduce = 0%

2013-12-25 01:36:57,451 Stage-1 map = 100%,  reduce = 0%

2013-12-25 01:36:59,483 Stage-1 map = 100%,  reduce = 100%

Ended Job = job_201312230051_0004





Time taken: 8.016 seconds

by using struct data type we can access the sub element of main element  by using select from empmahidata . This is all about Hive Complex Data Types Example.Please do subscribe for more updates from us and please comment your opinion about this post and share this post


  1. Hi,

    I have some requirement like this

    I m getting below data from xml’s after conversion
    colum1, column2, colum3, colum4
    1, sai, chaitanya, [‘1′,’2′], [‘3′,’4′]

    output: I want to maintain tightly couple relationship between array’s,my output should be like below

    can you please help me
    Thanks In advance

    Sai chaitanya

  2. Pooja Rajendran says:

    How to access map values in the above example.Kindly reply.

    • Gurumurthy CL says:



      create table map_data (sub array) row format delimited fields terminated by ‘ , ‘ collection items terminated by ‘$’ map keys terminated by ‘#';

      select sub[“Physics”] from map_data;


  3. Hello,

    Is hive didn’t support Varchar data type?

    And also i’ll be having a doubt. Could you please elaborate that how to use UPDATE & DELETE in hive?

    Thanks in advance

    Best Regards,

Speak Your Mind