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

Incorrect parsing of column a name when an identifier is used in Snowflake TIMEDIFF in the qualify method #1851

Closed
wezham opened this issue Jun 29, 2023 · 3 comments

Comments

@wezham
Copy link
Contributor

wezham commented Jun 29, 2023

As stated in the snowflake documentation the signature for timediff

TIMEDIFF( <date_or_time_part> , <date_or_time_expr1> , <date_or time_expr2> )

date_or_time_part
The unit of time. Must be one of the values listed in Supported Date and Time Parts (e.g. month). The value can be a string literal or can be unquoted (e.g. 'month' or month).

However, when using the unquoted argument like YEAR instead of 'YEAR', qualify sees the argument as a column and attempts to resolve it in the schema. For example you can see the code block below:

table_schema = {"sample_table": {"created_at": "timestamp_tz"}}
sql_query = "SELECT TIMEDIFF(YEAR, created_at, current_timestamp()) from sample_table;"
expression_ = qualify(
    parse_one(sql_query),
    dialect="snowflake",
    qualify_columns=True,
    validate_qualify_columns=True,
    expand_alias_refs=True,
    schema=table_schema,
)

Results in

    raise OptimizeError(
sqlglot.errors.OptimizeError: Column '"YEAR"' could not be resolved
@tobymao
Copy link
Owner

tobymao commented Jun 29, 2023

you need to specify dialect in parse_one

parse_one(sql, read="snowflake")

@tobymao
Copy link
Owner

tobymao commented Jun 29, 2023

separately we need to implement timediff

@wezham
Copy link
Contributor Author

wezham commented Jun 29, 2023

Yep that was my error when re-producing. Thanks

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