Skip to content

Commit

Permalink
restrict ORDER BY args to (unqualified) column refs to emit schema
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobin Baker committed Aug 27, 2017
1 parent caedfb9 commit fe87d73
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 14 deletions.
8 changes: 1 addition & 7 deletions raco/backends/myria/myria.py
Original file line number Diff line number Diff line change
Expand Up @@ -598,16 +598,10 @@ def compileme(self, inputid):
class MyriaInMemoryOrderBy(algebra.OrderBy, MyriaOperator):

def compileme(self, inputsym):
# In principle, MyriaL supports arbitrary scalar expressions
# as ORDER BY arguments, but MyriaX can only handle column references.
assert all(isinstance(col, AttributeRef)
for col in self.sort_columns),\
"Myria supports only column references as ORDER BY arguments."
return {
"opType": "InMemoryOrderBy",
"argChild": inputsym,
"argSortColumns": [col.get_position(self.scheme())
for col in self.sort_columns],
"argSortColumns": [col.position for col in self.sort_columns],
"argAscending": self.ascending
}

Expand Down
8 changes: 4 additions & 4 deletions raco/myrial/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,11 +257,11 @@ def bagcomp(self, from_clause, where_clause, emit_clause,
if limit_clause is None:
raise InvalidStatementException(
"An ORDER BY clause must be accompanied by a LIMIT clause")
orderby_exprs, orderby_ords = zip(*orderby_clause)
orderby_exprs = [multiway.rewrite_refs(sexpr, from_args, info)
for sexpr in orderby_exprs]
orderby_cols, orderby_ords = zip(*orderby_clause)
orderby_cols = [get_unnamed_ref(col, op.scheme())
for col in orderby_cols]
op = raco.algebra.OrderBy(input=op,
sort_columns=orderby_exprs,
sort_columns=orderby_cols,
ascending=orderby_ords)

if limit_clause:
Expand Down
6 changes: 3 additions & 3 deletions raco/myrial/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -812,9 +812,9 @@ def p_explicit_orderby_list(p):

@staticmethod
def p_explicit_orderby_arg(p):
"""orderby_arg : sexpr ASC
| sexpr DESC
| sexpr"""
"""orderby_arg : column_ref ASC
| column_ref DESC
| column_ref"""
if len(p) == 3 and p[2] == 'ASC':
p[0] = (p[1], True)
if len(p) == 3 and p[2] == 'DESC':
Expand Down

0 comments on commit fe87d73

Please sign in to comment.