Trigger a Function from a Table Commit
By default, functions trigger when any of their input tables receives new data. The trigger_by parameter lets users specify a subset of input tables that should trigger the function instead, or disable automatic triggering entirely.
Needs a transformer. Getting its guide.
Called tabsdata 2 times (ctrl+o to expand)
Generating — trigger_by narrows the default trigger set to orders alone. regions is still read on every run and still supplies its current data, it just no longer starts one.
Called tabsdata 3 times (ctrl+o to expand)
The transformer, registered in sales:
@transformer(
input_tables=["orders", "regions"],
output_tables=["orders_by_region"],
trigger_by=["orders"],
)
def summarize(orders: TableFrameSpec, regions: TableFrameSpec) -> TableFrameSpec:
return orders.group_by("region").agg(col("amount").sum())
This is not about avoiding duplicate runs. A plan that commits both tables runs the transformer once either way, since the plan covers every downstream function and orders them by dependency rather than firing one run per committed table.