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

georgia-tech-db / eva / e6161546-9e33-42e7-a2b6-f8fbe6aa8255

08 Sep 2023 02:22AM UTC coverage: 80.449% (-12.5%) from 92.929%
e6161546-9e33-42e7-a2b6-f8fbe6aa8255

push

circle-ci

jiashenC
fix lint

13 of 13 new or added lines in 8 files covered. (100.0%)

9398 of 11682 relevant lines covered (80.45%)

1.45 hits per line

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

95.59
/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
2✔
16
from typing import List, Tuple
2✔
17

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

23

24
class CreateFunctionStatement(AbstractStatement):
2✔
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__(
2✔
50
        self,
51
        name: str,
52
        if_not_exists: bool,
53
        impl_path: str,
54
        inputs: List[ColumnDefinition] = [],
55
        outputs: List[ColumnDefinition] = [],
56
        function_type: str = None,
57
        query: SelectStatement = None,
58
        metadata: List[Tuple[str, str]] = None,
59
    ):
60
        super().__init__(StatementType.CREATE_FUNCTION)
2✔
61
        self._name = name
2✔
62
        self._if_not_exists = if_not_exists
2✔
63
        self._inputs = inputs
2✔
64
        self._outputs = outputs
2✔
65
        self._impl_path = Path(impl_path) if impl_path else None
2✔
66
        self._function_type = function_type
2✔
67
        self._query = query
2✔
68
        self._metadata = metadata
2✔
69

70
    def __str__(self) -> str:
2✔
71
        s = "CREATE FUNCTION"
1✔
72

73
        if self._if_not_exists:
1✔
74
            s += " IF NOT EXISTS"
1✔
75

76
        s += " " + self._name
1✔
77

78
        if self._query is not None:
1✔
79
            s += f" FROM ({self._query})"
×
80

81
        if self._function_type is not None:
1✔
82
            s += " TYPE " + str(self._function_type)
1✔
83

84
        if self._impl_path:
1✔
85
            s += f" IMPL {self._impl_path.name}"
1✔
86

87
        if self._metadata is not None:
1✔
88
            for key, value in self._metadata:
1✔
89
                # NOTE :- Removing quotes around key and making it upper case
90
                # Since in tests we are doing a straight string comparison
91
                s += f" {key.upper()} '{value}'"
1✔
92
        return s
1✔
93

94
    @property
2✔
95
    def name(self):
2✔
96
        return self._name
2✔
97

98
    @property
2✔
99
    def if_not_exists(self):
2✔
100
        return self._if_not_exists
2✔
101

102
    @property
2✔
103
    def inputs(self):
2✔
104
        return self._inputs
2✔
105

106
    @inputs.setter
2✔
107
    def inputs(self, value):
2✔
108
        self._inputs = value
×
109

110
    @property
2✔
111
    def outputs(self):
2✔
112
        return self._outputs
2✔
113

114
    @outputs.setter
2✔
115
    def outputs(self, value):
2✔
116
        self._outputs = value
×
117

118
    @property
2✔
119
    def impl_path(self):
2✔
120
        return self._impl_path
2✔
121

122
    @property
2✔
123
    def function_type(self):
2✔
124
        return self._function_type
2✔
125

126
    @property
2✔
127
    def query(self):
2✔
128
        return self._query
2✔
129

130
    @property
2✔
131
    def metadata(self):
2✔
132
        return self._metadata
2✔
133

134
    def __eq__(self, other):
2✔
135
        if not isinstance(other, CreateFunctionStatement):
1✔
136
            return False
1✔
137
        return (
1✔
138
            self.name == other.name
139
            and self.if_not_exists == other.if_not_exists
140
            and self.inputs == other.inputs
141
            and self.outputs == other.outputs
142
            and self.impl_path == other.impl_path
143
            and self.function_type == other.function_type
144
            and self.query == other.query
145
            and self.metadata == other.metadata
146
        )
147

148
    def __hash__(self) -> int:
2✔
149
        return hash(
1✔
150
            (
151
                super().__hash__(),
152
                self.name,
153
                self.if_not_exists,
154
                tuple(self.inputs),
155
                tuple(self.outputs),
156
                self.impl_path,
157
                self.function_type,
158
                self.query,
159
                tuple(self.metadata),
160
            )
161
        )
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