[Hadoop]Hive r0.9.0中文文档(四)之Hive变量的使用
例子:
$ a=b
$ hive -e " describe $a "
如果你hive数据库中没有b这个表,则会提示Table b does not exist
hive的变量设置可以放在hiveconf中,使变量赋值与查询合并为一句话:
例子:
$ bin/hive -hiveconf a=b -e 'set a; set hiveconf:a; \
create table if not exists b (col int); describe ${hiveconf:a}'
Results in:
Hive history file=/tmp/edward/hive_job_log_edward_201011240906_1463048967.txt
a=b
hiveconf:a=b
OK
Time taken: 5.913 seconds
OK
col int
Time taken: 0.754 seconds
二、hive变量使用
hive的变量有3个作用空间hiveconf,system,env。hiveconf就像平时一样设置:
set x=myvalue
X变量会被这样调用:
${hiveconf:x}
Annotated examples of usage from the test case
ql/src/test/queries/clientpositive/set_processor_namespaces.q
set zzz=5;
-- sets zzz=5
set zzz;
set system:xxx=5;
set system:xxx;
-- sets a system property xxx to 5
set system:yyy=${system:xxx};
set system:yyy;
-- sets yyy with value of xxx
set go=${hiveconf:zzz};
set go;
-- sets go base on value on zzz
set hive.variable.substitute=false;
set raw=${hiveconf:zzz};
set raw;
-- disable substitution set a value to the literal
set hive.variable.substitute=true;
EXPLAIN SELECT * FROM src where key=${hiveconf:zzz};
SELECT * FROM src where key=${hiveconf:zzz};
--use a variable in a query
set a=1;
set b=a;
set c=${hiveconf:${hiveconf:b}};
set c;
--uses nested variables.
set jar=../lib/derby.jar;
add file ${hiveconf:jar};
list file;
delete file ${hiveconf:jar};
list file;
三、Disabling
Variable substitution is on by default. If this causes an issue with an already existing script disable it.
set hive.variable.substitute=false;
set hive.variable.substitute=false;

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
-
上一篇
[Hadoop]Sqoop 1.4.2中文文档(一)之数据导入
一、Sqoop Help $ sqoop help usage: sqoop COMMAND [ARGS] Available commands: codegen Generate code to interact with database records create-hive-table Import a table definition into Hive eval Evaluate a SQL statement and display the results export Export an HDFS directory to a database table help List available commands import Import a table from a database to HDFS import-all-tables Import tables from a database to HDFS list-databases List available databases on a server list-tables List available ...
-
下一篇
[Hadoop]Hive r0.9.0中文文档(三)之Hive相关命令
一、Hive命令选项 Usage: Usage: hive [-hiveconf x=y]* [<-i filename>]* [<-f filename>|<-e query-string>] [-S] -i <filename> Initialization Sql from file (executed automatically and silently before any other commands) -e 'quoted query string' Sql from command line -f <filename> Sql from file -S Silent mode in interactive shell where only data is emitted -hiveconf x=y Use this to set hive/hadoop configuration variables. -e and -f cannot be specified together. In the absence...
相关文章
文章评论
共有0条评论来说两句吧...
文章二维码
点击排行
推荐阅读
最新文章
- CentOS8,CentOS7,CentOS6编译安装Redis5.0.7
- Docker使用Oracle官方镜像安装(12C,18C,19C)
- SpringBoot2全家桶,快速入门学习开发网站教程
- Springboot2将连接池hikari替换为druid,体验最强大的数据库连接池
- SpringBoot2编写第一个Controller,响应你的http请求并返回结果
- SpringBoot2整合Redis,开启缓存,提高访问速度
- MySQL8.0.19开启GTID主从同步CentOS8
- SpringBoot2更换Tomcat为Jetty,小型站点的福音
- CentOS7,8上快速安装Gitea,搭建Git服务器
- Dcoker安装(在线仓库),最新的服务器搭配容器使用