Hive 变量串联 [英] Hive variable concatenation

查看:48
本文介绍了Hive 变量串联的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在将变量的值与字符串连接时遇到问题.我的脚本包含以下内容

I am facing problems in concatenating the value of a variable with a string . my script contains the below

set hivevar:tab_dt= substr(date_sub(current_date,1),1,10);

CREATE TABLE default.udr_lt_bc_${hivevar:tab_dt}
(
trans_id double 
)
ROW FORMAT DELIMITED FIELDS TERMINATED BY ",";

在上面,变量 tab_dt 以 yyyymmdd 格式正确分配了昨天的日期.但是当我尝试将此变量与静态字符串连接到表名中时,脚本失败.它不是在做串联.请提供解决方案.

in the above, the variable tab_dt gets assigned correctly with yesterdays date in the format yyyymmdd. but when i try to concatenate this variable in a table name with a static string, the script fails. it is not doing the concatenation . Kindly provide a solution.

注意:我也尝试了以下方法,但也出错

note: i tried the below too, which is erroring out too

set hivevar:tab_dt= substr(date_sub(current_date,1),1,10);
set hivevar:tab_nm1= default.udr_lt_bc_;
set hivevar:tab_name= concat(${hivevar:tab_dt},${hivevar:tab_nm1})

CREATE TABLE ${hivevar:tab_name}
(
trans_id double 
)
ROW FORMAT DELIMITED FIELDS TERMINATED BY ",";

这也会返回错误.

推荐答案

Hive 的另一种方式:

Another way in Hive:

select concat("table_",date_sub(from_unixtime(unix_timestamp(current_date,'yyyy-MM-dd'),'yyyy-MM-dd'),0));

在这里,我们可以在变量中使用上面的内容,并根据需要使用它.

Here, we can use above in a variable and use it as per our needs.

这篇关于Hive 变量串联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