1.Hive配置属性
(1)命令行方式
Hive配置属性存储于 hiveconf 命名空间中,该命名空间中的属性是可读写的。在查询语句中插入 '${hiveconf:变量名}',就可以通过 hive -hiveconf来替换变量。例如,查询语句和执行方式如下:
[root]$cat test.sql #查看该文件 SELECT * FROM ${hiveconf:tablename} limit ${hiveconf:var_rows}; [root]$hive -hiveconf tablename='t1' -hiveconf var_rows=10 -f test.sql 或者 #!/bin/bash tablename="student" limitcount="8" hive -S -e "use test; select * from ${tablename} limit ${limitcount};"
需要注意的是:
- 如果有多个变量,每个变量前都要有参数 -hiveconf
- 变量赋值等号左右不能有空格(例如var_rows=10不能有空格)
(2)hql脚本方式