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

Date casting function does not transpile correctly from Spark SQL to Snowflake SQL #4707

Closed
jiangli001 opened this issue Feb 5, 2025 · 0 comments · Fixed by #4713
Closed
Assignees

Comments

@jiangli001
Copy link

Reproducible code:

import sqlglot
sql = """select to_date(some_column, "yyyy-MM-dd) from df"""
print(sqlglot.parse_one(sql, "spark").sql("snowflake"))

The output is:

SELECT TO_DATE(some_column, 'yyyy-mm-DD') FROM df

The problem is that the to_date() function behaves differently in Spark and in Snowflake. In Spark, it returns NULL if the input does not match the format provided. In Snowflake, it raises an error if the input does not match the format provided. The correct transpiled function in Snowflake should be TRY_TO_DATE(), which returns a NULL value instead of raising an error.

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

Successfully merging a pull request may close this issue.

2 participants