Skip to content

Commit

Permalink
fix: if create table fails, we were not cleaning the entry in catalog (
Browse files Browse the repository at this point in the history
  • Loading branch information
gaurav274 committed Sep 24, 2023
1 parent af6fe33 commit 49bdf55
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
6 changes: 6 additions & 0 deletions evadb/executor/create_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
# 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 contextlib

from evadb.database import EvaDBDatabase
from evadb.executor.abstract_executor import AbstractExecutor
from evadb.executor.executor_utils import (
Expand All @@ -20,6 +22,7 @@
)
from evadb.plan_nodes.create_plan import CreatePlan
from evadb.storage.storage_engine import StorageEngine
from evadb.utils.errors import CatalogError
from evadb.utils.logging_manager import logger


Expand Down Expand Up @@ -70,4 +73,7 @@ def exec(self, *args, **kwargs):
# rollback if the create call fails
if create_table_done:
storage_engine.drop(catalog_entry)
# rollback catalog entry, suppress any errors raised by catalog
with contextlib.suppress(CatalogError):
self.catalog().delete_table_catalog_entry(catalog_entry)
raise e
11 changes: 10 additions & 1 deletion test/integration_tests/long/test_create_table_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ def _test_currently_cannot_create_boolean_table(self):
with self.assertRaises(ExecutorError):
execute_query_fetch_all(self.evadb, query)

@macos_skip_marker
def test_should_create_table_from_select(self):
create_query = """CREATE TABLE dummy_table
AS SELECT id, DummyObjectDetector(data).label FROM MyVideo;
Expand Down Expand Up @@ -113,6 +112,16 @@ def test_should_create_table_from_select_lateral_join(self):
query = "CREATE TABLE IF NOT EXISTS " f"uadtrac_fastRCNN AS {select_query};"
execute_query_fetch_all(self.evadb, query)

def test_create_table_with_incorrect_info(self):
create_table = "CREATE TABLE SlackCSV(metadata TEXT(1000));"
with self.assertRaises(Exception):
execute_query_fetch_all(self.evadb, create_table)

# running create table after fixing the error
create_table = "CREATE TABLE SlackCSV(user_profile TEXT(1000));"
execute_query_fetch_all(self.evadb, create_table)
execute_query_fetch_all(self.evadb, "DROP TABLE SlackCSV;")


if __name__ == "__main__":
unittest.main()

0 comments on commit 49bdf55

Please sign in to comment.