prql
prql copied to clipboard
`take` doesn't support parameters
from foo
take $count
fails with:
Error:
╭─[:2:6]
│
2 │ take $count
│ ───┬──
│ ╰──── `take` expected int or range, but found $count
───╯
You cannot use $.
This works:
let foo_count = 50
from foo
take foo_count
We are quite strict about what's allowed in take parameters, as there are limitations on some database engines. But I do think we should be able to support parameters.
Ref #1772
Definitely agree that the language should support this...
Hello. Is there any progress on this?
Hello. Is there any progress on this?
Not yet, no.
If folks would be up for contributing but aren't sure where to start, let us know and we can write up some guidance.
I'm not sure whom 'folks' are (English not my first language), but I would like to try to work on this in my free time.
I'm not sure whom 'folks' are (English not my first language),
Sorry, an Americanism, despite my European roots. Just "if anyone wants to contribute"...
I'm not sure whom 'folks' are (English not my first language), but I would like to try to work on this in my free time.
Great!
How much rust experience do you have?
You can see the Take struct here: https://github.com/PRQL/prql/blob/04b5174cba01bcc79837e69f0697486210d3d6dd/crates/prql-compiler/src/ir/rq/transform.rs#L32-L37. That probably needs to hold an Expr rather than a Range, and then it can hold parameters.
One approach to start is replacing Range with Expr, and then fix the errors that the compiler shows.
That struct is then converted into another struct a bit later in the pipeline here: https://github.com/PRQL/prql/blob/04b5174cba01bcc79837e69f0697486210d3d6dd/crates/prql-compiler/src/sql/srq/ast.rs#L95. If it's easier, you could start by only replacing it for the initial part of the pipeline, commit that, and then work on the next. (Though it won't work until it flows all the way through, but often breaking up work makes it much easier).
Does that make sense? You're welcome to ask questions here, or PR something partially complete.
CC @aljazerzen, who knows this code best.