What happened?
Group aggregation after append doesn't preserve column alias (nor order) which leads to broken aggregations
PRQL input
prql target:sql.snowflake
let shape = p -> (
p
select {
interaction_day = s"DATE_TRUNC('day', ts)",
user_id = s"substr(user, length('u:') + 1)",
}
)
from table1
shape
append (from table2 | shape)
group { user_id } (
aggregate {
daily_interaction = count interaction_day
}
)
SQL output
WITH table_0 AS (
SELECT
DATE_TRUNC('day', ts) AS interaction_day,
substr(user, length('u:') + 1) AS user_id
FROM
table2
),
table_1 AS (
SELECT
substr(user, length('u:') + 1) AS user_id,
DATE_TRUNC('day', ts) AS _expr_0
FROM
table1
UNION
ALL
SELECT
*
FROM
table_0
)
SELECT
user_id,
COUNT(*) AS daily_interaction
FROM
table_1
GROUP BY
user_id
-- Generated by PRQL compiler version:0.9.5 (https://prql-lang.org)
Expected SQL output
WITH table_0 AS (
SELECT
DATE_TRUNC('day', ts) AS interaction_day,
substr(user, length('u:') + 1) AS user_id
FROM
table2
),
table_1 AS (
SELECT
substr(user, length('u:') + 1) AS user_id,
DATE_TRUNC('day', ts) AS interaction_day
FROM
table1
UNION
ALL
SELECT
*
FROM
table_0
)
SELECT
user_id,
COUNT(*) AS daily_interaction
FROM
table_1
GROUP BY
user_id
-- Generated by PRQL compiler version:0.9.5 (https://prql-lang.org)
MVCE confirmation
Anything else?
No response
What happened?
Group aggregation after append doesn't preserve column alias (nor order) which leads to broken aggregations
PRQL input
SQL output
Expected SQL output
MVCE confirmation
Anything else?
No response