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

georgia-tech-db / eva / #832

12 Oct 2023 08:31AM UTC coverage: 0.0% (-68.5%) from 68.493%
#832

push

circle-ci

xzdandy
Minor

0 of 12331 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/functions/function_bootstrap_queries.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

16
from evadb.configuration.constants import EvaDB_INSTALLATION_DIR
×
17
from evadb.database import EvaDBDatabase
×
18
from evadb.server.command_handler import execute_query_fetch_all
×
19

20
NDARRAY_DIR = "ndarray"
×
21
TUTORIALS_DIR = "tutorials"
×
22

23
DummyObjectDetector_function_query = """CREATE FUNCTION IF NOT EXISTS DummyObjectDetector
×
24
                  INPUT  (Frame_Array NDARRAY INT8(3, ANYDIM, ANYDIM))
25
                  OUTPUT (label NDARRAY STR(1))
26
                  TYPE  Classification
27
                  IMPL  '{}/../test/util.py';
28
        """.format(
29
    EvaDB_INSTALLATION_DIR
30
)
31

32
DummyMultiObjectDetector_function_query = """CREATE FUNCTION
×
33
                  IF NOT EXISTS  DummyMultiObjectDetector
34
                  INPUT  (Frame_Array NDARRAY INT8(3, ANYDIM, ANYDIM))
35
                  OUTPUT (labels NDARRAY STR(2))
36
                  TYPE  Classification
37
                  IMPL  '{}/../test/util.py';
38
        """.format(
39
    EvaDB_INSTALLATION_DIR
40
)
41

42
DummyFeatureExtractor_function_query = """CREATE FUNCTION
×
43
                  IF NOT EXISTS DummyFeatureExtractor
44
                  INPUT (Frame_Array NDARRAY UINT8(3, ANYDIM, ANYDIM))
45
                  OUTPUT (features NDARRAY FLOAT32(1, ANYDIM))
46
                  TYPE Classification
47
                  IMPL '{}/../test/util.py';
48
        """.format(
49
    EvaDB_INSTALLATION_DIR
50
)
51

52
DummyNoInputFunction_function_query = """CREATE FUNCTION
×
53
                  IF NOT EXISTS DummyNoInputFunction
54
                  IMPL '{}/../test/util.py';
55
        """.format(
56
    EvaDB_INSTALLATION_DIR
57
)
58

59
DummyLLM_function_query = """CREATE FUNCTION
×
60
                  IF NOT EXISTS DummyLLM
61
                  IMPL '{}/../test/util.py';
62
        """.format(
63
    EvaDB_INSTALLATION_DIR
64
)
65

66
fuzzy_function_query = """CREATE FUNCTION IF NOT EXISTS FuzzDistance
×
67
                    INPUT (Input_Array1 NDARRAY ANYTYPE, Input_Array2 NDARRAY ANYTYPE)
68
                    OUTPUT (distance FLOAT(32, 7))
69
                    TYPE NdarrayFunction
70
                    IMPL "{}/functions/{}/fuzzy_join.py";
71
        """.format(
72
    EvaDB_INSTALLATION_DIR, NDARRAY_DIR
73
)
74

75
ArrayCount_function_query = """CREATE FUNCTION
×
76
            IF NOT EXISTS  ArrayCount
77
            INPUT (Input_Array NDARRAY ANYTYPE, Search_Key ANYTYPE)
78
            OUTPUT (key_count INTEGER)
79
            TYPE NdarrayFunction
80
            IMPL "{}/functions/{}/array_count.py";
81
        """.format(
82
    EvaDB_INSTALLATION_DIR, NDARRAY_DIR
83
)
84

85
Crop_function_query = """CREATE FUNCTION IF NOT EXISTS Crop
×
86
                INPUT  (Frame_Array NDARRAY UINT8(3, ANYDIM, ANYDIM),
87
                        bboxes NDARRAY FLOAT32(ANYDIM, 4))
88
                OUTPUT (Cropped_Frame_Array NDARRAY UINT8(3, ANYDIM, ANYDIM))
89
                TYPE  NdarrayFunction
90
                IMPL  "{}/functions/{}/crop.py";
91
        """.format(
92
    EvaDB_INSTALLATION_DIR, NDARRAY_DIR
93
)
94

