-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFAAMerge.hql
More file actions
97 lines (92 loc) · 2.32 KB
/
FAAMerge.hql
File metadata and controls
97 lines (92 loc) · 2.32 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
CREATE DATABASE if not exists ADFLAB;
CREATE EXTERNAL TABLE if not exists ADFLAB.FAAMaster
(
N_Number string,
Serial_Number string ,
MFR_MDL_Code string ,
Eng_MFR_Code string ,
Year_MFR string ,
Type_Registrant string ,
Name string ,
Street1 string ,
Street2 string ,
City string ,
State string ,
ZIP string ,
Region string ,
County string ,
Country string ,
Last_Activity_Date string ,
Cert_Issue_Date string ,
Certification_Requested string ,
Type_Aircraft string ,
Type_Engine string ,
Status_Code string ,
Mode_S_Code string ,
Fractional_Ownership string ,
Airworthiness_Date string ,
OtherName1 string ,
OtherName2 string ,
OtherName3 string ,
OtherName4 string ,
OtherName5 string ,
Expiration_Date string ,
Unique_ID string ,
Kit_MFR_Code string ,
Kit_Model string ,
MoseSCodeHex string
)
ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' lines terminated by '\n'
LOCATION 'wasb://input@adflabstaging.blob.core.windows.net/FAAmaster' TBLPROPERTIES("skip.header.line.count"="1");
CREATE EXTERNAL TABLE if not exists ADFLAB.FAAaircraft
(
MFR_NAME string,
MODEL_NAME string,
TYPE_AIRCRAFT string,
TYPE_ENGINE string,
AC_CATEGORY string,
AMAC_TC_BUILT string,
NUMBER_ENGINES string,
NUMBER_SEATS string,
AC_WEIGHT string,
SPEED string,
MFR_MDL_CODE string,
KIT_CODE string
)
ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' lines terminated by '\n'
LOCATION 'wasb://input@adflabstaging.blob.core.windows.net/FAAaircraft' TBLPROPERTIES("skip.header.line.count"="1");
CREATE TABLE if not exists ADFLAB.Dummy
(
Some_key tinyint
);
USE ADFLAB;
INSERT INTO Dummy VALUES (1);
insert overwrite directory 'wasb://output@adflabstaging.blob.core.windows.net/FAAMerge'
ROW FORMAT DELIMITED
FIELDS TERMINATED BY ','
SELECT
N_Number,Serial_Number,Year_MFR,MFR_Name,Model_Name,Number_Engines,Number_Seats, sort_col
FROM
(
SELECT
0 as sort_col,
'N_Number' as N_Number,
'Serial_Number' as Serial_Number,
'Year_MFR' as Year_MFR,
'MFR_Name' as MFR_Name,
'Model_Name' as Model_Name,
'Number_Engines' as Number_Engines,
'Number_Seats' as Number_Seats
FROM
Dummy
UNION ALL
SELECT
1 as sort_col, N_Number,Serial_Number,Year_MFR,MFR_Name,Model_Name,Number_Engines,Number_Seats
FROM
FAAmaster M
JOIN
FAAaircraft A
ON (M.MFR_MDL_CODE = A.MFR_MDL_CODE)
) U
ORDER BY
sort_col ASC;