prql
prql copied to clipboard
Aggregating on group key got messed with multiple CTEs
What happened?
The following prql fails on 0.11.4 but works on 0.10.1.
PRQL input
from foo
derive b = a + 1
filter true # ensure a CTE
derive c = b + 1
filter true # ensure another CTE
group {c} (
aggregate {
n = (average c)
}
)
SQL output
WITH table_1 AS (
SELECT
c AS _expr_0,
a + 1 AS _expr_1
FROM
foo
),
table_0 AS (
SELECT
_expr_1 + 1 AS c,
_expr_0
FROM
table_1
WHERE
true
)
SELECT
c,
AVG(_expr_0) AS n
FROM
table_0
WHERE
true
GROUP BY
c
Expected SQL output
WITH table_1 AS (
SELECT
a + 1 AS _expr_1
FROM
foo
),
table_0 AS (
SELECT
_expr_1 + 1 AS c,
_expr_0
FROM
table_1
WHERE
true
)
SELECT
c,
AVG(_expr_0) AS n
FROM
table_0
WHERE
true
GROUP BY
c
MVCE confirmation
- [X] Minimal example
- [ ] New issue
Anything else?
No response
Expected sql is wrong. just ignore it.
The error is: "c" is a derived column but appears as a real column in the first CTE
Thanks for the issue. This does look wrong.
We're rethinking how columns are resolved, so this may get pushed into that effort.
Any plan to solve this bug?
Any plan to solve this bug?
We're rethinking how columns are resolved, so this may get pushed into that effort.
The effort is taking a bit longer than hoped; the bounds are fairly wide given it's no one's day job...