Column reference error for `loop` inside functions

Aperta
#4,717 6 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
35/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
rust
Ambito
compilers

Direzione di ricerca

Start by running the supplied PRQL input as an MVCE and compare its generated SQL with the expected output. Trace the compiler path for loop expressions inside functions, focusing on column names and the recursive join condition. Done means the example compiles with the expected column references and join predicate, with a regression test covering it.

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

Descrizione

bug
What happened?

There's a regression in PRQL version:0.12.2 in that some loop examples no longer compile correctly.

The problems are:

  • References to _expr_0, _expr_1, _expr_2, _expr_3, and _expr_4 instead of t, x, and ewma,
  • Recursive reference to table_2.t in ) AS table_5 ON table_5.t = table_5.t + 1.

The expected output runs correctly in shell.duckdb.org.

PRQL input
let calc_ewma = func span rel -> (
  from rel
  filter t==1
  select {t, x, ewma=x}
  loop (
    join rel (that.t==this.t+1)
    select {t, x, ewma = 2/(span+1)*x + (1-2/(span+1))*ewma}
  )
)

let data = [
  {ts=1, value=1},
  {ts=2, value=12},
  {ts=3, value=13},
  {ts=4, value=5},
  {ts=5, value=1},
  ]

from data
select {t=ts, x=value}
calc_ewma 3
select {ts=t, value=x, value_ewma3=ewma}
SQL output
WITH RECURSIVE table_0 AS (
  SELECT
    1 AS ts,
    1 AS value
  UNION
  ALL
  SELECT
    2 AS ts,
    12 AS value
  UNION
  ALL
  SELECT
    3 AS ts,
    13 AS value
  UNION
  ALL
  SELECT
    4 AS ts,
    5 AS value
  UNION
  ALL
  SELECT
    5 AS ts,
    1 AS value
),
data AS (
  SELECT
    ts,
    value
  FROM
    table_0
),
table_3 AS (
  SELECT
    ts AS t,
    value AS x
  FROM
    data
),
table_2 AS (
  SELECT
    _expr_0,
    _expr_1,
    _expr_1 AS _expr_2
  FROM
    table_3
  WHERE
    _expr_0 = 1
  UNION
  ALL
  SELECT
    table_5.t AS _expr_3,
    table_5.x AS _expr_4,
    2 / (3 + 1) * table_5.x + (1 - 2 / (3 + 1)) * table_2._expr_2
  FROM
    table_2
    JOIN (
      SELECT
        ts AS t,
        value AS x
      FROM
        data
    ) AS table_5 ON table_5.t = table_5.t + 1
)
SELECT
  t AS ts,
  x AS value,
  _expr_2 AS value_ewma3
FROM
  table_2 AS table_4

-- Generated by PRQL compiler version:0.12.2 (https://prql-lang.org)
Expected SQL output
WITH RECURSIVE table_0 AS (
  SELECT
    1 AS ts,
    1 AS value
  UNION
  ALL
  SELECT
    2 AS ts,
    12 AS value
  UNION
  ALL
  SELECT
    3 AS ts,
    13 AS value
  UNION
  ALL
  SELECT
    4 AS ts,
    5 AS value
  UNION
  ALL
  SELECT
    5 AS ts,
    1 AS value
),
data AS (
  SELECT
    ts,
    value
  FROM
    table_0
),
table_3 AS (
  SELECT
    ts AS t,
    value AS x
  FROM
    data
),
table_2 AS (
  SELECT
    t,
    x,
    x AS ewma
  FROM
    table_3
  WHERE
    t = 1
  UNION
  ALL
  SELECT
    table_5.t,
    table_5.x,
    2 / (3 + 1) * table_5.x + (1 - 2 / (3 + 1)) * table_2.ewma as ewma
  FROM
    table_2
    JOIN (
      SELECT
        ts AS t,
        value AS x
      FROM
        data
    ) AS table_5 ON table_5.t = table_2.t + 1
)
SELECT
  t AS ts,
  x AS value,
  ewma AS value_ewma3
FROM
  table_2 AS table_4
MVCE confirmation
  • Minimal example
  • New issue
Anything else?

This might have been introduced in version 0.10 or 0.11 already as I noticed my examples failing to compile then. I've just been pinning to 0.9.5 since then.

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.