Skip to content

Commit

Permalink
Merge pull request graphnet-team#675 from Aske-Rosted/empty_db_handling
Browse files Browse the repository at this point in the history
handling of empty DB when merging
  • Loading branch information
Aske-Rosted authored Mar 21, 2024
2 parents 36efb24 + ed6b75f commit 205b20e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/graphnet/data/utilities/sqlite_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ def get_primary_keys(database: str) -> Tuple[Dict[str, str], str]:
query = 'SELECT name FROM sqlite_master WHERE type == "table"'
table_names = [table[0] for table in conn.execute(query).fetchall()]

assert len(table_names) > 0, "No tables found in database."

integer_primary_key = {}
for table in table_names:
query = f"SELECT l.name FROM pragma_table_info('{table}') as l WHERE l.pk = 1;"
Expand Down
9 changes: 8 additions & 1 deletion src/graphnet/data/writers/sqlite_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,14 @@ def _merge_databases(
for file_count, input_file in tqdm(enumerate(files), colour="green"):

# Extract table names and index column name in database
tables, primary_key = get_primary_keys(database=input_file)
try:
tables, primary_key = get_primary_keys(database=input_file)
except AssertionError as e:
if "No tables found in database." in str(e):
self.warning(f"Database {input_file} is empty. Skipping.")
continue
else:
raise e

for table_name in tables.keys():
# Extract all data in the table from the given database
Expand Down

0 comments on commit 205b20e

Please sign in to comment.