prql: Wrong or inconsitent behaviour with `take`
I suspect some minor problem in the parser in the case of take 1
A) (wrong)
from invoices
group [billing_city] (
take 1
)
SELECT
DISTINCT *
FROM
invoices
-- Generated by PRQL compiler version:0.5.2 (https://prql-lang.org)
B) (correct?)
from invoices
group [billing_city] (
take 2
)
WITH table_1 AS (
SELECT
*,
ROW_NUMBER() OVER (PARTITION BY billing_city) AS _expr_0
FROM
invoices
)
SELECT
*
FROM
table_1
WHERE
_expr_0 <= 2
-- Generated by PRQL compiler version:0.5.2 (https://prql-lang.org)
C) (very wrong)
from invoices
group [billing_city] (
take 1
)
select [a, b, c]
SELECT
DISTINCT a,
b,
c
FROM
invoices
-- Generated by PRQL compiler version:0.5.2 (https://prql-lang.org)
D) (correct?)
from invoices
group [billing_city] (
sort [-invoice_date]
take 1
)
WITH table_1 AS (
SELECT
*,
ROW_NUMBER() OVER (
PARTITION BY billing_city
ORDER BY
invoice_date DESC
) AS _expr_0
FROM
invoices
)
SELECT
*
FROM
table_1
WHERE
_expr_0 <= 1
-- Generated by PRQL compiler version:0.5.2 (https://prql-lang.org)
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 17 (10 by maintainers)
Oh, yes I do remember š Itās a thing that I was putting off for a long time.
https://github.com/PRQL/prql/issues/944
At the time it was not convenient to do, but now it may not be so anymore.
I think with your guidance weāre 90% of the way there ā this issue was a good case of that.
As you know, one of my priorities is to give you better leverage on your time, which weād get from contributions requiring less guidance. Letting folks be independent would also be a better contribution experience.
Itās possible that weāve done everything we can, and I donāt have specific examples for where we havenāt yet. But in general, Iāve found thereās often lots of potential to make things more local, requiring less context & guidance. RQ is a good example of that I reckon, even if we havenāt fully exploited it yet.
Iām going to try and pivot back to the compiler by fixing some of our bugs (like this) āĀ I think weāre probably under-weighing how important these are for having the language feel reliable. While Iām doing that, Iāll keep an eye open for opportunities on this dimension.
Closed by #2109.
Thanks for the guidance @aljazerzen .
Iām also going to reflect on this as a case of #1840. The actual code was fairly easy. But:
determine_select_columnswould have been hard without your guidance.So maybe we try and frame issues & tests as āwe need to change this RQ into this RQā. Does that resonate at all??
I had a quick look, and can look more tomorrow. This is code Iām hoping to get into myself more too (@aljazerzen wrote almost all of it).
FWIW the
byis a remnant from us usingbyto specify the columns in a group ā it just means the columns in thegroup.FYI I added #2080 so I could add some
dbg!statements and understand where the information was on thectxvariable.