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

georgia-tech-db / eva / 88056f97-3ba0-4458-8b7e-20f8bb782cbe

pending completion
88056f97-3ba0-4458-8b7e-20f8bb782cbe

Pull #787

circle-ci

xzdandy
Check Notebook under ray
Pull Request #787: Enable ray be default

9700 of 10045 relevant lines covered (96.57%)

0.97 hits per line

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

96.83
/eva/executor/executor_utils.py
1
# coding=utf-8
2
# Copyright 2018-2022 EVA
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 Generator, List
1✔
19

20
import cv2
1✔
21

22
from eva.catalog.catalog_manager import CatalogManager
1✔
23
from eva.catalog.catalog_type import VectorStoreType
1✔
24
from eva.expression.abstract_expression import AbstractExpression
1✔
25
from eva.models.storage.batch import Batch
1✔
26
from eva.parser.table_ref import TableInfo
1✔
27
from eva.parser.types import FileFormatType
1✔
28
from eva.readers.document.registry import SUPPORTED_TYPES
1✔
29
from eva.utils.logging_manager import logger
1✔
30

31

32
class ExecutorError(Exception):
1✔
33
    pass
1✔
34

35

36
def apply_project(batch: Batch, project_list: List[AbstractExpression]):
1✔
37
    if not batch.empty() and project_list:
1✔
38
        batches = [expr.evaluate(batch) for expr in project_list]
1✔
39
        batch = Batch.merge_column_wise(batches)
1✔
40
    return batch
1✔
41

42

43
def apply_predicate(batch: Batch, predicate: AbstractExpression) -> Batch:
1✔
44
    if not batch.empty() and predicate is not None:
1✔
45
        outcomes = predicate.evaluate(batch)
1✔
46
        batch.drop_zero(outcomes)
1✔
47
    return batch
1✔
48

49

50
def handle_if_not_exists(table_info: TableInfo, if_not_exist=False):
1✔
51
    # Table exists
52
    if CatalogManager().check_table_exists(
1✔
53
        table_info.table_name,
54
        table_info.database_name,
55
    ):
56
        err_msg = "Table: {} already exists".format(table_info)
1✔
57
        if if_not_exist:
1✔
58
            logger.warn(err_msg)
1✔
59
            return True
1✔
60
        else:
61
            logger.error(err_msg)
1✔
62
            raise ExecutorError(err_msg)
63
    # Table does not exist
64
    else:
65
        return False
1✔
66

67

68
def validate_image(image_path: Path) -> bool:
1✔
69
    try:
1✔
70
        data = cv2.imread(str(image_path))
1✔
71
        return data is not None
1✔
72
    except Exception as e:
73
        logger.warning(
74
            f"Unexpected Exception {e} occurred while reading image file {image_path}"
75
        )
76
        return False
77

78

79
def iter_path_regex(path_regex: Path) -> Generator[str, None, None]:
1✔
80
    return glob.iglob(os.path.expanduser(path_regex), recursive=True)
1✔
81

82

83
def validate_video(video_path: Path) -> bool:
1✔
84
    try:
1✔
85
        vid = cv2.VideoCapture(str(video_path))
1✔
86
        if not vid.isOpened():
1✔
87
            return False
1✔
88
        return True
1✔
89
    except Exception as e:
90
        logger.warning(
91
            f"Unexpected Exception {e} occurred while reading video file {video_path}"
92
        )
93

94

95
def validate_document(doc_path: Path) -> bool:
1✔
96
    return doc_path.suffix in SUPPORTED_TYPES
1✔
97

98

99
def validate_pdf(doc_path: Path) -> bool:
1✔
100
    return doc_path.suffix == ".pdf"
1✔
101

102

103
def validate_media(file_path: Path, media_type: FileFormatType) -> bool:
1✔
104
    if media_type == FileFormatType.VIDEO:
1✔
105
        return validate_video(file_path)
1✔
106
    elif media_type == FileFormatType.IMAGE:
1✔
107
        return validate_image(file_path)
1✔
108
    elif media_type == FileFormatType.DOCUMENT:
1✔
109
        return validate_document(file_path)
1✔
110
    elif media_type == FileFormatType.PDF:
1✔
111
        return validate_pdf(file_path)
1✔
112
    else:
113
        raise ValueError(f"Unsupported Media type {str(media_type)}")
114

115

116
def handle_vector_store_params(
1✔
117
    vector_store_type: VectorStoreType, index_path: str
118
) -> dict:
119
    """Handle vector store parameters based on the vector store type and index path.
120

121
    Args:
122
        vector_store_type (VectorStoreType): The type of vector store.
123
        index_path (str): The path to store the index.
124

125
    Returns:
126
        dict: Dictionary containing the appropriate vector store parameters.
127

128

129
    Raises:
130
        ValueError: If the vector store type in the node is not supported.
131
    """
132
    if vector_store_type == VectorStoreType.FAISS:
1✔
133
        return {"index_path": index_path}
1✔
134
    elif vector_store_type == VectorStoreType.QDRANT:
×
135
        return {"index_db": str(Path(index_path).parent)}
×
136
    else:
137
        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

© 2026 Coveralls, Inc