Skip to content

Commit

Permalink
fix: CREATE TABLE persists entry in the catalog even if the query fai…
Browse files Browse the repository at this point in the history
…ls (#1008)

Rollback the catalog entry if the create query fails
  • Loading branch information
gaurav274 authored Aug 31, 2023
1 parent fd63af1 commit 66685f0
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions evadb/executor/create_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,30 @@ def exec(self, *args, **kwargs):
if not handle_if_not_exists(
self.catalog(), self.node.table_info, self.node.if_not_exists
):
create_table_done = False
logger.debug(f"Creating table {self.node.table_info}")

catalog_entry = self.catalog().create_and_insert_table_catalog_entry(
self.node.table_info, self.node.column_list
)
storage_engine = StorageEngine.factory(self.db, catalog_entry)
storage_engine.create(table=catalog_entry)
try:
storage_engine.create(table=catalog_entry)
create_table_done = True
if self.children != []:
assert (
len(self.children) == 1
), "Create table from query expects 1 child, finds {}".format(
len(self.children)
)
child = self.children[0]

if self.children != []:
assert (
len(self.children) == 1
), "Create table from query expects 1 child, finds {}".format(
len(self.children)
)
child = self.children[0]

# Populate the table
for batch in child.exec():
batch.drop_column_alias()
storage_engine.write(catalog_entry, batch)
# Populate the table
for batch in child.exec():
batch.drop_column_alias()
storage_engine.write(catalog_entry, batch)
except Exception as e:
# rollback if the create call fails
if create_table_done:
storage_engine.drop(catalog_entry)
raise e

0 comments on commit 66685f0

Please sign in to comment.