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

georgia-tech-db / eva / #754

04 Sep 2023 09:54PM UTC coverage: 74.807% (-5.5%) from 80.336%
#754

push

circle-ci

jiashenC
update case

8727 of 11666 relevant lines covered (74.81%)

0.75 hits per line

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

79.49
/evadb/parser/lark_visitor/_expressions.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
import numpy as np
1✔
16
from lark import Tree
1✔
17

18
from evadb.catalog.catalog_type import ColumnType
1✔
19
from evadb.expression.abstract_expression import ExpressionType
1✔
20
from evadb.expression.comparison_expression import ComparisonExpression
1✔
21
from evadb.expression.constant_value_expression import ConstantValueExpression
1✔
22
from evadb.expression.logical_expression import LogicalExpression
1✔
23

24

25
##################################################################
26
# EXPRESSIONS
27
##################################################################
28
class Expressions:
1✔
29
    def string_literal(self, tree):
1✔
30
        text = tree.children[0]
1✔
31
        assert text is not None
1✔
32
        return ConstantValueExpression(text[1:-1], ColumnType.TEXT)
1✔
33

34
    def array_literal(self, tree):
1✔
35
        array_elements = []
1✔
36
        for child in tree.children:
1✔
37
            if isinstance(child, Tree):
1✔
38
                array_element = self.visit(child).value
1✔
39
                array_elements.append(array_element)
1✔
40

41
        res = ConstantValueExpression(np.array(array_elements), ColumnType.NDARRAY)
1✔
42
        return res
1✔
43

44
    def constant(self, tree):
1✔
45
        for child in tree.children:
1✔
46
            if isinstance(child, Tree):
1✔
47
                if child.data == "real_literal":
1✔
48
                    real_literal = self.visit(child)
1✔
49
                    return ConstantValueExpression(real_literal, ColumnType.FLOAT)
1✔
50
                elif child.data == "decimal_literal":
1✔
51
                    decimal_literal = self.visit(child)
1✔
52
                    return ConstantValueExpression(decimal_literal, ColumnType.INTEGER)
1✔
53

54
        return self.visit_children(tree)
1✔
55

56
    def logical_expression(self, tree):
1✔
57
        left = self.visit(tree.children[0])
1✔
58
        op = self.visit(tree.children[1])
1✔
59
        right = self.visit(tree.children[2])
1✔
60
        return LogicalExpression(op, left, right)
1✔
61

62
    def binary_comparison_predicate(self, tree):
1✔
63
        left = self.visit(tree.children[0])
1✔
64
        op = self.visit(tree.children[1])
1✔
65
        right = self.visit(tree.children[2])
1✔
66
        return ComparisonExpression(op, left, right)
1✔
67

68
    def nested_expression_atom(self, tree):
1✔
69
        # Todo Can there be >1 expression in this case
70
        expr = tree.children[0]
1✔
71
        return self.visit(expr)
1✔
72

73
    def comparison_operator(self, tree):
1✔
74
        op = str(tree.children[0])
1✔
75

76
        if op == "=":
1✔
77
            return ExpressionType.COMPARE_EQUAL
1✔
78
        elif op == "<":
1✔
79
            return ExpressionType.COMPARE_LESSER
1✔
80
        elif op == ">":
1✔
81
            return ExpressionType.COMPARE_GREATER
1✔
82
        elif op == ">=":
1✔
83
            return ExpressionType.COMPARE_GEQ
×
84
        elif op == "<=":
1✔
85
            return ExpressionType.COMPARE_LEQ
1✔
86
        elif op == "!=":
1✔
87
            return ExpressionType.COMPARE_NEQ
1✔
88
        elif op == "@>":
×
89
            return ExpressionType.COMPARE_CONTAINS
×
90
        elif op == "<@":
×
91
            return ExpressionType.COMPARE_IS_CONTAINED
×
92
        elif op == "LIKE":
×
93
            return ExpressionType.COMPARE_LIKE
×
94

95
    def logical_operator(self, tree):
1✔
96
        op = str(tree.children[0])
1✔
97

98
        if op == "OR":
1✔
99
            return ExpressionType.LOGICAL_OR
1✔
100
        elif op == "AND":
1✔
101
            return ExpressionType.LOGICAL_AND
1✔
102

103
    def expressions_with_defaults(self, tree):
1✔
104
        expr_list = []
1✔
105
        for child in tree.children:
1✔
106
            if isinstance(child, Tree):
1✔
107
                if child.data == "expression_or_default":
1✔
108
                    expression = self.visit(child)
1✔
109
                    expr_list.append(expression)
1✔
110
        return expr_list
1✔
111

112
    def sample_params(self, tree):
1✔
113
        sample_type = None
1✔
114
        sample_freq = None
1✔
115
        for child in tree.children:
1✔
116
            if child.data == "sample_clause":
1✔
117
                sample_freq = self.visit(child)
1✔
118
            elif child.data == "sample_clause_with_type":
×
119
                sample_type, sample_freq = self.visit(child)
×
120
        return sample_type, sample_freq
1✔
121

122
    def sample_clause(self, tree):
1✔
123
        sample_list = self.visit_children(tree)
1✔
124
        assert len(sample_list) == 2
1✔
125
        return ConstantValueExpression(sample_list[1])
1✔
126

127
    def sample_clause_with_type(self, tree):
1✔
128
        sample_list = self.visit_children(tree)
×
129
        assert len(sample_list) == 3 or len(sample_list) == 2
×
130
        if len(sample_list) == 3:
×
131
            return ConstantValueExpression(sample_list[1]), ConstantValueExpression(
×
132
                sample_list[2]
133
            )
134
        else:
135
            return ConstantValueExpression(sample_list[1]), ConstantValueExpression(1)
×
136

137
    def chunk_params(self, tree):
1✔
138
        chunk_params = self.visit_children(tree)
×
139
        assert len(chunk_params) == 2 or len(chunk_params) == 4
×
140
        if len(chunk_params) == 4:
×
141
            return {
×
142
                "chunk_size": ConstantValueExpression(chunk_params[1]),
143
                "chunk_overlap": ConstantValueExpression(chunk_params[3]),
144
            }
145

146
        elif len(chunk_params) == 2:
×
147
            if chunk_params[0] == "CHUNK_SIZE":
×
148
                return {
×
149
                    "chunk_size": ConstantValueExpression(chunk_params[1]),
150
                }
151
            elif chunk_params[0] == "CHUNK_OVERLAP":
×
152
                return {
×
153
                    "chunk_overlap": ConstantValueExpression(chunk_params[1]),
154
                }
155
            else:
156
                assert f"incorrect keyword found {chunk_params[0]}"
×
157

158
    def colon_param_dict(self, tree):
1✔
159
        param_dict = {}
1✔
160
        for child in tree.children:
1✔
161
            if isinstance(child, Tree):
1✔
162
                if child.data == "colon_param":
1✔
163
                    param = self.visit(child)
1✔
164
                    key = param[0].value
1✔
165
                    value = param[1].value
1✔
166
                    param_dict[key] = value
1✔
167
        return param_dict
1✔
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