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

georgia-tech-db / eva / #837

19 Oct 2023 09:02AM UTC coverage: 0.0% (-78.6%) from 78.632%
#837

push

circle-ci

Andy Xu
Add CostEntry

0 of 12416 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/insert_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 pandas as pd
×
16

17
from evadb.catalog.catalog_type import TableType
×
18
from evadb.database import EvaDBDatabase
×
19
from evadb.executor.abstract_executor import AbstractExecutor
×
20
from evadb.models.storage.batch import Batch
×
21
from evadb.plan_nodes.insert_plan import InsertPlan
×
22
from evadb.storage.storage_engine import StorageEngine
×
23

24

25
class InsertExecutor(AbstractExecutor):
×
26
    def __init__(self, db: EvaDBDatabase, node: InsertPlan):
×
27
        super().__init__(db, node)
×
28

29
    def exec(self, *args, **kwargs):
×
30
        storage_engine = None
×
31
        table_catalog_entry = None
×
32

33
        # Get catalog entry
34
        table_name = self.node.table_ref.table.table_name
×
35
        database_name = self.node.table_ref.table.database_name
×
36
        table_catalog_entry = self.catalog().get_table_catalog_entry(
×
37
            table_name, database_name
38
        )
39

40
        # Implemented only for STRUCTURED_DATA
41
        assert (
×
42
            table_catalog_entry.table_type == TableType.STRUCTURED_DATA
43
        ), "INSERT only implemented for structured data"
44

45
        values_to_insert = [val_node.value for val_node in self.node.value_list]
×
46
        tuple_to_insert = tuple(values_to_insert)
×
47
        columns_to_insert = [col_node.name for col_node in self.node.column_list]
×
48

49
        # Adding all values to Batch for insert
50
        dataframe = pd.DataFrame([tuple_to_insert], columns=columns_to_insert)
×
51
        batch = Batch(dataframe)
×
52

53
        storage_engine = StorageEngine.factory(self.db, table_catalog_entry)
×
54
        storage_engine.write(table_catalog_entry, batch)
×
55

56
        # Index update if there is an index built on the table.
57
        for index in self.db.catalog().get_all_index_catalog_entries():
×
58
            is_index_on_current_table = False
×
59
            for column in table_catalog_entry.columns:
×
60
                if column == index.feat_column:
×
61
                    is_index_on_current_table = True
×
62
            if is_index_on_current_table:
×
63
                create_index_query_list = index.index_def.split(" ")
×
64
                if_not_exists = " ".join(create_index_query_list[2:5]).lower()
×
65
                if if_not_exists != "if not exists":
×
66
                    create_index_query = (
×
67
                        " ".join(create_index_query_list[:2])
68
                        + " IF NOT EXISTS "
69
                        + " ".join(create_index_query_list[2:])
70
                    )
71
                from evadb.server.command_handler import execute_query_fetch_all
×
72

73
                execute_query_fetch_all(self.db, create_index_query)
×
74

75
        yield Batch(
×
76
            pd.DataFrame([f"Number of rows loaded: {str(len(values_to_insert))}"])
77
        )
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