def test_last_value_rows_between_current_row_unbounded_following(self): expr = an.LastValue(self.table_abc.fizz) \ .over(self.table_abc.foo) \ .orderby(self.table_abc.date) \ .rows(an.CURRENT_ROW, an.Following()) q = Query.from_(self.table_abc).select(expr) self.assertEqual( 'SELECT ' 'LAST_VALUE("fizz") ' 'OVER(' 'PARTITION BY "foo" ORDER BY "date" ' 'ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING' ') ' 'FROM "abc"', str(q))
def test_varpop_rows_between_unbounded_preceeding_x_following(self): expr = an.VarPop(self.table_abc.fizz) \ .over(self.table_abc.foo) \ .orderby(self.table_abc.date) \ .rows(an.Preceding(), an.Following(6)) q = Query.from_(self.table_abc).select(expr) self.assertEqual( 'SELECT ' 'VAR_POP("fizz") ' 'OVER(' 'PARTITION BY "foo" ORDER BY "date" ' 'ROWS BETWEEN UNBOUNDED PRECEDING AND 6 FOLLOWING' ') ' 'FROM "abc"', str(q))
def test_first_value_range_between_x_preceeding_unbounded_following(self): expr = an.FirstValue(self.table_abc.fizz) \ .over(self.table_abc.foo) \ .orderby(self.table_abc.date) \ .range(an.Preceding(3), an.Following()) q = Query.from_(self.table_abc).select(expr) self.assertEqual( 'SELECT ' 'FIRST_VALUE("fizz") ' 'OVER(' 'PARTITION BY "foo" ORDER BY "date" ' 'RANGE BETWEEN 3 PRECEDING AND UNBOUNDED FOLLOWING' ') ' 'FROM "abc"', str(q))
def test_variance_rows_between_unbounded_preceeding_unbounded_following( self): expr = (an.Variance(self.table_abc.fizz).over( self.table_abc.foo).orderby(self.table_abc.date).rows( an.Preceding(), an.Following())) q = Query.from_(self.table_abc).select(expr) self.assertEqual( "SELECT " 'VARIANCE("fizz") ' "OVER(" 'PARTITION BY "foo" ORDER BY "date" ' "ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING" ") " 'FROM "abc"', str(q), )
def test_last_value_rows_between_current_row_unbounded_following_ignore_nulls( self): expr = (an.LastValue(self.table_abc.fizz).over( self.table_abc.foo).orderby( self.table_abc.date).ignore_nulls().rows( an.CURRENT_ROW, an.Following(8))) q = Query.from_(self.table_abc).select(expr) self.assertEqual( "SELECT " 'LAST_VALUE("fizz" IGNORE NULLS) ' "OVER(" 'PARTITION BY "foo" ORDER BY "date" ' "ROWS BETWEEN CURRENT ROW AND 8 FOLLOWING" ") " 'FROM "abc"', str(q), )