Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aggregating on group key got messed with multiple CTEs #4263

Open
1 of 2 tasks
echou opened this issue Feb 26, 2024 · 3 comments
Open
1 of 2 tasks

Aggregating on group key got messed with multiple CTEs #4263

echou opened this issue Feb 26, 2024 · 3 comments
Labels
bug Invalid compiler output or panic

Comments

@echou
Copy link

echou commented Feb 26, 2024

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

  • Minimal example
  • New issue

Anything else?

No response

@echou echou added the bug Invalid compiler output or panic label Feb 26, 2024
@echou
Copy link
Author

echou commented Feb 26, 2024

Expected sql is wrong. just ignore it.

@echou
Copy link
Author

echou commented Feb 26, 2024

The error is: "c" is a derived column but appears as a real column in the first CTE

@max-sixty
Copy link
Member

Thanks for the issue. This does look wrong.

We're rethinking how columns are resolved, so this may get pushed into that effort.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Invalid compiler output or panic
Projects
None yet
Development

No branches or pull requests

2 participants