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.91k stars 217 forks source link

Queries that return nested tuples #4803

Open vanillajonathan opened 3 months ago

vanillajonathan commented 3 months ago

What happened?

It compile a query but a is no where in the output. It probably shouldn't compile at all.

PRQL input

from foo
derive {
  a = {
    b = "b"
  },
}

SQL output

SELECT
  *,
  'b' AS b
FROM
  foo

-- Generated by PRQL compiler version:0.13.0 (https://prql-lang.org)

Expected SQL output

No response

MVCE confirmation

Anything else?

No response

aljazerzen commented 2 months ago

That's expected behavior, but we have to formally decided on it (I think).

The result type of your query is [{a = {b = text} }]. Because tuples are not a thing in all SQL dialects (and hard to work with even where they are supported), we flatten the resulting type into this [{b = text}].

A few more examples:

There is an alternative behavior that we could implement:

A bit more explicit.

I think that one of the changes on my branch is a change to this second behavior.

dkratunov commented 1 month ago

This is also very relevant in engines that support dictionary/map types.

For example, as far as I can tell, there's no way to work with a Map(String,String) column in Clickhouse when using the prql dialect.