def test_order_by(self): self.assert_parsed_select( 'SELECT foo, bar, baz FROM table ORDER BY foo DESC, bar, baz ASC,', tq_ast.Select([ tq_ast.SelectField(tq_ast.ColumnId('foo'), None), tq_ast.SelectField(tq_ast.ColumnId('bar'), None), tq_ast.SelectField(tq_ast.ColumnId('baz'), None) ], tq_ast.TableId('table', None), None, None, [ tq_ast.Ordering(tq_ast.ColumnId('foo'), False), tq_ast.Ordering(tq_ast.ColumnId('bar'), True), tq_ast.Ordering(tq_ast.ColumnId('baz'), True) ], None, None))
def test_order_by_multiple_fields(self): self.assert_compiled_select( 'SELECT value FROM table1 ORDER BY value2, value DESC', typed_ast.Select( select_fields=[typed_ast.SelectField( typed_ast.ColumnRef('table1', 'value', tq_types.INT), 'value', None)], table=typed_ast.Table('table1', self.table1_type_ctx), where_expr=typed_ast.Literal(True, tq_types.BOOL), group_set=None, having_expr=typed_ast.Literal(True, tq_types.BOOL), orderings=[tq_ast.Ordering(tq_ast.ColumnId('value2'), True), tq_ast.Ordering(tq_ast.ColumnId('value'), False)], limit=None, type_ctx=self.make_type_context( [(None, 'value', tq_types.INT)], self.make_type_context([('table1', 'value', tq_types.INT) ])) ))
def p_ordering_desc(p): """ordering : column_id DESC""" p[0] = tq_ast.Ordering(p[1], False)
def p_ordering_asc(p): """ordering : column_id | column_id ASC""" p[0] = tq_ast.Ordering(p[1], True)