forked from apache/beam
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinput_data.py
More file actions
328 lines (287 loc) · 10.6 KB
/
input_data.py
File metadata and controls
328 lines (287 loc) · 10.6 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
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
# coding=utf-8
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
import typing
from apache_beam.io.gcp.pubsub import PubsubMessage
# This file contains the input data to be requested by the example tests, if
# needed.
def text_data():
return '\n'.join([
"Fool\tThou shouldst not have been old till thou hadst",
"\tbeen wise.",
"KING LEAR\tNothing will come of nothing: speak again.",
"\tNever, never, never, never, never!"
])
def word_count_jinja_parameter_data():
return \
'{"readFromTextTransform": {"path": ' \
'"gs://dataflow-samples/shakespeare/kinglear.txt"}, ' \
'"mapToFieldsSplitConfig": {"language": "python", ' \
'"fields":{"value":"1"}}, ' \
'"explodeTransform":{"fields":"word"}, ' \
'"combineTransform":{"group_by":"word", "combine":{"value":"sum"}}, ' \
'"mapToFieldsCountConfig":{"language": "python", "fields":' \
'{"output": "word + \\" - \\" + str(value)"}}, ' \
'"writeToTextTransform":' \
'{"path":"gs://apache-beam-testing-derrickaw/wordCounts/"}}'
def word_count_jinja_template_data():
return \
[('apache_beam/yaml/examples/transforms/jinja/'
'include/submodules/readFromTextTransform.yaml'),
('apache_beam/yaml/examples/transforms/jinja/'
'include/submodules/mapToFieldsSplitConfig.yaml'),
('apache_beam/yaml/examples/transforms/jinja/'
'include/submodules/explodeTransform.yaml'),
('apache_beam/yaml/examples/transforms/jinja/'
'include/submodules/combineTransform.yaml'),
('apache_beam/yaml/examples/transforms/jinja/'
'include/submodules/mapToFieldsCountConfig.yaml'),
('apache_beam/yaml/examples/transforms/jinja/'
'include/submodules/writeToTextTransform.yaml')]
def iceberg_dynamic_destinations_users_data():
return [{
'id': 3, 'name': 'Smith', 'email': 'smith@example.com', 'zip': 'NY'
},
{
'id': 4,
'name': 'Beamberg',
'email': 'beamberg@example.com',
'zip': 'NY'
}]
def products_csv():
return '\n'.join([
'transaction_id,product_name,category,price',
'T0012,Headphones,Electronics,59.99',
'T5034,Leather Jacket,Apparel,109.99',
'T0024,Aluminum Mug,Kitchen,29.99',
'T0104,Headphones,Electronics,59.99',
'T0302,Monitor,Electronics,249.99'
])
def youtube_comments_csv():
return '\n'.join([
'video_id,comment_text,likes,replies',
'XpVt6Z1Gjjo,I AM HAPPY,1,1',
'XpVt6Z1Gjjo,I AM SAD,1,1',
'XpVt6Z1Gjjo,§ÁĐ,1,1'
])
def spanner_orders_data():
return [{
'order_id': 1,
'customer_id': 1001,
'product_id': 2001,
'order_date': '24-03-24',
'order_amount': 150,
},
{
'order_id': 2,
'customer_id': 1002,
'product_id': 2002,
'order_date': '19-04-24',
'order_amount': 90,
},
{
'order_id': 3,
'customer_id': 1003,
'product_id': 2003,
'order_date': '7-05-24',
'order_amount': 110,
}]
def shipments_data():
return [{
'shipment_id': 'S1',
'customer_id': 'C1',
'shipment_date': '2023-05-01',
'shipment_cost': 150.0,
'customer_name': 'Alice',
'customer_email': 'alice@example.com'
},
{
'shipment_id': 'S2',
'customer_id': 'C2',
'shipment_date': '2023-06-12',
'shipment_cost': 300.0,
'customer_name': 'Bob',
'customer_email': 'bob@example.com'
},
{
'shipment_id': 'S3',
'customer_id': 'C1',
'shipment_date': '2023-05-10',
'shipment_cost': 20.0,
'customer_name': 'Alice',
'customer_email': 'alice@example.com'
},
{
'shipment_id': 'S4',
'customer_id': 'C4',
'shipment_date': '2024-07-01',
'shipment_cost': 150.0,
'customer_name': 'Derek',
'customer_email': 'derek@example.com'
},
{
'shipment_id': 'S5',
'customer_id': 'C5',
'shipment_date': '2023-05-09',
'shipment_cost': 300.0,
'customer_name': 'Erin',
'customer_email': 'erin@example.com'
},
{
'shipment_id': 'S6',
'customer_id': 'C4',
'shipment_date': '2024-07-02',
'shipment_cost': 150.0,
'customer_name': 'Derek',
'customer_email': 'derek@example.com'
}]
def bigtable_data():
return [{
'product_id': '1', 'product_name': 'pixel 5', 'product_stock': '2'
}, {
'product_id': '2', 'product_name': 'pixel 6', 'product_stock': '4'
}, {
'product_id': '3', 'product_name': 'pixel 7', 'product_stock': '20'
}, {
'product_id': '4', 'product_name': 'pixel 8', 'product_stock': '10'
}, {
'product_id': '5', 'product_name': 'pixel 11', 'product_stock': '3'
}, {
'product_id': '6', 'product_name': 'pixel 12', 'product_stock': '7'
}, {
'product_id': '7', 'product_name': 'pixel 13', 'product_stock': '8'
}, {
'product_id': '8', 'product_name': 'pixel 14', 'product_stock': '3'
}]
def bigquery_data():
return [{
'customer_id': 1001,
'customer_name': 'Alice',
'customer_email': 'alice@gmail.com'
},
{
'customer_id': 1002,
'customer_name': 'Bob',
'customer_email': 'bob@gmail.com'
},
{
'customer_id': 1003,
'customer_name': 'Claire',
'customer_email': 'claire@gmail.com'
}]
def pubsub_messages_data():
"""
Provides a list of PubsubMessage objects for testing.
"""
return [
PubsubMessage(data=b"{\"label\": \"37a\", \"rank\": 1}", attributes={}),
PubsubMessage(data=b"{\"label\": \"37b\", \"rank\": 4}", attributes={}),
PubsubMessage(data=b"{\"label\": \"37c\", \"rank\": 3}", attributes={}),
PubsubMessage(data=b"{\"label\": \"37d\", \"rank\": 2}", attributes={}),
]
def pubsub_taxi_ride_events_data():
"""
Provides a list of PubsubMessage objects for testing taxi ride events.
"""
return [
PubsubMessage(
data=b"{\"ride_id\": \"1\", \"longitude\": 11.0, \"latitude\": -11.0,"
b"\"passenger_count\": 1, \"meter_reading\": 100.0, \"timestamp\": "
b"\"2025-01-01T00:29:00.00000-04:00\", \"ride_status\": \"pickup\"}",
attributes={}),
PubsubMessage(
data=b"{\"ride_id\": \"2\", \"longitude\": 22.0, \"latitude\": -22.0,"
b"\"passenger_count\": 2, \"meter_reading\": 100.0, \"timestamp\": "
b"\"2025-01-01T00:30:00.00000-04:00\", \"ride_status\": \"pickup\"}",
attributes={}),
PubsubMessage(
data=b"{\"ride_id\": \"1\", \"longitude\": 13.0, \"latitude\": -13.0,"
b"\"passenger_count\": 1, \"meter_reading\": 100.0, \"timestamp\": "
b"\"2025-01-01T00:31:00.00000-04:00\", \"ride_status\": \"enroute\"}",
attributes={}),
PubsubMessage(
data=b"{\"ride_id\": \"2\", \"longitude\": 24.0, \"latitude\": -24.0,"
b"\"passenger_count\": 2, \"meter_reading\": 100.0, \"timestamp\": "
b"\"2025-01-01T00:32:00.00000-04:00\", \"ride_status\": \"enroute\"}",
attributes={}),
PubsubMessage(
data=b"{\"ride_id\": \"3\", \"longitude\": 33.0, \"latitude\": -33.0,"
b"\"passenger_count\": 3, \"meter_reading\": 100.0, \"timestamp\": "
b"\"2025-01-01T00:35:00.00000-04:00\", \"ride_status\": \"enroute\"}",
attributes={}),
PubsubMessage(
data=b"{\"ride_id\": \"4\", \"longitude\": 44.0, \"latitude\": -44.0,"
b"\"passenger_count\": 4, \"meter_reading\": 100.0, \"timestamp\": "
b"\"2025-01-01T00:35:00.00000-04:00\", \"ride_status\": \"dropoff\"}",
attributes={}),
PubsubMessage(
data=b"{\"ride_id\": \"1\", \"longitude\": 15.0, \"latitude\": -15.0,"
b"\"passenger_count\": 1, \"meter_reading\": 100.0, \"timestamp\": "
b"\"2025-01-01T00:33:00.00000-04:00\", \"ride_status\": \"dropoff\"}",
attributes={}),
PubsubMessage(
data=b"{\"ride_id\": \"2\", \"longitude\": 26.0, \"latitude\": -26.0,"
b"\"passenger_count\": 2, \"meter_reading\": 100.0, \"timestamp\": "
b"\"2025-01-01T00:34:00.00000-04:00\", \"ride_status\": \"dropoff\"}",
attributes={}),
]
def kafka_messages_data():
"""
Provides a list of Kafka messages for testing.
"""
return [data.encode('utf-8') for data in text_data().split('\n')]
class TaxiRideEventSchema(typing.NamedTuple):
ride_id: str
longitude: float
latitude: float
passenger_count: int
meter_reading: float
timestamp: str
ride_status: str
def system_logs_csv():
return '\n'.join([
'LineId,Date,Time,Level,Process,Component,Content',
'1,2024-10-01,12:00:00,INFO,Main,ComponentA,System started successfully',
'2,2024-10-01,12:00:05,WARN,Main,ComponentA,Memory usage is high',
'3,2024-10-01,12:00:10,ERROR,Main,ComponentA,Task failed due to timeout',
])
def system_logs_data():
csv_data = system_logs_csv()
lines = csv_data.strip().split('\n')
headers = lines[0].split(',')
logs = []
for row in lines[1:]:
values = row.split(',')
log = dict(zip(headers, values))
log['LineId'] = int(log['LineId'])
logs.append(log)
return logs
def embedding_data():
return [0.1, 0.2, 0.3, 0.4, 0.5]
def system_logs_embedding_data():
csv_data = system_logs_csv()
lines = csv_data.strip().split('\n')
headers = lines[0].split(',')
headers.append('embedding')
logs = []
for row in lines[1:]:
values = row.split(',')
values.append(embedding_data())
log = dict(zip(headers, values))
log['LineId'] = int(log['LineId'])
logs.append(log)
return logs