Hive: Struct

(Last Updated On: )

This tutorial will show you how to use struct. If you have no installed Hive yet please follow this tutorial.

Create Table with Struct:

  1. CREATE TABLE test_struct (
  2. columnA STRING,
  3. columnB VARCHAR(15),
  4. columnC INT,
  5. columnD TIMESTAMP,
  6. columnE DATE,
  7. columnF STRUCT<key:STRING, value:INT>
  8. )
  9. STORED AS ORC;

Insert Data:

  1. INSERT INTO test_struct
  2. SELECT '1', '2', 1, '2019-02-07 20:58:27', '2019-02-07', NAMED_STRUCT('key', 'val', 'value', 1);

Select Data:
This will give back the value of “key” and “value” in columnF.

  1. SELECT columnF.key, columnF.value
  2. FROM test_struct;