DBA Hub

📋Steps in this guide1/1

Hive Variable | Set Hive Variable | HiveConf,Hivevar in hive

Hive stores variables in four different namespaces, namespace is a way to separate variables.

oracle configurationintermediate
by OracleDba
15 views
1

Overview

Hive Variable | Set Hive Variable | HiveConf,Hivevar in hive Hive stores variables in four different namespaces, namespace is a way to separate variables. - hiveconf - hivevar - system, and - env.

Code/Command (click line numbers to comment):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
select region ,city from temperature where region='Africa' and city='Lusaka' limit 10;

set regionname;
regionname='Africa'

set cityname;
cityname='Lusaka'

set table;
table=temperature

select region ,city from ${hiveconf:table} where region=${hiveconf:regionname} and city=${hiveconf:cityname} limit 10;

SET hivevar:table=temperature;
select * from ${hivevar:table} limit 10;

or

SELECT * FROM ${table}

SELECT "${env:HIVE_HOME}";
OK
/home/hdoop/apache-hive-3.1.1-bin
Time taken: 2.469 seconds, Fetched: 1 row(s)

SELECT "${system:user.name}";
OK
hdoop
Time taken: 0.193 seconds, Fetched: 1 row(s)

hdoop@hadoop:~$ hive --hivevar table=temperature

hive>
    > select * from bucket.${table} limit 10;
OK
Zambia  Lusaka  1       1       1995    73      Africa
Zambia  Lusaka  1       2       1995    70      Africa
Zambia  Lusaka  1       3       1995    72      Africa
Zambia  Lusaka  1       4       1995    76      Africa
Zambia  Lusaka  1       5       1995    76      Africa
Zambia  Lusaka  1       6       1995    74      Africa
Zambia  Lusaka  1       7       1995    76      Africa
Zambia  Lusaka  1       8       1995    78      Africa
Zambia  Lusaka  1       9       1995    77      Africa
Zambia  Lusaka  1       10      1995    77      Africa
Time taken: 1.998 seconds, Fetched: 10 row(s)

hdoop@hadoop:~$ hive --hivevar table=temperature -f demo.hql

Africa  Lusaka
Africa  Lusaka
Africa  Lusaka
Africa  Lusaka
Africa  Lusaka
Africa  Lusaka
Africa  Lusaka
Africa  Lusaka
Africa  Lusaka
Africa  Lusaka
Time taken: 2.955 seconds, Fetched: 10 row(s)

hdoop@hadoop:~$ cat demo.hql
set regionname='Africa';
set cityname='Lusaka';
use bucket;
select region ,city from ${table}  where region=${hiveconf:regionname} and city=${hiveconf:cityname} limit 10;

Comments (0)

Please to add comments

No comments yet. Be the first to comment!