Skip to content

feat(optimizer): Annotate type for snowflake FLOOR function#6030

Merged
georgesittas merged 2 commits intomainfrom
RD-1042471-annotate-type-for-floor-function
Oct 8, 2025
Merged

feat(optimizer): Annotate type for snowflake FLOOR function#6030
georgesittas merged 2 commits intomainfrom
RD-1042471-annotate-type-for-floor-function

Conversation

@fivetran-amrutabhimsenayachit
Copy link
Collaborator

Annotate type for FLOOR function.

Documentation:
https://docs.snowflake.com/en/sql-reference/functions/floor

@fivetran-amrutabhimsenayachit fivetran-amrutabhimsenayachit changed the title feat(optimizer): Annotate type for FLOOR function feat(optimizer): Annotate type for snowflake FLOOR function Oct 7, 2025
},
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"),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you check that this logic applies for the rest of the dialects that support Floor ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Collaborator

@georgesittas georgesittas Oct 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Collaborator Author

@fivetran-amrutabhimsenayachit fivetran-amrutabhimsenayachit Oct 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@fivetran-amrutabhimsenayachit fivetran-amrutabhimsenayachit force-pushed the RD-1042471-annotate-type-for-floor-function branch from 5bdaad3 to 3c55e7a Compare October 8, 2025 14:47
@georgesittas georgesittas merged commit 6f31b86 into main Oct 8, 2025
6 checks passed
@georgesittas georgesittas deleted the RD-1042471-annotate-type-for-floor-function branch October 8, 2025 16:05
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 this pull request may close these issues.

3 participants