A representation of the structure of a SQL SELECT query. Only the select_clause and from_clause are required for a valid query.
| 99 | |
| 100 | |
| 101 | class Query(AbstractStatement): |
| 102 | # TODO: This has to be called Query for as long as we want to unpickle old reports, or |
| 103 | # we have to get into the legalese weeds. See: |
| 104 | # https://gerrit.cloudera.org/#/c/5162/5/tests/comparison/query.py@61 |
| 105 | # https://gerrit.cloudera.org/#/c/5162/1/tests/comparison/leopard/custom_pickle.py@9 |
| 106 | # If we decide at some point we don't need to unpickle some of the recent reports, |
| 107 | # then this can be renamed to something like SelectStatement. |
| 108 | """ |
| 109 | A representation of the structure of a SQL SELECT query. Only the select_clause and |
| 110 | from_clause are required for a valid query. |
| 111 | """ |
| 112 | |
| 113 | def __init__(self): |
| 114 | super(Query, self).__init__() |
| 115 | self.select_clause = None |
| 116 | self.from_clause = None |
| 117 | self.where_clause = None |
| 118 | self.group_by_clause = None |
| 119 | self.having_clause = None |
| 120 | self.union_clause = None |
| 121 | self.order_by_clause = None |
| 122 | self.limit_clause = None |
| 123 | # This is a fine default value, because any well-formed object will be a SELECT |
| 124 | # statement. Only the discrepancy searcher makes the decision at run time to change |
| 125 | # this. |
| 126 | self.execution = StatementExecutionMode.SELECT_STATEMENT |
| 127 | |
| 128 | def __deepcopy__(self, memo): |
| 129 | other = Query() |
| 130 | memo[self] = other |
| 131 | other.parent = memo[self.parent] if self.parent in memo else None |
| 132 | other.with_clause = deepcopy(self.with_clause, memo) |
| 133 | other.execution = self.execution |
| 134 | other.from_clause = deepcopy(self.from_clause, memo) |
| 135 | other.select_clause = deepcopy(self.select_clause, memo) |
| 136 | other.where_clause = deepcopy(self.where_clause, memo) |
| 137 | other.group_by_clause = deepcopy(self.group_by_clause, memo) |
| 138 | other.having_clause = deepcopy(self.having_clause, memo) |
| 139 | other.union_clause = deepcopy(self.union_clause, memo) |
| 140 | other.order_by_clause = deepcopy(self.order_by_clause, memo) |
| 141 | other.limit_clause = deepcopy(self.limit_clause, memo) |
| 142 | return other |
| 143 | |
| 144 | @property |
| 145 | def table_exprs(self): |
| 146 | '''Provides a list of all table_exprs that are declared by this query. This |
| 147 | includes table_exprs in the WITH and FROM sections. |
| 148 | ''' |
| 149 | table_exprs = super(Query, self).table_exprs # WITH clause |
| 150 | table_exprs.extend(self.from_clause.table_exprs) |
| 151 | return table_exprs |
| 152 | |
| 153 | @property |
| 154 | def is_unioned_query(self): |
| 155 | return self.parent \ |
| 156 | and self.parent.union_clause \ |
| 157 | and self.parent.union_clause.query is self |
| 158 |
no outgoing calls