Hadoop -hivevar和-hiveconf之间有什么区别?

Hadoop -hivevar和-hiveconf之间有什么区别?,hadoop,hive,hiveql,Hadoop,Hive,Hiveql,从hive-h: --hiveconf <property=value> Use value for given property --hivevar <key=value> Variable subsitution to apply to hive commands. e.g. --hivevar A=B --hiveconf为给定属性使用值 --要应用于配置单元的hivevar变

从hive-h:

--hiveconf <property=value>   Use value for given property
--hivevar <key=value>         Variable subsitution to apply to hive
                                  commands. e.g. --hivevar A=B
--hiveconf为给定属性使用值
--要应用于配置单元的hivevar变量替代
命令。e、 g.——hivevar A=B

除了名称空间之外,没有区别
hiveconf
hivevar
是不同的名称空间
hivevar
namespace被添加到单独的配置属性名称空间和配置单元变量名称空间中。有关更多信息,请参阅

您可以参考此内容了解差异


变量有三个名称空间–hiveconf、system和env。(也可以在Hive 0.8.0及更高版本中使用define或hivevar选项在单独的名称空间中创建。)

我觉得文档中的示例不够充分,因此我试图给出一个答案

一开始只有
--hiveconf
,变量替换不存在

--hiveconf
选项允许用户从命令行进行设置,就是这样。所有配置单元配置值都存储在
hiveconf
命名空间下,即
hiveconf:mapred.reduce.tasks
。这些值允许您控制映射器和还原器的数量、是否应显示状态消息以及脚本是否应在出现错误时继续

后来。这意味着您现在可以使用
${…}
语法在查询中使用变量。但是,可以从命令行设置的变量只有在
hiveconf
命名空间下使用
--hiveconf
,因此用户将变量放在那里

将您的个人变量放在配置单元配置名称空间下可能不会破坏任何东西,但这也是不好的形式。稍后,将专门为用户变量添加
hivevar
名称空间,用户变量也可以使用
--hivevar
在命令行中定义。这意味着在配置单元配置值和用户定义变量之间有一个更清晰的分离

总而言之:
应使用
hiveconf
命名空间和
--hiveconf
设置配置单元配置值。
应使用
hivevar
命名空间和
--hivevar
定义用户变量。

hiveconf
名称空间下设置用户变量可能不会破坏任何东西,但不建议这样做。

@Llama对此进行了详细解释,并指出这两种类型的变量的访问方式不同

使用
${var name}
访问
--hivevar
变量,而
--hiveconf
在配置单元内访问
${hiveconf:var name}

e、 下面的示例访问变量并在配置单元中打印其值

hivevar:

hive --hivevar a='this is a' -e '!echo ${a};'
hive --hiveconf a='this is a' -e '!echo ${hiveconf:a};'
SET this_dt = CURRENT_DATE;
select ${hiveconf:this_dt};
set hivevar:cur_dt=current_date;
select ${hivevar:cur_dt};
输出:
这是一个

hiveconf:

hive --hivevar a='this is a' -e '!echo ${a};'
hive --hiveconf a='this is a' -e '!echo ${hiveconf:a};'
SET this_dt = CURRENT_DATE;
select ${hiveconf:this_dt};
set hivevar:cur_dt=current_date;
select ${hivevar:cur_dt};

输出:
这是一个

我们也可以在脚本开头使用它们,如下所示:

hiveconf:

hive --hivevar a='this is a' -e '!echo ${a};'
hive --hiveconf a='this is a' -e '!echo ${hiveconf:a};'
SET this_dt = CURRENT_DATE;
select ${hiveconf:this_dt};
set hivevar:cur_dt=current_date;
select ${hivevar:cur_dt};
hivevar:

hive --hivevar a='this is a' -e '!echo ${a};'
hive --hiveconf a='this is a' -e '!echo ${hiveconf:a};'
SET this_dt = CURRENT_DATE;
select ${hiveconf:this_dt};
set hivevar:cur_dt=current_date;
select ${hivevar:cur_dt};

其实我很久以前就想出来了,不过答案不错,谢谢!我想你可能有,但我决定提交另一个答案给未来的读者,以防万一您好,您能在单独的config.hql中添加hivevar并将其导入主hql脚本吗?