`append` twice with null columns leads to runtime Google BigQuery SQL error `UNION ALL has incompatible types`

Aperta
#5,349 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 3 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
45/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
google-cloud, rust, sql
Ambito
backend, databases

Direzione di ricerca

Start with the related issue #5341 and trace how PRQL lowers nested append operations for the BigQuery target. Reproduce the supplied PRQL input and inspect the generated SQL and relevant tests; the issue names no source files or tests. Done means the generated BigQuery SQL uses subqueries and CTEs so repeated appends with null columns run without incompatible UNION ALL types.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug
What happened?
  • Doing two append in Google BigQuery with null columns.
  • prqlc outputs a query that leads to runtime failure UNION ALL has incompatible types
PRQL input
prql target:sql.bigquery

from beers
select { name, price_per_l, alcohol_degree = null, brewing_date = null }
sort { +price_per_l }
take 2
append (
  from beers
  select { name, price_per_l = null, alcohol_degree, brewing_date = null }
  sort { -alcohol_degree }
  take 2
  append (
    from beers
    select { name, price_per_l = null, alcohol_degree = null, brewing_date }
    sort { -brewing_date }
    take 2
  )
)
SQL output
(
  SELECT
    name,
    price_per_l,
    NULL AS alcohol_degree,
    NULL AS brewing_date
  FROM
    beers
  ORDER BY
    price_per_l
  LIMIT
    2
)
UNION
ALL (
  SELECT
    name,
    NULL AS price_per_l,
    alcohol_degree,
    NULL AS brewing_date
  FROM
    beers
  ORDER BY
    alcohol_degree DESC
  LIMIT
    2
)
UNION
ALL (
  SELECT
    name,
    NULL AS price_per_l,
    NULL AS alcohol_degree,
    brewing_date
  FROM
    beers
  ORDER BY
    brewing_date DESC
  LIMIT
    2
)
Expected SQL output
WITH cte0 as (
  SELECT
    name,
    price_per_l
  FROM
    beers
  ORDER BY
    price_per_l
  LIMIT
    2
), cte1 as (
  SELECT
    name,
    alcohol_degree,
  FROM
    beers
  ORDER BY
    alcohol_degree DESC
  LIMIT
    2
), cte2 as (
  SELECT
    name,
    NULL AS price_per_l,
    NULL AS alcohol_degree,
    brewing_date
  FROM
    beers
  ORDER BY
    brewing_date DESC
  LIMIT
    2
)
(
  SELECT
    name,
    price_per_l,
    NULL AS alcohol_degree,
    NULL AS brewing_date
  FROM
    cte0
)
UNION
ALL (
  SELECT
    name,
    NULL AS price_per_l,
    alcohol_degree,
    NULL AS brewing_date
  FROM
    cte1
)
UNION
ALL (
  SELECT
    name,
    NULL AS price_per_l,
    NULL AS alcohol_degree,
    brewing_date
  FROM
    cte2
)
MVCE confirmation
  • Minimal example
  • New issue
Anything else?

Related to https://github.com/PRQL/prql/issues/5341.
Unfortunately, Google BigQuery is even more picky, and needs both subqueries and CTEs to succesfully infer the types here.

Lingua principale
Rust
Stelle
10.9k
Fork
261
Merge medio
3g 21h
PR unite (30g)
84

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di PRQL/prql

Tutte le issue di PRQL/prql

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.