-
Notifications
You must be signed in to change notification settings - Fork 0
/
Question_2_Hive.txt
72 lines (52 loc) · 3.08 KB
/
Question_2_Hive.txt
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
67
68
69
70
71
72
Q2
Sub-part 1:
Hive queries:
set hive.cli.print.current.db=true;
create database moduleEnd;
create table customer
(cust_id int,
firstName string,
lastName string,
age int,
profession string) row format delimited fields terminated by ',' stored as textfile
location 'user/bigcdac432550/exam/hive/Q1';
load data local inpath 'custs.txt' overwrite into table customer;
select profession, count(cust_id) from customer group by profession;
--------------------------------------------------------------------------------------------------------
Sub-part 2:
Hive Queries:
create table txn
(txn_id int,
txn_date string,
cust_id int,
amount double,
category string,
product string,
city string,
state string,
spendby string) row format delimited fields terminated by ',' stored as textfile
location '/user/bigcdac432550/exam/hive/Q2';
load data local inpath 'custs.txt' overwrite into table customer;
select product, sum(amount) as sales from txn group by product order by sales desc limit 10;
---------------------------------------------------------------------------------------------------------
Sub-part 3:
Hive Queries:
set hive.exec.dynamic.partition.mode=nonstrict;
set hive.exec.dynamic.partition=true;
create table txn_partition
(txn_id int,
txn_date string,
cust_id int,
amount double,
product string,
city string,
state string,
spendby string)
partitioned by (category string)
row format delimited fields terminated by ',' stored as textfile
location '/user/bigcdac432550/exam/hive/txn_partition';
insert overwrite table txn_partition partition(category)
select txn.txn_id,txn.txn_date,txn.cust_id,txn.amount,
txn.product,txn.city,txn.state,txn.spendby,txn.category from txn distribute by category;
show partitions txn_partition;
----------------------------------------------------------------------------------------------------------