-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path06_create_customer_demograhics_hive_table.hql
72 lines (65 loc) · 2.12 KB
/
06_create_customer_demograhics_hive_table.hql
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
-- create customer_demographics table and load parquet data
create table customer_demographics (
`CustomerID` int,
`TotalPurchaseYTD` string,
`DateFirstPurchase` string,
`BirthDate` string,
`MaritalStatus` string,
`YearlyIncome` string,
`Gender` string,
`TotalChildren` string,
`NumberChildrenAtHome` string,
`Education` string,
`Occupation` string,
`HomeOwnerFlag` string,
`NumberCarsOwned` string,
`CommuteDistance` string
)
stored as parquet;
load data local inpath 'part-00000-a7e0548d-8088-498c-95f9-701f3f34480a-c000.snappy.parquet' overwrite into table customer_demographics;
load data local inpath 'part-00001-a7e0548d-8088-498c-95f9-701f3f34480a-c000.snappy.parquet' into table customer_demographics;
load data local inpath 'part-00002-a7e0548d-8088-498c-95f9-701f3f34480a-c000.snappy.parquet' into table customer_demographics;
load data local inpath 'part-00003-a7e0548d-8088-498c-95f9-701f3f34480a-c000.snappy.parquet' into table customer_demographics;
-- check data
select * from customer_demographics limit 20;
-- compare with XML data in customer_test
select Demographics from customer_test limit 10;
-- create customer_demo table with appropriate column data types
create external table customer_demo (
`customerid` int,
`totalpurchaseytd` decimal(15,2),
`datefirstpurchase` timestamp,
`birthdate` timestamp,
`maritalstatus` string,
`yearlyincome` string,
`gender` string,
`totalchildren` tinyint,
`numberchildrenathome` tinyint,
`education` string,
`occupation` string,
`homeownerflag` string,
`numbercarsowned` tinyint,
`commutedistance` string
)
stored as parquet;
-- transform data from customer_demographics and insert into customer_demo
insert overwrite table customer_demo
select
customerid,
cast(totalpurchaseytd as decimal(15,2)),
to_date(substr(datefirstpurchase, 1, 10)),
to_date(substr(birthdate, 1, 10)),
maritalstatus,
yearlyincome,
gender,
cast(totalchildren as int),
cast(numberchildrenathome as int),
education,
occupation,
homeownerflag,
cast(numbercarsowned as int),
commutedistance
from customer_demographics;
-- check data in customer_demo
select * from customer_demo limit 10;
drop table customer_demographics;