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

georgia-tech-db / eva / 2fdc9ac8-ccff-4e89-aebb-f7eb50cc437b

21 Sep 2023 05:23PM UTC coverage: 93.203% (+0.5%) from 92.73%
2fdc9ac8-ccff-4e89-aebb-f7eb50cc437b

push

circle-ci

web-flow
Merge branch 'georgia-tech-db:master' into master

462 of 462 new or added lines in 53 files covered. (100.0%)

11176 of 11991 relevant lines covered (93.2%)

0.93 hits per line

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

97.33
/evadb/parser/create_function_statement.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
from pathlib import Path
1✔
16
from typing import List, Tuple
1✔
17

18
from evadb.parser.create_statement import ColumnDefinition
1✔
19
from evadb.parser.select_statement import SelectStatement
1✔
20
from evadb.parser.statement import AbstractStatement
1✔
21
from evadb.parser.types import StatementType
1✔
22

23

24
class CreateFunctionStatement(AbstractStatement):
1✔
25
    """CreateFunctionStatement constructed after parsing the input query
26

27
    Attributes:
28
        name: str
29
            function_name provided by the user required
30
        if_not_exists: bool
31
            if true should throw an error if function with same name exists
32
            else will replace the existing
33
        inputs: List[ColumnDefinition]
34
            function inputs, represented similar to a table column definition
35
        outputs: List[ColumnDefinition]
36
            function outputs, represented similar to a table column definition
37
        impl_file_path: str
38
            file path which holds the implementation of the function.
39
            This file should be placed in the function directory and
40
            the path provided should be relative to the function dir.
41
        query: SelectStatement
42
            data source for the model train or fine tune.
43
        function_type: str
44
            function type. it can be object detection, classification etc.
45
        metadata: List[Tuple[str, str]]
46
            metadata, list of key value pairs used for storing metadata of functions, mostly used for advanced function types
47
    """
48

49
    def __init__(
1✔
50
        self,
51
        name: str,
52
        or_replace: bool,
53
        if_not_exists: bool,
54
        impl_path: str,
55
        inputs: List[ColumnDefinition] = [],
56
        outputs: List[ColumnDefinition] = [],
57
        function_type: str = None,
58
        query: SelectStatement = None,
59
        metadata: List[Tuple[str, str]] = None,
60
    ):
61
        super().__init__(StatementType.CREATE_FUNCTION)
1✔
62
        self._name = name
1✔
63
        self._or_replace = or_replace
1✔
64
        self._if_not_exists = if_not_exists
1✔
65
        self._inputs = inputs
1✔
66
        self._outputs = outputs
1✔
67
        self._impl_path = Path(impl_path) if impl_path else None
1✔
68
        self._function_type = function_type
1✔
69
        self._query = query
1✔
70
        self._metadata = metadata
1✔
71

72
    def __str__(self) -> str:
1✔
73
        s = "CREATE"
1✔
74

75
        if self._or_replace:
1✔
76
            s += " OR REPLACE"
×
77

78
        s += " " + "FUNCTION"
1✔
79

80
        if self._if_not_exists:
1✔
81
            s += " IF NOT EXISTS"
1✔
82

83
        s += " " + self._name
1✔
84

85
        if self._query is not None:
1✔
86
            s += f" FROM ({self._query})"
×
87

88
        if self._function_type is not None:
1✔
89
            s += " TYPE " + str(self._function_type)
1✔
90

91
        if self._impl_path:
1✔
92
            s += f" IMPL {self._impl_path.name}"
1✔
93

94
        if self._metadata is not None:
1✔
95
            for key, value in self._metadata:
1✔
96
                # NOTE :- Removing quotes around key and making it upper case
97
                # Since in tests we are doing a straight string comparison
98
                s += f" {key.upper()} '{value}'"
1✔
99
        return s
1✔
100

101
    @property
1✔
102
    def name(self):
1✔
103
        return self._name
1✔
104

105
    @property
1✔
106
    def or_replace(self):
1✔
107
        return self._or_replace
1✔
108

109
    @property
1✔
110
    def if_not_exists(self):
1✔
111
        return self._if_not_exists
1✔
112

113
    @property
1✔
114
    def inputs(self):
1✔
115
        return self._inputs
1✔
116

117
    @inputs.setter
1✔
118
    def inputs(self, value):
1✔
119
        self._inputs = value
1✔
120

121
    @property
1✔
122
    def outputs(self):
1✔
123
        return self._outputs
1✔
124

125
    @outputs.setter
1✔
126
    def outputs(self, value):
1✔
127
        self._outputs = value
1✔
128

129
    @property
1✔
130
    def impl_path(self):
1✔
131
        return self._impl_path
1✔
132

133
    @property
1✔
134
    def function_type(self):
1✔
135
        return self._function_type
1✔
136

137
    @property
1✔
138
    def query(self):
1✔
139
        return self._query
1✔
140

141
    @property
1✔
142
    def metadata(self):
1✔
143
        return self._metadata
1✔
144

145
    def __eq__(self, other):
1✔
146
        if not isinstance(other, CreateFunctionStatement):
1✔
147
            return False
1✔
148
        return (
1✔
149
            self.name == other.name
150
            and self.or_replace == other.or_replace
151
            and self.if_not_exists == other.if_not_exists
152
            and self.inputs == other.inputs
153
            and self.outputs == other.outputs
154
            and self.impl_path == other.impl_path
155
            and self.function_type == other.function_type
156
            and self.query == other.query
157
            and self.metadata == other.metadata
158
        )
159

160
    def __hash__(self) -> int:
1✔
161
        return hash(
1✔
162
            (
163
                super().__hash__(),
164
                self.name,
165
                self.or_replace,
166
                self.if_not_exists,
167
                tuple(self.inputs),
168
                tuple(self.outputs),
169
                self.impl_path,
170
                self.function_type,
171
                self.query,
172
                tuple(self.metadata),
173
            )
174
        )
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