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

georgia-tech-db / eva / f09e3b44-ef34-4638-a136-6dc1a5893c0a

26 Oct 2023 11:49PM UTC coverage: 92.368% (-0.8%) from 93.203%
f09e3b44-ef34-4638-a136-6dc1a5893c0a

push

circle-ci

web-flow
Merge branch 'georgia-tech-db:master' into master

1152 of 1152 new or added lines in 80 files covered. (100.0%)

11836 of 12814 relevant lines covered (92.37%)

0.92 hits per line

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

95.0
/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
1✔
16

17
import pandas as pd
1✔
18

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

31

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

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

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

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

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

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

65
            msg = f"The table {name} has been successfully created"
1✔
66
            if self.children != []:
1✔
67
                assert (
1✔
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]
1✔
73

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

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

85
            yield Batch(pd.DataFrame([msg]))
1✔
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