MCPcopy Create free account
hub / github.com/sqlalchemy/sqlalchemy / test_over_framespec

Method test_over_framespec

test/sql/test_compiler.py:3179–3265  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

3177 )
3178
3179 def test_over_framespec(self):
3180 expr = table1.c.myid
3181 self.assert_compile(
3182 select(func.row_number().over(order_by=expr, rows=(0, None))),
3183 "SELECT row_number() OVER "
3184 "(ORDER BY mytable.myid ROWS BETWEEN CURRENT "
3185 "ROW AND UNBOUNDED FOLLOWING)"
3186 " AS anon_1 FROM mytable",
3187 )
3188
3189 self.assert_compile(
3190 select(func.row_number().over(order_by=expr, rows=(None, None))),
3191 "SELECT row_number() OVER "
3192 "(ORDER BY mytable.myid ROWS BETWEEN UNBOUNDED "
3193 "PRECEDING AND UNBOUNDED FOLLOWING)"
3194 " AS anon_1 FROM mytable",
3195 )
3196
3197 self.assert_compile(
3198 select(func.row_number().over(order_by=expr, range_=(None, 0))),
3199 "SELECT row_number() OVER "
3200 "(ORDER BY mytable.myid RANGE BETWEEN "
3201 "UNBOUNDED PRECEDING AND CURRENT ROW)"
3202 " AS anon_1 FROM mytable",
3203 )
3204
3205 self.assert_compile(
3206 select(func.row_number().over(order_by=expr, range_=(-5, 10))),
3207 "SELECT row_number() OVER "
3208 "(ORDER BY mytable.myid RANGE BETWEEN "
3209 ":param_1 PRECEDING AND :param_2 FOLLOWING)"
3210 " AS anon_1 FROM mytable",
3211 checkparams={"param_1": 5, "param_2": 10},
3212 )
3213
3214 self.assert_compile(
3215 select(func.row_number().over(order_by=expr, range_=(1, 10))),
3216 "SELECT row_number() OVER "
3217 "(ORDER BY mytable.myid RANGE BETWEEN "
3218 ":param_1 FOLLOWING AND :param_2 FOLLOWING)"
3219 " AS anon_1 FROM mytable",
3220 checkparams={"param_1": 1, "param_2": 10},
3221 )
3222
3223 self.assert_compile(
3224 select(func.row_number().over(order_by=expr, range_=(-10, -1))),
3225 "SELECT row_number() OVER "
3226 "(ORDER BY mytable.myid RANGE BETWEEN "
3227 ":param_1 PRECEDING AND :param_2 PRECEDING)"
3228 " AS anon_1 FROM mytable",
3229 checkparams={"param_1": 10, "param_2": 1},
3230 )
3231
3232 self.assert_compile(
3233 select(func.row_number().over(order_by=expr, groups=(None, 0))),
3234 "SELECT row_number() OVER "
3235 "(ORDER BY mytable.myid GROUPS BETWEEN "
3236 "UNBOUNDED PRECEDING AND CURRENT ROW)"

Callers

nothing calls this directly

Calls 3

selectFunction · 0.90
assert_compileMethod · 0.80
overMethod · 0.45

Tested by

no test coverage detected