Revision 2902
Added by Aaron Marcuse-Kubitza over 12 years ago
lib/sql_gen.py | ||
---|---|---|
153 | 153 |
def is_underlying_table(table): |
154 | 154 |
return isinstance(table, Table) and table.to_Table() is table |
155 | 155 |
|
156 |
class NoUnderlyingTableException(Exception): pass |
|
157 |
|
|
158 |
def underlying_table(table): |
|
159 |
table = remove_table_rename(table) |
|
160 |
if not is_underlying_table(table): raise NoUnderlyingTableException |
|
161 |
return table |
|
162 |
|
|
156 | 163 |
def as_Table(table, schema=None): |
157 | 164 |
if table == None or isinstance(table, Code): return table |
158 | 165 |
else: return Table(table, schema) |
... | ... | |
260 | 267 |
if isinstance(col, NamedCol): col = col.code |
261 | 268 |
return col |
262 | 269 |
|
263 |
class NoUnderlyingTableException(Exception): pass |
|
264 |
|
|
265 | 270 |
def underlying_col(col): |
266 | 271 |
col = remove_col_rename(col) |
267 | 272 |
if not isinstance(col, Col): raise NoUnderlyingTableException |
268 | 273 |
|
269 |
table = remove_table_rename(col.table) |
|
270 |
if not is_underlying_table(table): raise NoUnderlyingTableException |
|
271 |
|
|
272 |
return Col(col.name, table, col.srcs) |
|
274 |
return Col(col.name, underlying_table(col.table), col.srcs) |
|
273 | 275 |
|
274 | 276 |
def wrap(wrap_func, value): |
275 | 277 |
'''Wraps a value, propagating any column renaming to the returned value.''' |
Also available in: Unified diff
sql_gen.py: Added underlying_table() and use it in underlying_col()