From 2c27d36a2c2f2918c24a67e488febfbf878181ec Mon Sep 17 00:00:00 2001 From: Phillip Cloud <417981+cpcloud@users.noreply.github.com> Date: Wed, 6 Dec 2023 16:39:07 -0500 Subject: [PATCH] test(joins): add test for #7288. --- .../test_join/test_complex_join_agg/out.sql | 17 +++++++++++++++++ ibis/backends/tests/test_join.py | 10 ++++++++++ 2 files changed, 27 insertions(+) create mode 100644 ibis/backends/tests/snapshots/test_join/test_complex_join_agg/out.sql diff --git a/ibis/backends/tests/snapshots/test_join/test_complex_join_agg/out.sql b/ibis/backends/tests/snapshots/test_join/test_complex_join_agg/out.sql new file mode 100644 index 0000000000000..c454d75c63aa1 --- /dev/null +++ b/ibis/backends/tests/snapshots/test_join/test_complex_join_agg/out.sql @@ -0,0 +1,17 @@ +SELECT + t3.key1 AS key1, + AVG(t3.value1 - t3.value2) AS avg_diff +FROM ( + SELECT + t0.value1 AS value1, + t0.key1 AS key1, + t0.key2 AS key2, + t1.value2 AS value2, + t1.key1 AS key1_right, + t1.key4 AS key4 + FROM table1 AS t0 + LEFT OUTER JOIN table2 AS t1 + ON t0.key1 = t1.key1 +) AS t3 +GROUP BY + 1 \ No newline at end of file diff --git a/ibis/backends/tests/test_join.py b/ibis/backends/tests/test_join.py index 87835045a9791..65fd3dab85b30 100644 --- a/ibis/backends/tests/test_join.py +++ b/ibis/backends/tests/test_join.py @@ -381,3 +381,13 @@ def test_outer_join_nullability(backend, how, nrows, gen_right, keys): result = expr.to_pyarrow() assert len(result) == nrows + + +def test_complex_join_agg(snapshot): + t1 = ibis.table(dict(value1="float", key1="string", key2="string"), name="table1") + t2 = ibis.table(dict(value2="float", key1="string", key4="string"), name="table2") + + avg_diff = (t1.value1 - t2.value2).mean() + expr = t1.left_join(t2, "key1").group_by(t1.key1).aggregate(avg_diff=avg_diff) + + snapshot.assert_match(str(ibis.to_sql(expr, dialect="duckdb")), "out.sql")