PRQL / prql

PRQL is a modern language for transforming data — a simple, powerful, pipelined SQL replacement
https://prql-lang.org
Apache License 2.0
9.96k stars 218 forks source link

Variables at the start of pipelines #414

Closed max-sixty closed 2 years ago

max-sixty commented 2 years ago

Currently, this works:

func iden x = x

from foo
derive bar: (temp_c | iden)
SELECT
  foo.*,
  temp_c AS bar
FROM
  foo

But this doesn't:

func iden x = x

from foo
derive bar: (
  temp_c
  iden
)
Error { span: Some(Span { start: 42, end: 48 }), reason: NotFound { name: "temp_c", namespace: "function" }, help: None }

I think this should probably work:

aljazerzen commented 2 years ago

Because | is equivalent to \n, this:

(
  temp_c
  iden
)

is equivalent to:

( | temp_c | iden | )

Value is the first entry in pipeline, so one would have to write:

func iden x = x

from foo
derive bar: (temp_c
  iden
)

I would be more convenient to be able to determine that value is actually the second entry, but I think that for would require better types for currying, which we currently don't have.

Until we do, I think this can remain a rough edge, just as ( | derive x ) is.

max-sixty commented 2 years ago

Thanks @aljazerzen , that clear in retrospect.

It's not an ideal state — it means functions need to be on one line! I suspect this might not be easy to resolve without the full type system; I'll reflect more. We could add \ but I'm not sure it helps with the confusion, even if it does with the line length.

aljazerzen commented 2 years ago

Functions on the same line? No just the first item (the value) must be in the same line. Function currys can be on lines below.

Anyway, this will be ironed out, when typing hits. And I believe we are not far from it. When window functions & website are done we can release 0.2 and I can get started on this.

max-sixty commented 2 years ago

Anyway, this will be ironed out, when typing hits. And I believe we are not far from it. When window functions & website are done we can release 0.2 and I can get started on this.

Amazing if you think it's not far (though I suspect it'll be a lot of work!)

I will do a review of where we're at for 0.2 and follow up on some of the things we had discussed.

richb-hanover commented 1 year ago

Updated example to use 0.3 syntax:

func iden x -> x

from foo
derive bar = (temp_c | iden)