diff --git a/raco/expression/expression.py b/raco/expression/expression.py index 376675c5..b206d9bf 100644 --- a/raco/expression/expression.py +++ b/raco/expression/expression.py @@ -350,14 +350,19 @@ def get_position(self, scheme, state_scheme=None): class UnnamedAttributeRef(AttributeRef): - def __init__(self, position): + def __init__(self, position, debug_info=None): + if debug_info is None: + debug_info = "${}".format(position) + self.debug_info = debug_info self.position = position def __str__(self): - return "$%s" % (self.position) + return "%s" % (self.debug_info) def __repr__(self): - return "{op}({pos!r})".format(op=self.opname(), pos=self.position) + return "{op}({pos!r}, {dbg!r})".format(op=self.opname(), + pos=self.position, + dbg=self.debug_info) def __eq__(self, other): return (other.__class__ == self.__class__ diff --git a/raco/myrial/groupby.py b/raco/myrial/groupby.py index d1876380..f3f04c86 100644 --- a/raco/myrial/groupby.py +++ b/raco/myrial/groupby.py @@ -43,7 +43,7 @@ class NestedAggregateException(Exception): pass -class InvalidAttributeRefException(Exception): +class NonGroupedAccessException(Exception): '''Attempting to access a non-grouping term in an aggregate expression''' pass @@ -73,7 +73,7 @@ def hoist_node(sexpr): # after the GroupBy input_pos = sexpr.get_position(input_scheme) if input_pos not in group_mappings: - raise InvalidAttributeRefException(str(sexpr)) + raise NonGroupedAccessException(str(sexpr)) output_pos = group_mappings[input_pos] return raco.expression.UnnamedAttributeRef(output_pos) diff --git a/raco/myrial/multiway.py b/raco/myrial/multiway.py index ad33f2f1..2608acee 100644 --- a/raco/myrial/multiway.py +++ b/raco/myrial/multiway.py @@ -15,6 +15,7 @@ def rewrite_node(sexpr): op = from_args[sexpr.relational_expression] scheme = op.scheme() + debug_info = None if not sexpr.field: offset = 0 elif isinstance(sexpr.field, int): @@ -22,10 +23,12 @@ def rewrite_node(sexpr): raise ColumnIndexOutOfBounds(str(sexpr)) offset = sexpr.field else: + assert isinstance(sexpr.field, basestring) offset = scheme.getPosition(sexpr.field) + debug_info = sexpr.field offset += base_offsets[sexpr.relational_expression] - return expression.UnnamedAttributeRef(offset) + return expression.UnnamedAttributeRef(offset, debug_info) def recursive_eval(sexpr): """Rewrite a node and all its descendents""" diff --git a/raco/myrial/query_tests.py b/raco/myrial/query_tests.py index 673cb895..d1c69bff 100644 --- a/raco/myrial/query_tests.py +++ b/raco/myrial/query_tests.py @@ -911,7 +911,7 @@ def test_aggregate_illegal_colref(self): STORE(out, OUTPUT); """ % self.emp_key - with self.assertRaises(raco.myrial.groupby.InvalidAttributeRefException): # noqa + with self.assertRaises(raco.myrial.groupby.NonGroupedAccessException): # noqa self.check_result(query, None) def test_nested_aggregates_are_illegal(self):