Skip to content

Commit 2295cd2

Browse files
committed
Add more protection for empty tables send to external systems
1 parent 80c3f87 commit 2295cd2

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# Copyright (c) Cosmo Tech corporation.
22
# Licensed under the MIT license.
33

4-
__version__ = '0.8.2'
4+
__version__ = '0.8.3'

cosmotech/coal/cli/commands/api/rds_send_store.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,16 @@ def rds_send_store(
8080
api_run = RunApi(api_client)
8181
_s = Store()
8282
for table_name in _s.list_tables():
83+
LOGGER.info(f"Sending data to table [cyan bold]CD_{table_name}[/]")
8384
data = convert_table_as_pylist(table_name)
85+
if not len(data):
86+
LOGGER.info(" - No rows : skipping")
87+
continue
8488
fieldnames = _s.get_table_schema(table_name).names
8589
for row in data:
8690
for field in fieldnames:
8791
if row[field] is None:
8892
del row[field]
89-
LOGGER.info(f"Sending data to table [cyan bold]CD_{table_name}[/]")
9093
LOGGER.debug(f" - Column list: {fieldnames}")
9194
LOGGER.info(f" - Sending {len(data)} rows")
9295
api_run.send_run_data(organization_id,

cosmotech/coal/cli/commands/store/dump_to_s3.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,15 @@ def data_upload(data_stream: BytesIO, file_name: str):
152152
for table_name in tables:
153153
_data_stream = BytesIO()
154154
_file_name = None
155+
_data = _s.get_table(table_name)
156+
if not len(_data):
157+
LOGGER.info(f"Table {table_name} is empty (skipping)")
158+
continue
155159
if output_type == "csv":
156160
_file_name = table_name + ".csv"
157-
pc.write_csv(_s.get_table(table_name), _data_stream)
161+
pc.write_csv(_data, _data_stream)
158162
elif output_type == "parquet":
159163
_file_name = table_name + ".parquet"
160-
pq.write_table(_s.get_table(table_name), _data_stream)
164+
pq.write_table(_data, _data_stream)
161165
LOGGER.info(f"Sending table {table_name} as {output_type}")
162166
data_upload(_data_stream, _file_name)

0 commit comments

Comments
 (0)