Repository navigation
feat: Python table functions on Snowflake - #1610
Merged
Merged
Conversation
Add @table_fn(...) for whole-partition Python table functions. Each call receives one partition as a data frame, polars by default or pandas from a pd.DataFrame annotation or the [defaults] function_dataframe setting, and returns a data frame matching its declared returns columns. Calls must use OVER (PARTITION BY ...), checked at compile time in models, function bodies and SQL tests. Polars functions reject fractional NUMBER arguments. Snowflake deploys a vectorized end_partition handler that checks the returned columns.
Comments before OVER and inside its clause no longer hide the partition. The generated Snowflake handler prefixes its locals so any entry point name works, and names repeated returned columns. DEC counts as a fixed-point type for polars arguments. The docs state how the frame annotation is read.
The partition check, analysis, SQL-test markers and Snowflake rendering now skip each dialect's own line comments, such as Snowflake's //, before OVER and inside it.
github-merge-queue
Bot
removed this pull request from the merge queue due to failed status checks
Nov 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Per-group work such as smoothing a series is hard in SQL, and projects had no Python table functions, so it lived outside the project.
Changes
functions/python/<name>.pymay define one@table_fn(...)function withreturnsas a column-to-type map. It gets one whole partition as a data frame and returns rows.pd.DataFrameannotation picks pandas, and[defaults] function_dataframe = "pandas"changes the project default.OVER (PARTITION BY ...)in models, functions and SQL tests, or compilation fails. Snowflake rendersTABLE(fn(args) OVER (...)); analysis and SQL tests treat the clause as part of the call.pandas(pluspolars,pyarrow).NUMBER/DECIMAL/DEC/NUMERICargument fails compilation.functions.mdx; fixedruntime_version(required), the adapter table, and the testing reference's claim that models can't depend on table functions.Goldens:
config-unknown-default-keylists the new allowed key; the macro-expansion oracle gains the call's partition flag.DuckShop: n/a; DuckDB has no Python table functions.
Verification
OVERhandling, Snowflake DDL and the generated handler.TEST(mode table_fn), and a wrong-columns function failed naming them; schema dropped.make test(only stale-local-version checks fail) andmake check-cion the final head.