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'.
cars struct form is: ARRAY<STRUCT<name:string, mfg:string, year:int>>
bikes struct form is: ARRAY<STRUCT<name: string, mfg:string, year: int, price: double>>
buses struct form is: ARRAY<STRUCT<name: string, mfg:string, year: int, price: double>>
I am creating a view 'vehicles' using this UDF as below
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;
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"
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;
Note: If i have UDF with only cars struct, works fine. Facing issue only if the UDF contains more than one STRUCT.
Any help?