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

georgia-tech-db / eva / #758

04 Sep 2023 08:37PM UTC coverage: 0.0% (-78.3%) from 78.333%
#758

push

circle-ci

hershd23
Increased underline length in at line 75 in text_summarization.rst
	modified:   docs/source/benchmarks/text_summarization.rst

0 of 11303 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/executor_utils.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 glob
×
16
import os
×
17
from pathlib import Path
×
18
from typing import TYPE_CHECKING, Generator, List
×
19

20
if TYPE_CHECKING:
21
    from evadb.catalog.catalog_manager import CatalogManager
22

23
from evadb.catalog.catalog_type import VectorStoreType
×
24
from evadb.expression.abstract_expression import AbstractExpression
×
25
from evadb.expression.function_expression import FunctionExpression
×
26
from evadb.models.storage.batch import Batch
×
27
from evadb.parser.table_ref import TableInfo
×
28
from evadb.parser.types import FileFormatType
×
29
from evadb.readers.document.registry import SUPPORTED_TYPES
×
30
from evadb.utils.generic_utils import try_to_import_cv2
×
31
from evadb.utils.logging_manager import logger
×
32

33

34
class ExecutorError(Exception):
×
35
    pass
×
36

37

38
def apply_project(
×
39
    batch: Batch, project_list: List[AbstractExpression], catalog: "CatalogManager"
40
):
41
    if not batch.empty() and project_list:
×
42
        batches = [expr.evaluate(batch) for expr in project_list]
×
43
        batch = Batch.merge_column_wise(batches)
×
44

45
        # persist stats of function expression
46
        for expr in project_list:
×
47
            for func_expr in expr.find_all(FunctionExpression):
×
48
                if func_expr.udf_obj and func_expr._stats:
×
49
                    udf_id = func_expr.udf_obj.row_id
×
50
                    catalog.upsert_udf_cost_catalog_entry(
×
51
                        udf_id, func_expr.udf_obj.name, func_expr._stats.prev_cost
52
                    )
53
    return batch
×
54

55

56
def apply_predicate(
×
57
    batch: Batch, predicate: AbstractExpression, catalog: "CatalogManager"
58
) -> Batch:
59
    if not batch.empty() and predicate is not None:
×
60
        outcomes = predicate.evaluate(batch)
×
61
        batch.drop_zero(outcomes)
×
62
        batch.reset_index()
×
63

64
        # persist stats of function expression
65
        for func_expr in predicate.find_all(FunctionExpression):
×
66
            if func_expr.udf_obj and func_expr._stats:
×
67
                udf_id = func_expr.udf_obj.row_id
×
68
                catalog.upsert_udf_cost_catalog_entry(
×
69
                    udf_id, func_expr.udf_obj.name, func_expr._stats.prev_cost
70
                )
71
    return batch
×
72

73

74
def handle_if_not_exists(
×
75
    catalog: "CatalogManager", table_info: TableInfo, if_not_exist=False
76
):
77
    # Table exists
78
    if catalog.check_table_exists(
×
79
        table_info.table_name,
80
        table_info.database_name,
81
    ):
82
        err_msg = "Table: {} already exists".format(table_info)
×
83
        if if_not_exist:
×
84
            logger.warn(err_msg)
×
85
            return True
×
86
        else:
87
            logger.error(err_msg)
×
88
            raise ExecutorError(err_msg)
89
    # Table does not exist
90
    else:
91
        return False
×
92

93

94
def validate_image(image_path: Path) -> bool:
×
95
    try:
×
96
        try_to_import_cv2()
×
97
        import cv2
×
98

99
        data = cv2.imread(str(image_path))
×
100
        return data is not None
×
101
    except Exception as e:
102
        logger.warning(
103
            f"Unexpected Exception {e} occurred while reading image file {image_path}"
104
        )
105
        return False
106

107

108
def iter_path_regex(path_regex: Path) -> Generator[str, None, None]:
×
109
    return glob.iglob(os.path.expanduser(path_regex), recursive=True)
×
110

111

112
def validate_video(video_path: Path) -> bool:
×
113
    try:
×
114
        try_to_import_cv2()
×
115
        import cv2
×
116

117
        vid = cv2.VideoCapture(str(video_path))
×
118
        if not vid.isOpened():
×
119
            return False
×
120
        return True
×
121
    except Exception as e:
122
        logger.warning(
123
            f"Unexpected Exception {e} occurred while reading video file {video_path}"
124
        )
125

126

127
def validate_document(doc_path: Path) -> bool:
×
128
    return doc_path.suffix in SUPPORTED_TYPES
×
129

130

131
def validate_pdf(doc_path: Path) -> bool:
×
132
    return doc_path.suffix == ".pdf"
×
133

134

135
def validate_media(file_path: Path, media_type: FileFormatType) -> bool:
×
136
    if media_type == FileFormatType.VIDEO:
×
137
        return validate_video(file_path)
×
138
    elif media_type == FileFormatType.IMAGE:
×
139
        return validate_image(file_path)
×
140
    elif media_type == FileFormatType.DOCUMENT:
×
141
        return validate_document(file_path)
×
142
    elif media_type == FileFormatType.PDF:
×
143
        return validate_pdf(file_path)
×
144
    else:
145
        raise ValueError(f"Unsupported Media type {str(media_type)}")
146

147

148
def handle_vector_store_params(
×
149
    vector_store_type: VectorStoreType, index_path: str
150
) -> dict:
151
    """Handle vector store parameters based on the vector store type and index path.
152

153
    Args:
154
        vector_store_type (VectorStoreType): The type of vector store.
155
        index_path (str): The path to store the index.
156

157
    Returns:
158
        dict: Dictionary containing the appropriate vector store parameters.
159

160

161
    Raises:
162
        ValueError: If the vector store type in the node is not supported.
163
    """
164
    if vector_store_type == VectorStoreType.FAISS:
×
165
        return {"index_path": index_path}
×
166
    elif vector_store_type == VectorStoreType.QDRANT:
×
167
        return {"index_db": str(Path(index_path).parent)}
×
168
    else:
169
        raise ValueError("Unsupported vector store type: {}".format(vector_store_type))
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