BigQuery `JSON_KEYS` transpiles to `J_S_O_N_KEYS_AT_DEPTH` in DuckDB (missing generator transform)

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

I maintainer di solito rispondono entro 4 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
55/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Tranquilla
Stack tecnologico
python, sql

Direzione di ricerca

Start by reading sqlglot/dialects/duckdb.py and the BigQuery parsing path that produces exp.JSONKeysAtDepth; then look for nearby generator transforms and their tests. Check how the project handles unsupported arguments during transpilation. Done means the one-argument form emits DuckDB's json_keys(x), with an explicit, tested behavior for the depth argument.

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

Descrizione

Bug Engine: DuckDB Improvement

JSON_KEYS is parsed into exp.JSONKeysAtDepth by the BigQuery dialect, but the DuckDB generator has no transform registered for that expression. As a result, transpiling to DuckDB falls back to the class-name snake_case output, which is not a valid DuckDB function.

Version

sqlglot==28.10.1, also reproduces against main (30.4.3) per source inspection of sqlglot/dialects/duckdb.py.

Reproduction

from sqlglot import parse_one

print(parse_one("SELECT JSON_KEYS(x) FROM t", dialect="bigquery").sql(dialect="duckdb"))
# SELECT J_S_O_N_KEYS_AT_DEPTH(x) FROM t

print(parse_one("SELECT JSON_KEYS(x, 2) FROM t", dialect="bigquery").sql(dialect="duckdb"))
# SELECT J_S_O_N_KEYS_AT_DEPTH(x, 2) FROM t

Executing the output against DuckDB fails:

duckdb.CatalogException: Scalar Function with name j_s_o_n_keys_at_depth does not exist!
Did you mean "json_keys"?

Expected

JSON_KEYS(x) should transpile to DuckDB's json_keys(x).

The two-argument form is where the question lies: BigQuery's JSON_KEYS(json_expr, max_depth) takes an optional depth, while DuckDB's json_keys has no depth parameter. Dropping max_depth silently would be lossy; raising on the DuckDB side is another option. Guidance on the preferred direction would be welcome.

References

Lingua principale
Python
Stelle
3.3k
Fork
471
Merge medio
6g 7h
PR unite (30g)
35

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 SQLMesh/sqlmesh

Tutte le issue di SQLMesh/sqlmesh

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.