95
Open_function_query = """CREATE FUNCTION IF NOT EXISTS Open
×
96
                INPUT (img_path TEXT(1000))
97
                OUTPUT (data NDARRAY UINT8(3, ANYDIM, ANYDIM))
98
                TYPE NdarrayFunction
99
                IMPL "{}/functions/{}/open.py";
100
        """.format(
101
    EvaDB_INSTALLATION_DIR, NDARRAY_DIR
102
)
103

104
Similarity_function_query = """CREATE FUNCTION IF NOT EXISTS Similarity
×
105
                    INPUT (Frame_Array_Open NDARRAY UINT8(3, ANYDIM, ANYDIM),
106
                           Frame_Array_Base NDARRAY UINT8(3, ANYDIM, ANYDIM),
107
                           Feature_Extractor_Name TEXT(100))
108
                    OUTPUT (distance FLOAT(32, 7))
109
                    TYPE NdarrayFunction
110
                    IMPL "{}/functions/{}/similarity.py";
111
        """.format(
112
    EvaDB_INSTALLATION_DIR, NDARRAY_DIR
113
)
114

115
Unnest_function_query = """CREATE FUNCTION IF NOT EXISTS Unnest
×
116
                INPUT  (inp NDARRAY ANYTYPE)
117
                OUTPUT (out ANYTYPE)
118
                TYPE  NdarrayFunction
119
                IMPL  "{}/functions/{}/unnest.py";
120
        """.format(
121
    EvaDB_INSTALLATION_DIR, NDARRAY_DIR
122
)
123

124
Fastrcnn_function_query = """CREATE FUNCTION IF NOT EXISTS FastRCNNObjectDetector
×
125
      INPUT  (Frame_Array NDARRAY UINT8(3, ANYDIM, ANYDIM))
126
      OUTPUT (labels NDARRAY STR(ANYDIM), bboxes NDARRAY FLOAT32(ANYDIM, 4),
127
                scores NDARRAY FLOAT32(ANYDIM))
128
      TYPE  Classification
129
      IMPL  '{}/functions/fastrcnn_object_detector.py';
130
      """.format(
131
    EvaDB_INSTALLATION_DIR
132
)
133

134
Yolo_function_query = """CREATE FUNCTION IF NOT EXISTS Yolo
×
135
      TYPE  ultralytics
136
      MODEL 'yolov8m.pt';
137
      """
138

139
face_detection_function_query = """CREATE FUNCTION IF NOT EXISTS FaceDetector
×
140
                  INPUT  (frame NDARRAY UINT8(3, ANYDIM, ANYDIM))
141
                  OUTPUT (bboxes NDARRAY FLOAT32(ANYDIM, 4),
142
                          scores NDARRAY FLOAT32(ANYDIM))
143
                  TYPE  FaceDetection
144
                  IMPL  '{}/functions/face_detector.py';
145
        """.format(
146
    EvaDB_INSTALLATION_DIR
147
)
148

149
Mvit_function_query = """CREATE FUNCTION IF NOT EXISTS MVITActionRecognition
×
150
        INPUT  (Frame_Array NDARRAY UINT8(3, 16, 224, 224))
151
        OUTPUT (labels NDARRAY STR(ANYDIM))
152
        TYPE  Classification
153
        IMPL  '{}/functions/mvit_action_recognition.py';
154
        """.format(
155
    EvaDB_INSTALLATION_DIR
156
)
157

158
Asl_function_query = """CREATE FUNCTION IF NOT EXISTS ASLActionRecognition
×
159
        INPUT  (Frame_Array NDARRAY UINT8(3, 16, 224, 224))
160
        OUTPUT (labels NDARRAY STR(ANYDIM))
161
        TYPE  Classification
162
        IMPL  '{}/functions/asl_action_recognition.py';
163
        """.format(
164
    EvaDB_INSTALLATION_DIR
165
)
166

