-
Notifications
You must be signed in to change notification settings - Fork 21
/
customer_demo.hql
50 lines (46 loc) · 1.38 KB
/
customer_demo.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
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
location '/user/cloudera/bigretail/output/stores/spark/customer_demographics';
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
location '/user/cloudera/bigretail/output/stores/spark/customer_demo';
-- 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;
drop table customer_demographics;