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
JSON_KEYSis parsed intoexp.JSONKeysAtDepthby 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 againstmain(30.4.3) per source inspection ofsqlglot/dialects/duckdb.py.Reproduction
Executing the output against DuckDB fails:
Expected
JSON_KEYS(x)should transpile to DuckDB'sjson_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'sjson_keyshas no depth parameter. Droppingmax_depthsilently would be lossy; raising on the DuckDB side is another option. Guidance on the preferred direction would be welcome.References
JSON_KEYS: https://cloud.google.com/bigquery/docs/reference/standard-sql/json_functions#json_keysjson_keys: https://duckdb.org/docs/stable/data/json/json_functions.html