167
norfair_obj_tracker_query = """CREATE FUNCTION IF NOT EXISTS NorFairTracker
×
168
                  IMPL  '{}/functions/trackers/nor_fair.py';
169
        """.format(
170
    EvaDB_INSTALLATION_DIR
171
)
172

173
Sift_function_query = """CREATE FUNCTION IF NOT EXISTS SiftFeatureExtractor
×
174
        IMPL  '{}/functions/sift_feature_extractor.py';
175
        """.format(
176
    EvaDB_INSTALLATION_DIR
177
)
178

179
Text_feat_function_query = """CREATE FUNCTION IF NOT EXISTS SentenceFeatureExtractor
×
180
        IMPL  '{}/functions/sentence_feature_extractor.py';
181
        """.format(
182
    EvaDB_INSTALLATION_DIR
183
)
184

185
mnistcnn_function_query = """CREATE FUNCTION IF NOT EXISTS MnistImageClassifier
×
186
        INPUT  (data NDARRAY (3, 28, 28))
187
        OUTPUT (label TEXT(2))
188
        TYPE  Classification
189
        IMPL  '{}/functions/mnist_image_classifier.py';
190
        """.format(
191
    EvaDB_INSTALLATION_DIR
192
)
193

194
chatgpt_function_query = """CREATE FUNCTION IF NOT EXISTS ChatGPT
×
195
        IMPL '{}/functions/chatgpt.py';
196
        """.format(
197
    EvaDB_INSTALLATION_DIR
198
)
199

200
yolo8n_query = """CREATE FUNCTION IF NOT EXISTS Yolo
×
201
            TYPE  ultralytics
202
            MODEL 'yolov8n.pt';
203
        """
204

205

206
def init_builtin_functions(db: EvaDBDatabase, mode: str = "debug") -> None:
×
207
    """Load the built-in functions into the system during system bootstrapping.
208

209
    The function loads a set of pre-defined function queries based on the `mode` argument.
210
    In 'debug' mode, the function loads debug functions along with release functions.
211
    In 'release' mode, only release functions are loaded. In addition, in 'debug' mode,
212
    the function loads a smaller model to accelerate the test suite time.
213

214
    Args:G
215
        mode (str, optional): The mode for loading functions, either 'debug' or 'release'.
216
        Defaults to 'debug'.
217

218
    """
219

220
    # Attempting to import torch module
221
    # It is necessary to import torch before to avoid encountering a
222
    # "RuntimeError: random_device could not be read"
223
    # The suspicion is that importing torch prior to decord resolves this issue
224
    try:
×
225
        import torch  # noqa: F401
×
226
    except ImportError:
227
        pass
228

229
    # Enable environment variables
230
    # Relevant for transformer-based models
231
    import os
×
232

233
    os.environ["PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION"] = "python"
×
234
    os.environ["TOKENIZERS_PARALLELISM"] = "false"
×
235

236
    # list of function queries to load
237
    queries = [
×
238
        mnistcnn_function_query,
239
        Fastrcnn_function_query,
240
        ArrayCount_function_query,
241
        Crop_function_query,
242
        Open_function_query,
243
        Similarity_function_query,
244
        norfair_obj_tracker_query,
245
        chatgpt_function_query,
246
        face_detection_function_query,
247
        # Mvit_function_query,
248
        Sift_function_query,
249
        Yolo_function_query,
250
    ]
251

252
    # if mode is 'debug', add debug functions
253
    if mode == "debug":
×
254
        queries.extend(
×
255
            [
256
                DummyObjectDetector_function_query,
257
                DummyMultiObjectDetector_function_query,
258
                DummyFeatureExtractor_function_query,
259
                DummyNoInputFunction_function_query,
260
                DummyLLM_function_query,
261
            ]
262
        )
263

264
    # execute each query in the list of function queries
265
    # ignore exceptions during the bootstrapping phase due to missing packages
266
    for query in queries:
×
267
        try:
×
268
            execute_query_fetch_all(
269
                db, query, do_not_print_exceptions=False, do_not_raise_exceptions=True
270
            )
271
        except Exception:
272
            pass
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