2
votes

Does Hive support multiple CTEs inside VIEW statement? I know Hive supports CTE (HIVE-1180), but not sure if it has any limitation - for example, supporting multiple CTEs inside VIEW statement:

CREATE OR REPLACE VIEW prdviews.temp
AS WITH set1 AS (SELECT 1 AS id FROM testdb.table1), 
        set2 AS (select 2 AS id FROM testdb.table2)
SELECT * FROM set1
UNION ALL
SELECT * FROM set2;

select * from prdviews.temp;

Executing above query creates Hive view successfully. But when I run a SELECT query, it returns error. Or am I doing it wrong? The above query or any similar query returns error similar to this:

Error while compiling statement: FAILED: SemanticException Line 3:24 Table not found 'set1' in definition of VIEW temp [ WITH set1 AS (SELECT 1 AS `id` FROM `testdb`.`table1`), set2 AS (select 2 AS `id` FROM `testdb`.`table2`) SELECT `set1`.`id` FROM set1 UNION ALL SELECT `set2`.`id` FROM set2 ] used as temp at Line 1:14
1
The issue is with the UNION ALL - David דודו Markovitz
I am facing similar issue, did any one find resolution for this? - PhanidharSwarna

1 Answers

0
votes

The below is working in CDH 5x

with t1 as(select * from empinfo where empid=101),t2 as(select * from empinfo where empid=102) select * from t1 union all select * from t2;

And also the below

select * from empinfo where empid=101 union all select * from empinfo where empid=102;