Choosing the Right Type
- Adding a column to each row? Use a UDF.
- Splitting each row into multiple rows? Use a Chunker.
- Computing across rows with a different output shape? Use a Batch UDTF.
At a Glance
UDFs (1:1)
Standard UDFs produce exactly one output value per input row. Use them to add computed columns to existing tables or materialized views.
Each input row produces exactly one output value. The new column is added to the same table.
Use cases: Embeddings, data enrichment, format conversion, scoring.
See UDFs for the full guide.
Chunkers (Scalar UDTFs, 1:N)
Chunkers — also called scalar UDTFs — expand each source row into multiple output rows. The output is a materialized view that inherits parent columns and supports incremental refresh. Source:documents
Derived:
chunks (1:N expansion via @chunker)
Each source row produces one or more output rows. Parent columns (
doc_id, title) are inherited automatically.
Use cases: Document chunking, video segmentation, image tiling.
See Chunkers for the full guide.
Batch UDTFs (N:M)
Batch UDTFs read from a source table (or partition) and produce output with an arbitrary schema and row count. They always perform a full refresh. Source:sales
Derived:
sales_summary (N:M aggregation via @udtf)
6 input rows become 2 output rows with a completely different schema. The output shape is determined entirely by the UDTF logic — it could be fewer rows (aggregation), more rows (clustering), or the same count with different columns.
Use cases: Deduplication, clustering, aggregation, cross-row joins.
See Batch UDTFs for the full guide.
API Reference
- UDF —
@udfdecorator andUDFclass - UDTF —
@udtf,@chunker,@batch_udtfdecorators andUDTF/Chunkerclasses - Table —
add_columns(),backfill() - Connection —
create_udtf_view(),create_materialized_view()