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

georgia-tech-db / eva / a4c010ba-78be-4818-8e6f-1da08c6af280

31 Aug 2023 11:59PM UTC coverage: 70.992% (-10.6%) from 81.552%
a4c010ba-78be-4818-8e6f-1da08c6af280

push

circle-ci

web-flow
Merge branch 'staging' into evadb_staging

54 of 54 new or added lines in 3 files covered. (100.0%)

8020 of 11297 relevant lines covered (70.99%)

0.71 hits per line

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

29.23
/evadb/executor/delete_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
from typing import Iterator
1✔
16

17
import pandas as pd
1✔
18
from sqlalchemy import and_, or_
1✔
19

20
from evadb.catalog.catalog_type import TableType
1✔
21
from evadb.catalog.models.table_catalog import TableCatalogEntry
1✔
22
from evadb.database import EvaDBDatabase
1✔
23
from evadb.executor.abstract_executor import AbstractExecutor
1✔
24
from evadb.expression.abstract_expression import ExpressionType
1✔
25
from evadb.expression.comparison_expression import ComparisonExpression
1✔
26
from evadb.expression.constant_value_expression import ConstantValueExpression
1✔
27
from evadb.expression.logical_expression import LogicalExpression
1✔
28
from evadb.expression.tuple_value_expression import TupleValueExpression
1✔
29
from evadb.models.storage.batch import Batch
1✔
30
from evadb.plan_nodes.project_plan import ProjectPlan
1✔
31
from evadb.storage.storage_engine import StorageEngine
1✔
32

33

34
class DeleteExecutor(AbstractExecutor):
1✔
35
    """ """
36

37
    def __init__(self, db: EvaDBDatabase, node: ProjectPlan):
1✔
38
        super().__init__(db, node)
×
39
        self.predicate = node.where_clause
×
40

41
    def predicate_node_to_filter_clause(
1✔
42
        self, table: TableCatalogEntry, predicate_node: ComparisonExpression
43
    ):
44
        filter_clause = None
×
45
        left = predicate_node.get_child(0)
×
46
        right = predicate_node.get_child(1)
×
47

48
        if isinstance(left, TupleValueExpression):
×
49
            column = left.name
×
50
            x = table.columns[column]
×
51
        elif isinstance(left, ConstantValueExpression):
×
52
            value = left.value
×
53
            x = value
×
54
        else:
55
            left_filter_clause = self.predicate_node_to_filter_clause(table, left)
×
56

57
        if isinstance(right, TupleValueExpression):
×
58
            column = right.name
×
59
            y = table.columns[column]
×
60
        elif isinstance(right, ConstantValueExpression):
×
61
            value = right.value
×
62
            y = value
×
63
        else:
64
            right_filter_clause = self.predicate_node_to_filter_clause(table, right)
×
65

66
        if isinstance(predicate_node, LogicalExpression):
×
67
            if predicate_node.etype == ExpressionType.LOGICAL_AND:
×
68
                filter_clause = and_(left_filter_clause, right_filter_clause)
×
69
            elif predicate_node.etype == ExpressionType.LOGICAL_OR:
×
70
                filter_clause = or_(left_filter_clause, right_filter_clause)
×
71

72
        elif isinstance(predicate_node, ComparisonExpression):
×
73
            assert (
×
74
                predicate_node.etype != ExpressionType.COMPARE_CONTAINS
75
                and predicate_node.etype != ExpressionType.COMPARE_IS_CONTAINED
76
            ), f"Predicate type {predicate_node.etype} not supported in delete"
77

78
            if predicate_node.etype == ExpressionType.COMPARE_EQUAL:
×
79
                filter_clause = x == y
×
80
            elif predicate_node.etype == ExpressionType.COMPARE_GREATER:
×
81
                filter_clause = x > y
×
82
            elif predicate_node.etype == ExpressionType.COMPARE_LESSER:
×
83
                filter_clause = x < y
×
84
            elif predicate_node.etype == ExpressionType.COMPARE_GEQ:
×
85
                filter_clause = x >= y
×
86
            elif predicate_node.etype == ExpressionType.COMPARE_LEQ:
×
87
                filter_clause = x <= y
×
88
            elif predicate_node.etype == ExpressionType.COMPARE_NEQ:
×
89
                filter_clause = x != y
×
90

91
        return filter_clause
×
92

93
    def exec(self, *args, **kwargs) -> Iterator[Batch]:
1✔
94
        table_catalog = self.node.table_ref.table.table_obj
×
95
        storage_engine = StorageEngine.factory(self.db, table_catalog)
×
96

97
        assert (
×
98
            table_catalog.table_type == TableType.STRUCTURED_DATA
99
        ), "DELETE only implemented for structured data"
100

101
        table_to_delete_from = storage_engine._try_loading_table_via_reflection(
×
102
            table_catalog.name
103
        )
104

105
        sqlalchemy_filter_clause = self.predicate_node_to_filter_clause(
×
106
            table_to_delete_from, predicate_node=self.predicate
107
        )
108
        # verify where clause and convert to sqlalchemy supported filter
109
        # https://stackoverflow.com/questions/34026210/where-filter-from-table-object-using-a-dictionary-or-kwargs
110

111
        storage_engine.delete(table_catalog, sqlalchemy_filter_clause)
×
112
        yield Batch(pd.DataFrame(["Deleted rows"]))
×
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