-
Notifications
You must be signed in to change notification settings - Fork 8
/
process-file.sh
executable file
·139 lines (137 loc) · 3.63 KB
/
process-file.sh
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!/usr/bin/bash
clickhouse-local --time --engine_file_skip_empty_files 1 --optimize_trivial_insert_select 0 --query "
INSERT INTO FUNCTION remoteSecure('${CLICKHOUSE_PLANES_HOST}', '${TABLE}', '${CLICKHOUSE_PLANES_USER}', '${CLICKHOUSE_PLANES_PASSWORD}')
WITH arrayJoin(trace) AS elem,
elem.1 AS time_offset,
elem.2 AS lat,
elem.3 AS lon,
elem.4 AS altitude,
elem.5 AS ground_speed,
elem.6 AS track_degrees,
elem.7 AS flags,
elem.8 AS vertical_rate,
elem.9 AS aircraft,
elem.10 AS source,
elem.11 AS geometric_altitude,
elem.12 AS geometric_vertical_rate,
elem.13 AS indicated_airspeed,
elem.14 AS roll_angle
SELECT
CAST(timestamp + time_offset AS DateTime64(3)) AS time, time::Date AS date,
icao, r, t, dbFlags, noRegData, ownOp, year, desc,
lat, lon,
toInt32OrZero(altitude),
ground_speed,
track_degrees,
flags,
vertical_rate,
aircraft.alert,
aircraft.alt_geom,
aircraft.gva,
aircraft.nac_p,
aircraft.nac_v,
aircraft.nic,
aircraft.nic_baro,
aircraft.rc,
aircraft.sda,
aircraft.sil,
aircraft.sil_type,
aircraft.spi,
aircraft.track,
aircraft.type,
aircraft.version,
aircraft.category,
aircraft.emergency,
trimRight(aircraft.flight),
aircraft.squawk,
aircraft.baro_rate,
aircraft.nav_altitude_fms,
aircraft.nav_altitude_mcp,
aircraft.nav_modes,
aircraft.nav_qnh,
aircraft.geom_rate,
aircraft.ias,
aircraft.mach,
aircraft.mag_heading,
aircraft.oat,
aircraft.roll,
aircraft.tas,
aircraft.tat,
aircraft.true_heading,
aircraft.wd,
aircraft.ws,
aircraft.track_rate,
aircraft.nav_heading,
source,
geometric_altitude,
geometric_vertical_rate,
indicated_airspeed,
roll_angle,
'${SOURCE}'
FROM file('$1', JSONLines, '
icao String,
r String,
t String,
dbFlags Int32,
noRegData Bool,
ownOp String,
year UInt16,
timestamp Decimal64(3),
desc String,
trace Array(Tuple(
Decimal64(3),
Float64,
Float64,
String,
Float32,
Float32,
UInt32,
Int32,
Tuple(
alert Int64,
alt_geom Int64,
gva Int64,
nac_p Int64,
nac_v Int64,
nic Int64,
nic_baro Int64,
rc Int64,
sda Int64,
sil Int64,
sil_type String,
spi Int64,
track Float64,
type String,
version Int64,
category String,
emergency String,
flight String,
squawk String,
baro_rate Int64,
nav_altitude_fms Int64,
nav_altitude_mcp Int64,
nav_modes Array(String),
nav_qnh Float64,
geom_rate Int64,
ias Int64,
mach Float64,
mag_heading Float64,
oat Int64,
roll Float64,
tas Int64,
tat Int64,
true_heading Float64,
wd Int64,
ws Int64,
track_rate Float64,
nav_heading Float64
),
LowCardinality(String),
Int32,
Int32,
Int32,
Float32
))
', 'gz')
" || exit 1
echo -n '.'