• 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

79.22
/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
1✔
16
import os
1✔
17
from pathlib import Path
1✔
18
from typing import TYPE_CHECKING, Generator, List
1✔
19

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

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

33

34
class ExecutorError(Exception):
1✔
35
    pass
1✔
36

37

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

45
        # persist stats of function expression
46
        for expr in project_list:
1✔
47
            for func_expr in expr.find_all(FunctionExpression):
1✔
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
1✔
54

55

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

64
        # persist stats of function expression
65
        for func_expr in predicate.find_all(FunctionExpression):
1✔
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
1✔
72

73

74
def handle_if_not_exists(
1✔
75
    catalog: "CatalogManager", table_info: TableInfo, if_not_exist=False
76
):
77
    # Table exists
78
    if catalog.check_table_exists(
1✔
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
1✔
92

93

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

99
        data = cv2.imread(str(image_path))
1✔
100
        return data is not None
1✔
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]:
1✔
109
    return glob.iglob(os.path.expanduser(path_regex), recursive=True)
1✔
110

111

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

117
        vid = cv2.VideoCapture(str(video_path))
1✔
118
        if not vid.isOpened():
1✔
119
            return False
×
120
        return True
1✔
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:
1✔
128
    return doc_path.suffix in SUPPORTED_TYPES
×
129

130

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

134

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

147

148
def handle_vector_store_params(
1✔
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:
1✔
165
        return {"index_path": index_path}
1✔
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