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

georgia-tech-db / eva / #832

12 Oct 2023 08:31AM UTC coverage: 0.0% (-68.5%) from 68.493%
#832

push

circle-ci

xzdandy
Minor

0 of 12331 relevant lines covered (0.0%)

0.0 hits per line

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

0.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
×
16

17
import pandas as pd
×
18

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

31

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

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

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

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

51
        if not is_native_table:
×
52
            catalog_entry = self.catalog().create_and_insert_table_catalog_entry(
×
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)
×
60

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

65
            msg = f"The table {name} has been successfully created"
×
66
            if self.children != []:
×
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]))
×
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