Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

json_format(to_json()) fails (trino -> spark) #1547

Closed
joshmarcus opened this issue May 4, 2023 · 2 comments
Closed

json_format(to_json()) fails (trino -> spark) #1547

joshmarcus opened this issue May 4, 2023 · 2 comments

Comments

@joshmarcus
Copy link

joshmarcus commented May 4, 2023

When translating SQL like json_format(to_json(column)) from read='trino' to write='spark', it's translated as:
TO_JSON(TO_JSON(column)) which fails in SparkSQL, as TO_JSON doesn't accept the return type of TO_JSON.

query = "select json_format(to_json(column)) from table"
sqlglot.transpile(query, read="trino", write="spark")

returns

['SELECT TO_JSON(TO_JSON(column)) FROM table']

expected:

['SELECT TO_JSON(column) FROM table']
@joshmarcus
Copy link
Author

Locally, I just drop JSON_FORMAT() instead of converting it to TO_JSON().

@georgesittas
Copy link
Collaborator

I can take a look soon, but it seems that TO_JSON is not in Trino's docs and indeed it throws an error for me:

trino> SELECT json_format(to_json('[1, 2, 3]'));
Query 20230504_171741_00002_uihyy failed: line 1:20: Function 'to_json' not registered
SELECT json_format(to_json('[1, 2, 3]'))

It works with SELECT JSON_FORMAT(JSON '[1, 2, 3]'), although it's not parsed correctly atm in SQLGlot.

@tobymao tobymao closed this as completed in aef9cfa May 5, 2023
adrianisk pushed a commit to adrianisk/sqlglot that referenced this issue Jun 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants