prql
prql copied to clipboard
Extend `let` beyond relations
This works:
let some = 5
from employees
take some
But this does not:
let some = 5 + 5
from employees
take some
Yes, currently let needs to resolve to a table / relation.
Relaxing this would be good! It's not trivial in the compiler; and it would be less frequently used than for relations, but it would be an elegant generalization.
I'm going to adjust the title slightly if that's OK @vanillajonathan
I had a look at implementing this. It's not obvious how to do it.
When we lower the expressions, we need to create a table instance, since that's the only thing that RQ can hold.
Currently we do that here: https://github.com/PRQL/prql/blob/9b21e945282130fea5619d994ff1568b4ea46f0d/prql-compiler/src/semantic/lowering.rs#L198
Just above that line, we do allow a Literal in RelationKind: https://github.com/PRQL/prql/blob/9b21e945282130fea5619d994ff1568b4ea46f0d/prql-compiler/src/ast/rq/mod.rs#L41-L46
But should we also allow other types like expressions? Or should we resolve those first?
@aljazerzen if you have thoughts...