Thanks to visit codestin.com
Credit goes to github.com

Skip to content

using select after group col (take n) causes a crash/panic for certain targets (have DISTINCT ON) #3111

@cornservant

Description

@cornservant

What happened?

The compiler panics when compiling the PRQL input given below.

I am using prqlc 0.9.2 on Manjaro Linux x86_64.

PRQL input

prql target:sql.postgres
# prql target:sql.clickhouse
# prql target:sql.duckdb

from a
join b (b.a_id == a.id)
group {a.id} (
  sort b.x
  take 1
)
select {a.id, b.y}

SQL output

--

Expected SQL output

No response

MVCE confirmation

  • Minimal example
  • New issue

Anything else?

The compiler does not crash when

  • adding the column b.x to the final select statement, OR
  • changing the target language to anything other than sql.postgres, sql.clickhouse, sql.duckdb

Playground-friendly version of the offending input:

prql target:sql.postgres
# prql target:sql.clickhouse
# prql target:sql.duckdb

from customers
join invoices (invoices.customer_id == customers.customer_id)
group {customers.customer_id} (
  sort {- invoices.total}
  take 1
)
sort { customers.customer_id }
select { customers.customer_id, invoices.billing_country }

stderr output with RUST_LOG=trace: https://gist.github.com/exit91/410a49f7d7b8d7ccf14b3dbf781e7bec

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions