我正在閱讀我公司的另一個團隊的一些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'))'作爲比較 –