• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

georgia-tech-db / eva / 209620fd-a5d9-4f5c-9551-fa1d12bfd2a1

27 Sep 2023 05:22AM UTC coverage: 79.438% (-0.02%) from 79.462%
209620fd-a5d9-4f5c-9551-fa1d12bfd2a1

push

circle-ci

gaurav274
improve error messages and handle create table failures in native dbs

26 of 26 new or added lines in 1 file covered. (100.0%)

9786 of 12319 relevant lines covered (79.44%)

1.43 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

72.5
/evadb/executor/create_executor.py
1
# coding=utf-8
2
# Copyright 2018-2023 EvaDB
3
#
4
# Licensed under the Apache License, Version 2.0 (the "License");
5
# you may not use this file except in compliance with the License.
6
# You may obtain a copy of the License at
7
#
8
#     http://www.apache.org/licenses/LICENSE-2.0
9
#
10
# Unless required by applicable law or agreed to in writing, software
11
# distributed under the License is distributed on an "AS IS" BASIS,
12
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
# See the License for the specific language governing permissions and
14
# limitations under the License.
15
import contextlib
2✔
16

17
import pandas as pd
2✔
18

19
from evadb.database import EvaDBDatabase
2✔
20
from evadb.executor.abstract_executor import AbstractExecutor
2✔
21
from evadb.executor.executor_utils import (
2✔
22
    create_table_catalog_entry_for_native_table,
23
    handle_if_not_exists,
24
)
25
from evadb.models.storage.batch import Batch
2✔
26
from evadb.plan_nodes.create_plan import CreatePlan
2✔
27
from evadb.storage.storage_engine import StorageEngine
2✔
28
from evadb.utils.errors import CatalogError
2✔
29
from evadb.utils.logging_manager import logger
2✔
30

31

32
class CreateExecutor(AbstractExecutor):
2✔
33
    def __init__(self, db: EvaDBDatabase, node: CreatePlan):
2✔
34
        super().__init__(db, node)
2✔
35

36
    def exec(self, *args, **kwargs):
2✔
37
        # create a table in the ative database if set
38
        is_native_table = self.node.table_info.database_name is not None
2✔
39

40
        check_if_exists = handle_if_not_exists(
2✔
41
            self.catalog(), self.node.table_info, self.node.if_not_exists
42
        )
43
        name = self.node.table_info.table_name
2✔
44
        if check_if_exists:
2✔
45
            yield Batch(pd.DataFrame([f"Table {name} already exists"]))
×
46
            return
×
47

48
        create_table_done = False
2✔
49
        logger.debug(f"Creating table {self.node.table_info}")
2✔
50

51
        if not is_native_table:
2✔
52
            catalog_entry = self.catalog().create_and_insert_table_catalog_entry(
2✔
53
                self.node.table_info, self.node.column_list
54
            )
55
        else:
56
            catalog_entry = create_table_catalog_entry_for_native_table(
×
57
                self.node.table_info, self.node.column_list
58
            )
59
        storage_engine = StorageEngine.factory(self.db, catalog_entry)
2✔
60

61
        try:
2✔
62
            storage_engine.create(table=catalog_entry)
2✔
63
            create_table_done = True
2✔
64

65
            msg = f"The table {name} has been successfully created"
2✔
66
            if self.children != []:
2✔
67
                assert (
×
68
                    len(self.children) == 1
69
                ), "Create table from query expects 1 child, finds {}".format(
70
                    len(self.children)
71
                )
72
                child = self.children[0]
×
73

74
                rows = 0
×
75
                # Populate the table
76
                for batch in child.exec():
×
77
                    batch.drop_column_alias()
×
78
                    storage_engine.write(catalog_entry, batch)
×
79
                    rows += len(batch)
×
80

81
                msg = (
×
82
                    f"The table {name} has been successfully created with {rows} rows."
83
                )
84

85
            yield Batch(pd.DataFrame([msg]))
2✔
86
        except Exception as e:
87
            # rollback if the create call fails
88
            with contextlib.suppress(CatalogError):
89
                if create_table_done:
90
                    storage_engine.drop(catalog_entry)
91
            # rollback catalog entry, suppress any errors raised by catalog
92
            with contextlib.suppress(CatalogError):
93
                self.catalog().delete_table_catalog_entry(catalog_entry)
94
            raise e
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc