MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / test_aggregate_order_by_one

Method test_aggregate_order_by_one

test/sql/test_functions.py:1148–1181  ·  view source on GitHub ↗
(self, style)

Source from the content-addressed store, hash-verified

1146
1147 @testing.variation("style", ["none", "inline", "within_group"])
1148 def test_aggregate_order_by_one(self, style):
1149 table = Table(
1150 "table1", MetaData(), Column("a", Integer), Column("b", Integer)
1151 )
1152 expr = func.array_agg(table.c.a).aggregate_order_by(table.c.b.desc())
1153 stmt = select(expr)
1154
1155 if style.none:
1156 dialect = default.DefaultDialect()
1157 dialect.aggregate_order_by_style = AggregateOrderByStyle.NONE
1158 with expect_raises_message(
1159 exc.CompileError,
1160 "this dialect does not support ORDER BY "
1161 "within an aggregate function",
1162 ):
1163 stmt.compile(dialect=dialect)
1164 elif style.within_group:
1165 dialect = default.DefaultDialect()
1166 dialect.aggregate_order_by_style = (
1167 AggregateOrderByStyle.WITHIN_GROUP
1168 )
1169 self.assert_compile(
1170 stmt,
1171 "SELECT array_agg(table1.a) "
1172 "WITHIN GROUP (ORDER BY table1.b DESC) "
1173 "AS array_agg_1 FROM table1",
1174 dialect=dialect,
1175 )
1176 else:
1177 self.assert_compile(
1178 stmt,
1179 "SELECT array_agg(table1.a ORDER BY table1.b DESC) "
1180 "AS array_agg_1 FROM table1",
1181 )
1182
1183 @testing.variation("style", ["inline", "within_group"])
1184 def test_aggregate_order_by_two(self, style):

Callers

nothing calls this directly

Calls 10

TableClass · 0.90
MetaDataClass · 0.90
ColumnClass · 0.90
selectFunction · 0.90
expect_raises_messageFunction · 0.90
array_aggMethod · 0.80
assert_compileMethod · 0.80
aggregate_order_byMethod · 0.45
descMethod · 0.45
compileMethod · 0.45

Tested by

no test coverage detected