feat(optimizer): Annotate type for snowflake FLOOR function#6030
feat(optimizer): Annotate type for snowflake FLOOR function#6030georgesittas merged 2 commits intomainfrom
Conversation
sqlglot/dialects/dialect.py
Outdated
| }, | ||
| exp.Abs: lambda self, e: self._annotate_by_args(e, "this"), | ||
| exp.Anonymous: lambda self, e: self._annotate_with_type(e, exp.DataType.Type.UNKNOWN), | ||
| exp.Floor: lambda self, e: self._annotate_by_args(e, "this"), |
There was a problem hiding this comment.
Did you check that this logic applies for the rest of the dialects that support Floor ?
There was a problem hiding this comment.
Most of the dialects (postgres, redshit, presto, athena, clickhouse, duckdb, trino) return the same data type as the numeric input expression. While some other dialects like bigquery, databricks, hive, mysql, oracle, spark, t-sql do not preserve the input type.
For eg: BigQuery has existing implementation for FLOOR function:
exp.Floor: lambda self, e: _annotate_math_functions(self, e)
This implementation overrides the base dialect.
There was a problem hiding this comment.
How were these tested? Both the fact that the first group preserves and that the second group doesn't preserve. If the type is not preserved, what's the resulting type for the latter group?
There was a problem hiding this comment.
I tested using parse_one. So for the dialects not preserving the input type as per the documentation, sqlglot still preserves the input type as exp.Floor: lambda self, e: self._annotate_by_args(e, "this"), is mentioned in the base dialect.
So just like big query each dialect having different implementation can choose to override the base dialect or I can just move the code from base dialect to snowflake, the latter seems clean.
5bdaad3 to
3c55e7a
Compare
Annotate type for FLOOR function.
Documentation:
https://docs.snowflake.com/en/sql-reference/functions/floor