• 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/select_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 __future__ import annotations
×
16

17
import typing
×
18
from typing import List, Union
×
19

20
if typing.TYPE_CHECKING:
21
    from evadb.parser.table_ref import TableRef
22

23
from evadb.expression.abstract_expression import AbstractExpression
×
24
from evadb.parser.statement import AbstractStatement
×
25
from evadb.parser.types import ParserOrderBySortType, StatementType
×
26

27

28
class SelectStatement(AbstractStatement):
×
29
    """
30
    Select Statement constructed after parsing the input query
31

32
    Attributes
33
    ----------
34
    _target_list : List[AbstractExpression]
35
        list of target attributes in the select query,
36
        each attribute is represented as a Abstract Expression
37
    _from_table : TableRef | Select Statement
38
        table reference in the select query, can be a select statement
39
        in nested queries
40
    _where_clause : AbstractExpression
41
        predicate of the select query, represented as a expression tree.
42
    **kwargs : to support other functionality, Orderby, Distinct, Groupby.
43
    """
44

45
    def __init__(
×
46
        self,
47
        target_list: List[AbstractExpression] = None,
48
        from_table: Union[TableRef, SelectStatement] = None,
49
        where_clause: AbstractExpression = None,
50
        **kwargs,
51
    ):
52
        super().__init__(StatementType.SELECT)
×
53
        self._from_table = from_table
×
54
        self._where_clause = where_clause
×
55
        self._target_list = target_list
×
56
        self._union_link = None
×
57
        self._union_all = False
×
58
        self._groupby_clause = kwargs.get("groupby_clause", None)
×
59
        self._orderby_list = kwargs.get("orderby_list", None)
×
60
        self._limit_count = kwargs.get("limit_count", None)
×
61

62
    @property
×
63
    def union_link(self):
×
64
        return self._union_link
×
65

66
    @union_link.setter
×
67
    def union_link(self, next_select: "SelectStatement"):
×
68
        self._union_link = next_select
×
69

70
    @property
×
71
    def union_all(self):
×
72
        return self._union_all
×
73

74
    @union_all.setter
×
75
    def union_all(self, all: bool):
×
76
        self._union_all = all
×
77

78
    @property
×
79
    def where_clause(self):
×
80
        return self._where_clause
×
81

82
    @where_clause.setter
×
83
    def where_clause(self, where_expr: AbstractExpression):
×
84
        self._where_clause = where_expr
×
85

86
    @property
×
87
    def target_list(self):
×
88
        return self._target_list
×
89

90
    @target_list.setter
×
91
    def target_list(self, target_expr_list: List[AbstractExpression]):
×
92
        self._target_list = target_expr_list
×
93

94
    @property
×
95
    def from_table(self):
×
96
        return self._from_table
×
97

98
    @from_table.setter
×
99
    def from_table(self, table: TableRef):
×
100
        self._from_table = table
×
101

102
    @property
×
103
    def groupby_clause(self):
×
104
        return self._groupby_clause
×
105

106
    @groupby_clause.setter
×
107
    def groupby_clause(self, groupby_clause):
×
108
        self._groupby_clause = groupby_clause
×
109

110
    @property
×
111
    def orderby_list(self):
×
112
        return self._orderby_list
×
113

114
    @orderby_list.setter
×
115
    def orderby_list(self, orderby_list):
×
116
        self._orderby_list = orderby_list
×
117

118
    @property
×
119
    def limit_count(self):
×
120
        return self._limit_count
×
121

122
    @limit_count.setter
×
123
    def limit_count(self, limit_count):
×
124
        self._limit_count = limit_count
×
125

126
    def __str__(self) -> str:
×
127
        target_list_str = ""
×
128
        if self._target_list is not None:
×
129
            for expr in self._target_list:
×
130
                target_list_str += str(expr) + ", "
×
131
            target_list_str = target_list_str.rstrip(", ")
×
132

133
        orderby_list_str = ""
×
134
        if self._orderby_list is not None:
×
135
            for expr in self._orderby_list:
×
136
                sort_str = ""
×
137
                if expr[1] == ParserOrderBySortType.ASC:
×
138
                    sort_str = "ASC"
×
139
                elif expr[1] == ParserOrderBySortType.DESC:
×
140
                    sort_str = "DESC"
×
141
                orderby_list_str += str(expr[0]) + " " + sort_str + ", "
×
142
            orderby_list_str = orderby_list_str.rstrip(", ")
×
143

144
        select_str = f"SELECT {target_list_str} FROM {str(self._from_table)}"
×
145
        if self._where_clause is not None:
×
146
            select_str += " WHERE " + str(self._where_clause)
×
147

148
        if self._union_link is not None:
×
149
            if not self._union_all:
×
150
                select_str += " UNION " + str(self._union_link)
×
151
            else:
152
                select_str += " UNION ALL " + str(self._union_link)
×
153

154
        if self._groupby_clause is not None:
×
155
            select_str += " GROUP BY " + str(self._groupby_clause)
×
156

157
        if self._orderby_list is not None:
×
158
            select_str += " ORDER BY " + orderby_list_str
×
159

160
        if self._limit_count is not None:
×
161
            select_str += " LIMIT " + str(self._limit_count)
×
162

163
        select_str = select_str.rstrip(" ")
×
164

165
        return select_str
×
166

167
    def __eq__(self, other):
×
168
        if not isinstance(other, SelectStatement):
×
169
            return False
×
170
        return (
×
171
            self.from_table == other.from_table
172
            and self.target_list == other.target_list
173
            and self.where_clause == other.where_clause
174
            and self.union_link == other.union_link
175
            and self.union_all == other.union_all
176
            and self._groupby_clause == other.groupby_clause
177
            and self.orderby_list == other.orderby_list
178
            and self.limit_count == other.limit_count
179
        )
180

181
    def __hash__(self) -> int:
×
182
        return hash(
×
183
            (
184
                super().__hash__(),
185
                self.from_table,
186
                tuple(self.target_list or []),
187
                self.where_clause,
188
                self.union_link,
189
                self.union_all,
190
                self.groupby_clause,
191
                tuple(self.orderby_list or []),
192
                self.limit_count,
193
            )
194
        )
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