数据参数在Hive

时间:2016-08-13 04:46:28

标签: hive

我将数据参数传递给hive脚本,但它无效。

SET yrmonth=concat(substr(to_date(${hiveconf:runningdate}),1,4),substr(to_date(${hiveconf:runningdate}),6,2));
SET fom=TRUNC(${hiveconf:runningdate},'MONTH');
SET lom=LAST_DAY(${hiveconf:runningdate});

USE cust_db;

SELECT saleid,podid,pname
    FROM product 
    WHERE productln_yrmo=${hiveconf:yrmonth};

- productln_yrmo是int column

SELECT cid,cname,cloc
    FROM customer 
    WHERE customer_createddt >='${hiveconf:fom}' 
    AND customer_createddt <='${hiveconf:lom}'
    AND cloc = 'AUS';

- customer_createddt是日期列

hive -hiveconf runningdate='2016-05-18' -f cust.hql

1 个答案:

答案 0 :(得分:0)

从您的查询中,'customer_createddt'似乎是DATE类型,因为您已使用'&lt; ='和'&gt; ='运算符来获取'fom'和'lom'之间的值范围。我想日期范围的词典比较工作得很好。但是,不确定何时使用'customer_createddt'列上的分区创建表DDL 所以请到目前为止尝试一下铸造字符串(也请在表格DDL上发布以获得更清晰的信息)

SELECT cid,cname,cloc
    FROM customer 
    WHERE customer_createddt >=CAST(${hiveconf:fom} AS DATE) 
    AND customer_createddt <=CAST(${hiveconf:lom} AS DATE)
    AND cloc = 'AUS';