hive使用变量

使用set设置变量

hive> set name=lucy; 
hive> set name;
name=lucy
hive> select * from employee where name='${hiveconf:name}';
Total jobs = 1
Launching Job 1 out of 1
Number of reduce tasks is set to 0 since there's no reduce operator
Starting Job = job_1471442913162_0001, Tracking URL = http://ubuntu:8088/proxy/application_1471442913162_0001/
Kill Command = /app/bigdata/hadoop-2.7.2/bin/hadoop job  -kill job_1471442913162_0001
Hadoop job information for Stage-1: number of mappers: 1; number of reducers: 0
2016-08-18 19:25:50,915 Stage-1 map = 0%,  reduce = 0%
2016-08-18 19:26:00,758 Stage-1 map = 100%,  reduce = 0%, Cumulative CPU 1.64 sec
MapReduce Total cumulative CPU time: 1 seconds 640 msec
Ended Job = job_1471442913162_0001
MapReduce Jobs Launched: 
Job 0: Map: 1   Cumulative CPU: 1.64 sec   HDFS Read: 374 HDFS Write: 90 SUCCESS
Total MapReduce CPU Time Spent: 1 seconds 640 msec
OK
lucy    11000.0 ["tom","jack","dave","kate"]    {"tom":1200.0,"jack":1560.0}    {"street":"beijing","city":"changanjie","state":"xichengqu","zip":10000}
Time taken: 28.615 seconds, Fetched: 1 row(s)

使用系统变量

root@ubuntu:~# env
XDG_SESSION_ID=13
TERM=xterm
SHELL=/bin/bash
……
HOME=/root
LANGUAGE=en_US:
LOGNAME=root
……

employee有两条数据,打印两条

hive> select '${env:HOME}' from employee;
Total jobs = 1
Launching Job 1 out of 1
Number of reduce tasks is set to 0 since there's no reduce operator
Starting Job = job_1471442913162_0002, Tracking URL = http://ubuntu:8088/proxy/application_1471442913162_0002/
Kill Command = /app/bigdata/hadoop-2.7.2/bin/hadoop job  -kill job_1471442913162_0002
Hadoop job information for Stage-1: number of mappers: 1; number of reducers: 0
2016-08-18 19:30:19,926 Stage-1 map = 0%,  reduce = 0%
2016-08-18 19:30:29,449 Stage-1 map = 100%,  reduce = 0%, Cumulative CPU 1.2 sec
MapReduce Total cumulative CPU time: 1 seconds 200 msec
Ended Job = job_1471442913162_0002
MapReduce Jobs Launched: 
Job 0: Map: 1   Cumulative CPU: 1.2 sec   HDFS Read: 374 HDFS Write: 12 SUCCESS
Total MapReduce CPU Time Spent: 1 seconds 200 msec
OK
/root
/root
Time taken: 24.098 seconds, Fetched: 2 row(s)

你可能感兴趣的:(#,hive)