Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Queries that return nested tuples #4803

Open
2 tasks done
vanillajonathan opened this issue Jul 29, 2024 · 2 comments
Open
2 tasks done

Queries that return nested tuples #4803

vanillajonathan opened this issue Jul 29, 2024 · 2 comments
Labels
language-design Changes to PRQL-the-language

Comments

@vanillajonathan
Copy link
Collaborator

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

  • Minimal example
  • New issue

Anything else?

No response

@vanillajonathan vanillajonathan added the bug Invalid compiler output or panic label Jul 29, 2024
@aljazerzen
Copy link
Member

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:

  • [{a = {b = text, c = int}}] -> [{b = text, c = int}],
  • [{a = int, b = {c = text}}] -> [{a = int, c = text}],
  • [{a = {b = text}, c = {d = int}}] -> [{b = text, d = int}].

There is an alternative behavior that we could implement:

  • [{a = {b = text} }] -> [{`a.b` = text}]

A bit more explicit.

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

@aljazerzen aljazerzen added language-design Changes to PRQL-the-language and removed bug Invalid compiler output or panic labels Aug 1, 2024
@aljazerzen aljazerzen changed the title derive with tuple as value Queries that return nested tuples Aug 1, 2024
@dkratunov
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
language-design Changes to PRQL-the-language
Projects
None yet
Development

No branches or pull requests

3 participants