-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemocdf.sh
200 lines (171 loc) · 4.07 KB
/
democdf.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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
clear
cd /opt/demo
yum -y install git
git clone https://github.com/tspannhw/meetup-sensors
git clone https://github.com/tspannhw/FlinkSQLDemo
chmod -R 777 /opt/demo/FlinkSQLDemo
chmod -R 777 /opt/demo/meetup-sensors
/opt/demo/FlinkSQLDemo/sethdfspermissions.sh
/opt/cloudera/parcels/CDH/bin/kafka-topics --create --bootstrap-server edge2ai-1.dim.local:9092 --replication-factor 1 --partitions 1 --topic global_sensor_events
/opt/cloudera/parcels/CDH/bin/kafka-topics --create --bootstrap-server edge2ai-1.dim.local:9092 --replication-factor 1 --partitions 1 --topic energy
/opt/cloudera/parcels/CDH/bin/kafka-topics --create --bootstrap-server edge2ai-1.dim.local:9092 --replication-factor 1 --partitions 1 --topic scada
/opt/demo/FlinkSQLDemo/buildyarnsession.sh
/opt/demo/FlinkSQLDemo/startsqlclient.sh
show catalogs;
use catalog registry;
show tables;
describe test3;
CREATE TABLE global_sensor_events (
uuid STRING,
systemtime STRING ,
temperaturef STRING ,
pressure DOUBLE,
humidity DOUBLE,
lux DOUBLE,
proximity int,
oxidising DOUBLE ,
reducing DOUBLE,
nh3 DOUBLE ,
gasko STRING,
`current` INT,
voltage INT ,
`power` INT,
`total` INT,
fanstatus STRING
) WITH (
'connector.type' = 'kafka',
'connector.version' = 'universal',
'connector.topic' = 'global_sensor_events',
'connector.startup-mode' = 'earliest-offset',
'connector.properties.bootstrap.servers' = 'edge2ai-1.dim.local:9092',
'connector.properties.group.id' = 'flink-sql-global-sensor-join',
'format.type' = 'json'
);
CREATE TABLE energy (
uuid STRING,
systemtime STRING,
`current` INT,
voltage INT,
`power` INT,
`total` INT,
swver STRING,
hwver STRING,
type STRING,
model STRING,
mac STRING,
deviceId STRING,
hwId STRING,
fwId STRING,
oemId STRING,
alias STRING,
devname STRING,
iconhash STRING,
relaystate INT,
ontime INT,
activemode STRING,
feature STRING,
updating INT,
rssi INT,
ledoff INT,
latitude INT,
longitude INT,
`day` INT,
`index` INT,
zonestr STRING,
tzstr STRING,
dstoffset INT,
host STRING,
currentconsumption INT,
devicetime STRING,
ledon STRING,
fanstatus STRING,
`end` STRING,
te STRING,
cpu INT,
memory INT,
diskusage STRING
) WITH (
'connector.type' = 'kafka',
'connector.version' = 'universal',
'connector.topic' = 'energy',
'connector.startup-mode' = 'earliest-offset',
'connector.properties.bootstrap.servers' = 'edge2ai-1.dim.local:9092',
'connector.properties.group.id' = 'flink-sql-energy-consumer',
'format.type' = 'json'
);
CREATE TABLE scada (
uuid STRING,
systemtime STRING,
amplitude100 DOUBLE,
amplitude500 DOUBLE,
amplitude1000 DOUBLE,
lownoise DOUBLE,
midnoise DOUBLE,
highnoise DOUBLE,
amps DOUBLE,
ipaddress STRING,
host STRING,
host_name STRING,
macaddress STRING,
endtime STRING,
runtime STRING,
starttime STRING,
cpu DOUBLE,
cpu_temp STRING,
diskusage STRING,
memory DOUBLE,
id STRING,
temperature STRING,
adjtemp STRING,
adjtempf STRING,
temperaturef STRING,
pressure DOUBLE,
humidity DOUBLE,
lux DOUBLE,
proximity INT,
oxidising DOUBLE,
reducing DOUBLE,
nh3 DOUBLE,
gasko STRING
) WITH (
'connector.type' = 'kafka',
'connector.version' = 'universal',
'connector.topic' = 'scada',
'connector.startup-mode' = 'earliest-offset',
'connector.properties.bootstrap.servers' = 'edge2ai-1.dim.local:9092',
'connector.properties.group.id' = 'flink-sql-scada-consumer',
'format.type' = 'json'
);
INSERT INTO global_sensor_events
SELECT
scada.uuid,
scada.systemtime ,
scada.temperaturef ,
scada.pressure ,
scada.humidity ,
scada.lux ,
scada.proximity ,
scada.oxidising ,
scada.reducing ,
scada.nh3 ,
scada.gasko,
energy.`current`,
energy.voltage ,
energy.`power` ,
energy.`total`,
energy.fanstatus
FROM energy,
scada
WHERE
scada.systemtime = energy.systemtime;
show tables;
# then query then Quit
select * from energy;
select * from scada;
select * from global_sensor_events;
# when done
drop table energy;
drop table scada;
drop table global_sensor_events;
# exit
exit;