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

georgia-tech-db / eva / #754

04 Sep 2023 09:54PM UTC coverage: 74.807% (-5.5%) from 80.336%
#754

push

circle-ci

jiashenC
update case

8727 of 11666 relevant lines covered (74.81%)

0.75 hits per line

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

48.28
/evadb/executor/drop_object_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

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 ExecutorError, handle_vector_store_params
1✔
22
from evadb.models.storage.batch import Batch
1✔
23
from evadb.parser.types import ObjectType
1✔
24
from evadb.plan_nodes.drop_object_plan import DropObjectPlan
1✔
25
from evadb.storage.storage_engine import StorageEngine
1✔
26
from evadb.third_party.vector_stores.utils import VectorStoreFactory
1✔
27
from evadb.utils.logging_manager import logger
1✔
28

29

30
class DropObjectExecutor(AbstractExecutor):
1✔
31
    def __init__(self, db: EvaDBDatabase, node: DropObjectPlan):
1✔
32
        super().__init__(db, node)
1✔
33

34
    def exec(self, *args, **kwargs):
1✔
35
        """Drop Object executor"""
36

37
        if self.node.object_type == ObjectType.TABLE:
1✔
38
            yield self._handle_drop_table(self.node.name, self.node.if_exists)
1✔
39

40
        elif self.node.object_type == ObjectType.INDEX:
×
41
            yield self._handle_drop_index(self.node.name, self.node.if_exists)
×
42

43
        elif self.node.object_type == ObjectType.FUNCTION:
×
44
            yield self._handle_drop_function(self.node.name, self.node.if_exists)
×
45

46
    def _handle_drop_table(self, table_name: str, if_exists: bool):
1✔
47
        if not self.catalog().check_table_exists(table_name):
1✔
48
            err_msg = "Table: {} does not exist".format(table_name)
×
49
            if if_exists:
×
50
                return Batch(pd.DataFrame([err_msg]))
×
51
            else:
52
                raise ExecutorError(err_msg)
53

54
        table_obj = self.catalog().get_table_catalog_entry(table_name)
1✔
55
        storage_engine = StorageEngine.factory(self.db, table_obj)
1✔
56

57
        logger.debug(f"Dropping table {table_name}")
1✔
58
        storage_engine.drop(table=table_obj)
1✔
59

60
        for col_obj in table_obj.columns:
1✔
61
            for cache in col_obj.dep_caches:
1✔
62
                self.catalog().drop_function_cache_catalog_entry(cache)
×
63

64
        # todo also delete the indexes associated with the table
65
        assert self.catalog().delete_table_catalog_entry(
1✔
66
            table_obj
67
        ), "Failed to drop {}".format(table_name)
68

69
        return Batch(
1✔
70
            pd.DataFrame(
71
                {"Table Successfully dropped: {}".format(table_name)},
72
                index=[0],
73
            )
74
        )
75

76
    def _handle_drop_function(self, function_name: str, if_exists: bool):
1✔
77
        # check catalog if it already has this function entry
78
        if not self.catalog().get_function_catalog_entry_by_name(function_name):
×
79
            err_msg = (
×
80
                f"Function {function_name} does not exist, therefore cannot be dropped."
81
            )
82
            if if_exists:
×
83
                logger.warning(err_msg)
×
84
                return Batch(pd.DataFrame([err_msg]))
×
85
            else:
86
                raise RuntimeError(err_msg)
87
        else:
88
            function_entry = self.catalog().get_function_catalog_entry_by_name(
×
89
                function_name
90
            )
91
            for cache in function_entry.dep_caches:
×
92
                self.catalog().drop_function_cache_catalog_entry(cache)
×
93

94
            # todo also delete the indexes associated with the table
95

96
            self.catalog().delete_function_catalog_entry_by_name(function_name)
×
97

98
            return Batch(
×
99
                pd.DataFrame(
100
                    {f"Function {function_name} successfully dropped"},
101
                    index=[0],
102
                )
103
            )
104

105
    def _handle_drop_index(self, index_name: str, if_exists: bool):
1✔
106
        index_obj = self.catalog().get_index_catalog_entry_by_name(index_name)
×
107
        if not index_obj:
×
108
            err_msg = f"Index {index_name} does not exist, therefore cannot be dropped."
×
109
            if if_exists:
×
110
                logger.warning(err_msg)
×
111
                return Batch(pd.DataFrame([err_msg]))
×
112
            else:
113
                raise RuntimeError(err_msg)
114
        else:
115
            index = VectorStoreFactory.init_vector_store(
×
116
                index_obj.type,
117
                index_obj.name,
118
                **handle_vector_store_params(index_obj.type, index_obj.save_file_path),
119
            )
120
            assert (
×
121
                index is not None
122
            ), f"Failed to initialize the vector store handler for {index_obj.type}"
123

124
            if index:
×
125
                index.delete()
×
126

127
            self.catalog().drop_index_catalog_entry(index_name)
×
128

129
            return Batch(
×
130
                pd.DataFrame(
131
                    {f"Index {index_name} successfully dropped"},
132
                    index=[0],
133
                )
134
            )
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

© 2025 Coveralls, Inc