Specify default parameter values within a hive scr

2019-06-02 16:58发布

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?

标签: hive
3条回答
▲ chillily
2楼-- · 2019-06-02 17:28

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.

查看更多
虎瘦雄心在
3楼-- · 2019-06-02 17:31

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");

查看更多
Melony?
4楼-- · 2019-06-02 17:31

OK So take the logic away from Hive

In POSH or a cmd file

  1. Do the check
  2. Substitute if needed
  3. Call Hive

Maybe look at that as a wrapper.

Allan

查看更多
登录 后发表回答