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

未关闭
#5,770 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 4 天内回复

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
55/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
冷清
技术栈
python, sql

调研方向

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.

由索引模型根据 Issue 内容生成。

描述

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

主要语言
Python
星标
3.3k
派生
471
平均合并
6 天 7 小时
30 天内合并 PR
35

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

SQLMesh/sqlmesh 的其他 Issue

查看 SQLMesh/sqlmesh 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。