Exemplo n.º 1
0
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)"
            ]
Exemplo n.º 2
0
def test_aggregate():
    agg = Aggregate("*", "count", {})
    assert list(map(str, agg.get_columns())) == ["count(*)"]
Exemplo n.º 3
0
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')"
    ]
Exemplo n.º 4
0
def test_aggregate_tuple_quantity():
    agg = Aggregate(("x", "y"), "corr", {})
    assert list(map(str, agg.get_columns())) == ["corr(x, y)"]
Exemplo n.º 5
0
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')"
    ]
Exemplo n.º 6
0
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"
Exemplo n.º 7
0
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"
    ]
Exemplo n.º 8
0
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')"
    ]
Exemplo n.º 9
0
def test_aggregate_cast():
    agg = Aggregate("*", "count", {}, coltype="REAL")
    assert list(map(str, agg.get_columns())) == ["count(*)::REAL"]