prql icon indicating copy to clipboard operation
prql copied to clipboard

feat: use let for table def

Open aljazerzen opened this issue 2 years ago • 5 comments

Ref #523

aljazerzen avatar Dec 21 '22 12:12 aljazerzen

I find this quite reasonable.

One downside is that we only allow tables here — and probably only ever will, since everything can be represented by a table, and having a consistent type there simplifies things.

Will folks try doing:

let x = 5

from employees
filter id = x

...which looks like it should work, but doesn't?

I guess one option would be to force typing, too verbose but makes the point:

let x<table> = ...

I also think it's worth considering whether we should align the func and table definition syntax. With the proposed code, they don't look that similar:

let foo_table = (from employees)
func add a b -> a + b

Arguably the corollary of the proposed code would be to define funcs like:

let add = func a b -> a + b
# or
let add = a b -> a + b
# or
let add<func> = a b -> a + b

I recognize those suggestions widen the aperture of options rather than focus us — I don't mean to reopen every discussion about these. But in this case I do think it's worth ensuring the whole language is coherent. What do others think?

max-sixty avatar Dec 21 '22 18:12 max-sixty

Actually, signaling that you could define constants was my intention. Currently it (should) throw an error saying it's expecting a table, but this is a feature that does have use-cases.

See the linked issue for my comment about that.

aljazerzen avatar Dec 22 '22 07:12 aljazerzen

I agree with @max-sixty 's point that we should try to ensure the language remains coherent.

I'm in the process of writing up a bigger discussion around "Tables, transforms and pipelines" which I'll post in the discussions section. I've been trying to formulate my thought around that for months and I think I actually had a breakthrough insight yesterday (for me).

The points raised about functions and constants open the scope even further so can we hold on this for a bit until we've had time to discuss this in more depth?

snth avatar Dec 22 '22 09:12 snth

Agreed. Let's leave this PR open until then.

aljazerzen avatar Dec 22 '22 09:12 aljazerzen

Thanks. The discussion is in #1323 .

snth avatar Dec 22 '22 11:12 snth

Great! I'm a +0.7.

We should update the docs and the grammars too, and do a release, so the docs aren't out of date for something so fundamental. I'm happy to own those.

max-sixty avatar Jan 12 '23 17:01 max-sixty

As mentioned in #523 , I had a discussion with Aljaz on this and had misunderstood an aspect of this. Very happy with this feature now.

Thanks!

snth avatar Jan 13 '23 21:01 snth