title: How to create view for struct fields in hive
body: <p>STEP 1:
  I have written an UDF which will form 2 or more Struct columns like cars, bikes, buses. Also the UDF takes some info from other view called 'details'.</p>
  
  <pre><code>cars struct form is: ARRAY&lt;STRUCT&lt;name:string, mfg:string, year:int&gt;&gt;
  bikes struct form is: ARRAY&lt;STRUCT&lt;name: string, mfg:string, year: int, price: double&gt;&gt;
  buses struct form is: ARRAY&lt;STRUCT&lt;name: string, mfg:string, year: int, price: double&gt;&gt;
  </code></pre>
  
  <p>I am creating a view 'vehicles' using this UDF as below</p>
  
  <pre><code>ADD JAR s3://test/StructFV-0.1.jar;
  CREATE TEMPORARY FUNCTION TEST_STRUCT AS "com.test.TestStruct";
  
  CREATE DATABASE IF NOT EXISTS ranjith;
  USE ranjith;
  DROP VIEW IF EXISTS vehicles;
  CREATE VIEW vehicles AS 
  SELECT t.cars, t.bikes, t.buses
  FROM details d LATERAL VIEW TEST_STRUCT(d.data) t AS
  cars, bikes, buses;
  </code></pre>
  
  <p>STEP 2: 
  I want to explode each struct column into another view.
  When i try the below query, i am getting error like "The number of aliases supplied in the AS clause does not match the number of columns output by the UDTF expected"</p>
  
  <pre><code>USE ranjith;
  DROP VIEW IF EXISTS cars;
  CREATE VIEW cars AS 
  SELECT c.name as name, c.mfg as mfg, c.year as year 
  FROM vehicles v LATERAL VIEW EXPLODE (v.cars) exploded_table as c;
  </code></pre>
  
  <p>Note: If i have UDF with only cars struct, works fine. Facing issue only if the UDF contains more than one STRUCT.</p>
  
  <p>Any help?</p>