I am aware that it is possible to specify parameters for a hive query/script like so:
>hive -e "USE uk_pers_dev;set hive.cli.print.header=true;CREATE TABLE IF NOT EXISTS ${hiveconf:tablename} (mycol int);SELECT * FROM ${hiveconf:tablename};" -hiveconf tablename=mytable;
However what I would like to do is specify a default parameter value within my hive script that should be used in case no value is passed from the command-line. Is that possible?
JT
Could you use
SET myvar = "Hello World"
inside your hive script do
SET myvar = COALESCE(${hiveconf:myvar},"Default");
SELECT * FROM MyTable WHERE MyColumn = ${hiveconf:myvar};
OR
SELECT * FROM MyTable WHERE MyColumn = COALESCE(${hiveconf:myvar},"Default");
OK I have a table called airports
name: string
country: string
area_code int
in HIVE I do
SET mycol = name;
SELECT ${hiveconf:mycol} from airports;
works for me.
OK So take the logic away from Hive
In POSH or a cmd file
- Do the check
- Substitute if needed
- Call Hive
Maybe look at that as a wrapper.
Allan