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

Offen
#5,770 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 4 Tagen

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Anfängerfreundlichkeit
55/100
Issue-Typ
Bug
Klarheit
Größtenteils klar
Aktivitätsstatus
Ruhig
Tech-Stack
python, sql

Rechercherichtung

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.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

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

Vorherrschende Sprache
Python
Sterne
3.3k
Forks
471
Ø Merge
6 T. 7 Std.
Gemergte PRs (30 T.)
35

Entwicklungsumgebung

In Codespaces öffnen

Startet den Dev-Container des Projekts im Browser, mit Ihrem eigenen GitHub-Konto.

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus SQLMesh/sqlmesh

Alle Issues in SQLMesh/sqlmesh

Ähnliche Issues

Weitere Issues zu Python

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.