我正在阅读我公司的另一个团队的一些Hive脚本,并且无法理解其特定部分。有问题的部分是:where dt='${product_dt}'
,它可以在下面的代码块底部的第三行中找到。Hive语法:花括号和美元符号的用途
我从来没有见过这种语法,我也无法通过谷歌搜索找到任何东西(可能是因为我不知道使用正确的搜索条件)。任何洞察什么where
行过滤器步骤正在做什么,将不胜感激。
set hive.security.authorization.enabled=false;
add jar /opt/mobiletl/prod_workflow_dir/lib/hiveudf_hash.jar;
create temporary function hash_string as 'HashString';
drop table 00_truthset_product_email_uid_pid;
create table 00_truthset_product_email_uid_pid as
select distinct email,
concat_ws('|', hash_string(lower(email), "SHA-1"),
hash_string(lower(email), "MD5"),
hash_string(upper(email), "SHA-1"),
hash_string(upper(email), "MD5")) as hashed_email,
uid, address_id, confidencescore
from product.prod_vintages
where dt='${product_dt}'
and email is not null and email != ''
and address_id is not null and address_id != '';
我试过set product_dt = 2014-12;
,但似乎并没有工作:
hive> SELECT dt FROM enabilink.prod_vintages GROUP BY dt LIMIT 10;
. . .
dt
2014-12
2015-01
2015-02
2015-03
2015-05
2015-07
2015-10
2016-01
2016-02
2016-03
hive> set product_dt = 2014-12;
hive> SELECT email FROM product.prod_vintages WHERE dt='${product_dt}';
. . .
Total MapReduce CPU Time Spent: 2 seconds 570 msec
OK
email
Time taken: 25.801 seconds
'$ {product_dt}'是脚本中使用的变量。您可以使用! echo $ {product_dt}以打印其值。尝试使用TO_DATE('date')进行比较。 –
@AshishSingh好的,我做'show tables'并看一张表:'product_20161029'。我尝试:'set prod_dt = 20161029'然后'描述产品_ $ {prod_dt}',但什么也没有。我尝试'! echo $ {prod_dt}'并获得'$ {prod_dt}'。 – user2205916
尝试使用'dt =(from_unixtime(unix_timestamp($ {product_dt},'yyyyMMdd'),'yyyy -MM'))'作为比较 –