Skip to content

Commit

Permalink
allow named and qualified column refs
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobin Baker committed Aug 27, 2017
1 parent 8536c6c commit caedfb9
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
11 changes: 8 additions & 3 deletions raco/backends/myria/myria.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@
from raco.backends.sql.catalog import SQLCatalog, PostgresSQLFunctionProvider
from raco.catalog import Catalog
from raco.datastructure.UnionFind import UnionFind
from raco.expression import UnnamedAttributeRef
from raco.expression import AttributeRef, UnnamedAttributeRef
from raco.expression import WORKERID, COUNTALL
from raco.representation import RepresentationProperties
from raco.rules import distributed_group_by, check_partition_equality
from raco.expression import util
from urlparse import urlparse

LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -599,10 +598,16 @@ 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": self.sort_columns,
"argSortColumns": [col.get_position(self.scheme())
for col in self.sort_columns],
"argAscending": self.ascending
}

Expand Down
4 changes: 2 additions & 2 deletions raco/expression/expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,8 +404,8 @@ def __repr__(self):
dbg=self.debug_info)

def __eq__(self, other):
return (other.__class__ == self.__class__
and other.position == self.position)
return (other.__class__ == self.__class__ and
other.position == self.position)

def __ne__(self, other):
return not self.__eq__(other)
Expand Down
8 changes: 5 additions & 3 deletions raco/myrial/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,12 @@ 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")
orderbyTuples = zip(*orderby_clause)
orderby_exprs, orderby_ords = zip(*orderby_clause)
orderby_exprs = [multiway.rewrite_refs(sexpr, from_args, info)
for sexpr in orderby_exprs]
op = raco.algebra.OrderBy(input=op,
sort_columns=orderbyTuples[0],
ascending=orderbyTuples[1])
sort_columns=orderby_exprs,
ascending=orderby_ords)

if limit_clause:
if orderby_clause is None:
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 : column_ref ASC
| column_ref DESC
| column_ref"""
"""orderby_arg : sexpr ASC
| sexpr DESC
| sexpr"""
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 caedfb9

Please sign in to comment.