MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / test_over_framespec

Method test_over_framespec

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

Source from the content-addressed store, hash-verified

3201 )
3202
3203 def test_over_framespec(self):
3204 expr = table1.c.myid
3205 self.assert_compile(
3206 select(func.row_number().over(order_by=expr, rows=(0, None))),
3207 "SELECT row_number() OVER "
3208 "(ORDER BY mytable.myid ROWS BETWEEN CURRENT "
3209 "ROW AND UNBOUNDED FOLLOWING)"
3210 " AS anon_1 FROM mytable",
3211 )
3212
3213 self.assert_compile(
3214 select(func.row_number().over(order_by=expr, rows=(None, None))),
3215 "SELECT row_number() OVER "
3216 "(ORDER BY mytable.myid ROWS BETWEEN UNBOUNDED "
3217 "PRECEDING AND UNBOUNDED FOLLOWING)"
3218 " AS anon_1 FROM mytable",
3219 )
3220
3221 self.assert_compile(
3222 select(func.row_number().over(order_by=expr, rows=(-10, 1))),
3223 "SELECT row_number() OVER "
3224 "(ORDER BY mytable.myid ROWS BETWEEN "
3225 ":param_1 PRECEDING AND :param_2 FOLLOWING)"
3226 " AS anon_1 FROM mytable",
3227 checkparams={"param_1": 10, "param_2": 1},
3228 )
3229
3230 RF = FrameClauseType.FOLLOWING
3231 RP = FrameClauseType.PRECEDING
3232
3233 self.assert_compile(
3234 select(
3235 func.row_number().over(
3236 order_by=expr,
3237 rows=FrameClause(3, 2, RF, RP),
3238 )
3239 ),
3240 "SELECT row_number() OVER "
3241 "(ORDER BY mytable.myid ROWS BETWEEN "
3242 ":param_1 FOLLOWING AND :param_2 PRECEDING)"
3243 " AS anon_1 FROM mytable",
3244 checkparams={"param_1": 3, "param_2": 2},
3245 )
3246
3247 self.assert_compile(
3248 select(func.row_number().over(order_by=expr, range_=(None, 0))),
3249 "SELECT row_number() OVER "
3250 "(ORDER BY mytable.myid RANGE BETWEEN "
3251 "UNBOUNDED PRECEDING AND CURRENT ROW)"
3252 " AS anon_1 FROM mytable",
3253 )
3254
3255 self.assert_compile(
3256 select(func.row_number().over(order_by=expr, range_=(-5, 10))),
3257 "SELECT row_number() OVER "
3258 "(ORDER BY mytable.myid RANGE BETWEEN "
3259 ":param_1 PRECEDING AND :param_2 FOLLOWING)"
3260 " AS anon_1 FROM mytable",

Callers

nothing calls this directly

Calls 4

selectFunction · 0.90
FrameClauseClass · 0.90
assert_compileMethod · 0.80
overMethod · 0.45

Tested by

no test coverage detected