def test_aggregate_format_kwargs(): agg = Aggregate("'{collate_date}' - date", "min", {}) assert list( map(str, agg.get_columns( format_kwargs={"collate_date": "2012-01-01"}))) == [ "min('2012-01-01' - date)" ]
def test_aggregate(): agg = Aggregate("*", "count", {}) assert list(map(str, agg.get_columns())) == ["count(*)"]
def test_aggregate_tuple_quantity_when(): agg = Aggregate(("x", "y"), "corr", {}) assert list(map(str, agg.get_columns(when="date < '2012-01-01'"))) == [ "corr(x, y) FILTER (WHERE date < '2012-01-01')" ]
def test_aggregate_tuple_quantity(): agg = Aggregate(("x", "y"), "corr", {}) assert list(map(str, agg.get_columns())) == ["corr(x, y)"]
def test_ordered_aggregate_when(): agg = Aggregate("", "mode", {}, "x") assert list(map(str, agg.get_columns(when="date < '2012-01-01'"))) == [ "mode() WITHIN GROUP (ORDER BY x) FILTER (WHERE date < '2012-01-01')" ]
def test_ordered_aggregate(): agg = Aggregate("", "mode", {}, "x") (expression,) = agg.get_columns() assert str(expression) == "mode() WITHIN GROUP (ORDER BY x)" assert expression.name == "x_mode"
def test_aggregate_when_cast(): agg = Aggregate("", "mode", {}, "x", coltype="SMALLINT") assert list(map(str, agg.get_columns(when="date < '2012-01-01'"))) == [ "mode() WITHIN GROUP (ORDER BY x) FILTER (WHERE date < '2012-01-01')::SMALLINT" ]
def test_aggregate_when(): agg = Aggregate("1", "count", {}) assert list(map(str, agg.get_columns(when="date < '2012-01-01'"))) == [ "count(1) FILTER (WHERE date < '2012-01-01')" ]
def test_aggregate_cast(): agg = Aggregate("*", "count", {}, coltype="REAL") assert list(map(str, agg.get_columns())) == ["count(*)::REAL"]