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

georgia-tech-db / eva / #758

04 Sep 2023 08:37PM UTC coverage: 0.0% (-78.3%) from 78.333%
#758

push

circle-ci

hershd23
Increased underline length in at line 75 in text_summarization.rst
	modified:   docs/source/benchmarks/text_summarization.rst

0 of 11303 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/parser/lark_visitor/_functions.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 lark import Token, Tree
×
17

18
from evadb.expression.abstract_expression import ExpressionType
×
19
from evadb.expression.aggregation_expression import AggregationExpression
×
20
from evadb.expression.constant_value_expression import ConstantValueExpression
×
21
from evadb.expression.function_expression import FunctionExpression
×
22
from evadb.expression.tuple_value_expression import TupleValueExpression
×
23
from evadb.parser.create_udf_statement import CreateUDFStatement
×
24

25

26
##################################################################
27
# Functions - UDFs, Aggregate Windowed functions
28
##################################################################
29
class Functions:
×
30
    def udf_function(self, tree):
×
31
        udf_name = None
×
32
        udf_output = None
×
33
        udf_args = None
×
34

35
        for child in tree.children:
×
36
            if isinstance(child, Token):
×
37
                if child.value == "*":
×
38
                    udf_args = [TupleValueExpression(name="*")]
×
39
            if isinstance(child, Tree):
×
40
                if child.data == "simple_id":
×
41
                    udf_name = self.visit(child)
×
42
                elif child.data == "dotted_id":
×
43
                    udf_output = self.visit(child)
×
44
                elif child.data == "function_args":
×
45
                    udf_args = self.visit(child)
×
46

47
        func_expr = FunctionExpression(None, name=udf_name, output=udf_output)
×
48
        for arg in udf_args:
×
49
            func_expr.append_child(arg)
×
50

51
        return func_expr
×
52

53
    def function_args(self, tree):
×
54
        args = []
×
55
        for child in tree.children:
×
56
            if isinstance(child, Tree):
×
57
                args.append(self.visit(child))
×
58
        return args
×
59

60
    # Create UDF
61
    def create_udf(self, tree):
×
62
        udf_name = None
×
63
        if_not_exists = False
×
64
        input_definitions = []
×
65
        output_definitions = []
×
66
        impl_path = None
×
67
        udf_type = None
×
68
        query = None
×
69
        metadata = []
×
70

71
        create_definitions_index = 0
×
72
        for child in tree.children:
×
73
            if isinstance(child, Tree):
×
74
                if child.data == "udf_name":
×
75
                    udf_name = self.visit(child)
×
76
                elif child.data == "if_not_exists":
×
77
                    if_not_exists = True
×
78
                elif child.data == "create_definitions":
×
79
                    # There should be 2 createDefinition
80
                    # idx 0 describing udf INPUT
81
                    # idx 1 describing udf OUTPUT
82
                    if create_definitions_index == 0:
×
83
                        input_definitions = self.visit(child)
×
84
                        create_definitions_index += 1
×
85
                    elif create_definitions_index == 1:
×
86
                        output_definitions = self.visit(child)
×
87
                elif child.data == "udf_type":
×
88
                    udf_type = self.visit(child)
×
89
                elif child.data == "udf_impl":
×
90
                    impl_path = self.visit(child).value
×
91
                elif child.data == "simple_select":
×
92
                    query = self.visit(child)
×
93
                elif child.data == "udf_metadata":
×
94
                    # Each UDF metadata is a key value pair
95
                    key_value_pair = self.visit(child)
×
96
                    # value can be an integer or string
97
                    value = key_value_pair[1]
×
98
                    if isinstance(value, ConstantValueExpression):
×
99
                        value = value.value
×
100
                    # Removing .value from key_value_pair[0] since key is now an ID_LITERAL
101
                    # Adding lower() to ensure the key is in lowercase
102
                    metadata.append((key_value_pair[0].lower(), value)),
×
103

104
        return CreateUDFStatement(
×
105
            udf_name,
106
            if_not_exists,
107
            impl_path,
108
            input_definitions,
109
            output_definitions,
110
            udf_type,
111
            query,
112
            metadata,
113
        )
114

115
    def get_aggregate_function_type(self, agg_func_name):
×
116
        agg_func_type = None
×
117
        if agg_func_name == "COUNT":
×
118
            agg_func_type = ExpressionType.AGGREGATION_COUNT
×
119
        elif agg_func_name == "MIN":
×
120
            agg_func_type = ExpressionType.AGGREGATION_MIN
×
121
        elif agg_func_name == "MAX":
×
122
            agg_func_type = ExpressionType.AGGREGATION_MAX
×
123
        elif agg_func_name == "SUM":
×
124
            agg_func_type = ExpressionType.AGGREGATION_SUM
×
125
        elif agg_func_name == "AVG":
×
126
            agg_func_type = ExpressionType.AGGREGATION_AVG
×
127
        elif agg_func_name == "FIRST":
×
128
            agg_func_type = ExpressionType.AGGREGATION_FIRST
×
129
        elif agg_func_name == "LAST":
×
130
            agg_func_type = ExpressionType.AGGREGATION_LAST
×
131
        elif agg_func_name == "SEGMENT":
×
132
            agg_func_type = ExpressionType.AGGREGATION_SEGMENT
×
133
        return agg_func_type
×
134

135
    def aggregate_windowed_function(self, tree):
×
136
        agg_func_arg = None
×
137
        agg_func_name = None
×
138

139
        for child in tree.children:
×
140
            if isinstance(child, Tree):
×
141
                if child.data == "function_arg":
×
142
                    agg_func_arg = self.visit(child)
×
143
                elif child.data == "aggregate_function_name":
×
144
                    agg_func_name = self.visit(child).value
×
145
            elif isinstance(child, Token):
×
146
                token = child.value
×
147
                # Support for COUNT(*)
148
                if token != "*":
×
149
                    agg_func_name = token
×
150
                else:
151
                    agg_func_arg = TupleValueExpression(name="id")
×
152

153
        agg_func_type = self.get_aggregate_function_type(agg_func_name)
×
154
        agg_expr = AggregationExpression(agg_func_type, None, agg_func_arg)
×
155
        return agg_expr
×
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