You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# TODO: Consider how we might want to support multiple streams. Review other airbyte destinations
89
-
raiseException(f"The Glide destination expects only a single stream to be streamed into a Glide Table but found '{len(configured_catalog.streams)}' streams. Please select only one stream from the source.") # nopep8
84
+
defcreate_table_client_for_stream(stream_name):
85
+
# TODO: sanitize stream_name chars and length for GBT name
raiseException(f'Only destination sync mode overwrite is supported, but received "{configured_stream.destination_sync_mode}".') # nopep8 because https://github.com/hhatto/autopep8/issues/712
96
96
97
+
glide=create_table_client_for_stream(
98
+
configured_stream.stream.name)
97
99
# upsert the GBT with schema to set_schema for dumping the data into it
logger.debug(f"Found column/property '{prop_name}' with type '{prop_type}' and format '{prop_format}' in stream {configured_stream.stream.name}.") # nopep8
104
+
logger.debug(f"Found column/property '{prop_name}' with type '{prop_type}' in stream {configured_stream.stream.name}.") # nopep8
f"Stream {stream_name} was not present in configured streams, skipping")
121
123
continue
122
124
123
-
# TODO: check the columns match the columns that we saw in configured_catalog per https://docs.airbyte.com/understanding-airbyte/airbyte-protocol#destination
124
125
# add to buffer
125
126
record_data=message.record.data
126
127
record_id=str(uuid.uuid4())
@@ -133,24 +134,32 @@ def write(
133
134
# `Type.State` is a signal from the source that we should save the previous batch of `Type.RECORD` messages to the destination.
134
135
# It is a checkpoint that enables partial success.
135
136
# See https://docs.airbyte.com/understanding-airbyte/airbyte-protocol#state--checkpointing
136
-
logger.info(f"Writing buffered records to Glide API from {len(buffers.keys())} streams...") # nopep8 because
137
+
logger.info(f"Writing buffered records to Glide API from {len(buffers.keys())} streams...") # nopep8
137
138
forstream_nameinbuffers.keys():
138
139
stream_buffer=buffers[stream_name]
139
-
logger.info(f"Saving buffered records to Glide API (stream: '{stream_name}'count: '{len(stream_buffer)}')...") # nopep8 because https://github.com/hhatto/autopep8/issues/712
140
+
logger.info(f"Saving buffered records to Glide API (stream: '{stream_name}', record count: '{len(stream_buffer)}')...") # nopep8
140
141
DATA_INDEX=2
141
142
data_rows= [row_tuple[DATA_INDEX]
142
143
forrow_tupleinstream_buffer]
143
144
iflen(data_rows) >0:
145
+
ifstream_namenotintable_clients:
146
+
raiseException(
147
+
f"Stream '{stream_name}' not found in table_clients")
148
+
glide=table_clients[stream_name]
144
149
glide.add_rows(data_rows)
145
150
stream_buffer.clear()
146
151
logger.info(f"Saving buffered records to Glide API complete.") # nopep8 because https://github.com/hhatto/autopep8/issues/712
147
152
153
+
# dump all buffers now as we just wrote them to the table:
# overwrite the specified table's schema and rows with the stash:
209
+
r=requests.put(
210
+
self.url(f"tables/{table_id}"),
264
211
headers=self.headers(),
265
212
json={
266
-
"appID": self.hardcoded_app_id,
267
-
"queries": [
268
-
{
269
-
"tableName": self.table_id,
270
-
"utc": True
271
-
}
272
-
]
273
-
}
274
-
)
275
-
ifr.status_code!=200:
276
-
logger.error(f"get rows request failed with status {r.status_code}: {r.text}.") # nopep8 because https://github.com/hhatto/autopep8/issues/712
277
-
r.raise_for_status()
278
-
279
-
result=r.json()
280
-
281
-
# the result looks like an array of results; each result has a rows member that has an array or JSON rows:
282
-
forrowinresult:
283
-
forrinrow['rows']:
284
-
yieldr
285
-
286
-
defdelete_all(self) ->None:
287
-
# TODO: perf: don't put these in a list
288
-
rows=list(self.rows())
289
-
logger.debug(f"Iterating over {len(rows)} rows to delete")
290
-
291
-
forrowinrows:
292
-
# TODO: lame. batch these into one request with multiple mutations
293
-
r=requests.post(
294
-
self.url("function/mutateTables"),
295
-
headers=self.headers(),
296
-
json={
297
-
"appID": self.hardcoded_app_id,
298
-
"mutations": [
299
-
{
300
-
"kind": "delete-row",
301
-
"tableName": self.table_id,
302
-
"rowID": row['$rowID']
303
-
}
304
-
]
305
-
}
306
-
)
307
-
ifr.status_code!=200:
308
-
logger.error(f"delete request failed with status {r.status_code}: {r.text} trying to delete row id {row['$rowID']} with row: {row}") # nopep8 because https://github.com/hhatto/autopep8/issues/712
0 commit comments