When attempting to run an HQL script with the following logic, I receive the error:
ParseException line 4:0 cannot recognize input near 'CASE' 'WHEN' 'mytable' in serde properties specification
Script Logic
INSERT OVERWRITE DIRECTORY '/example/path'
ROW FORMAT DELIMITED
FIELDS TERMINATED BY ','
CASE WHEN ${hiveconf:tbl_name}='mytable'
THEN SELECT * FROM ${hiveconf:tbl_name} LEFT OUTER JOIN ...;
WHEN ${hiveconf:tbl_name}='mytable2'
THEN SELECT * FROM ${hiveconf:tbl_name} LEFT OUTER JOIN ...;
ELSE THEN
END
How can I correctly assign a select statement for the INSERT OVERWRITE DIRECTORY to use based on the value of the tbl_name parameter which I am passing in?
Update 1: When modifying as:
SELECT CASE WHEN ${hiveconf:tbl_name}='mytable'
THEN * FROM WHEN ${hiveconf:tbl_name}='mytable'
WHEN ${hiveconf:tbl_name}='mytable2'
THEN * FROM ${hiveconf:tbl_name} LEFT OUTER JOIN ...;
ELSE THEN
END
It errors with:
FAILED: ParseException line 9:9 cannot recognize input near '*' 'FROM' 'mytable' in expression specification
Update 2: When modifying as:
SELECT * CASE WHEN ${hiveconf:tbl_name}='mytable'
THEN FROM WHEN ${hiveconf:tbl_name}='mytable'
WHEN ${hiveconf:tbl_name}='mytable2'
THEN FROM ${hiveconf:tbl_name} LEFT OUTER JOIN ...;
ELSE THEN
END
It errors with:
FAILED: ParseException line 8:9 Failed to recognize predicate 'CASE'. Failed rule: 'regularBody' in statement
Quick solution is to use UNION ALL+WHERE. Like this:
Add your joins to each select.