Note: This is similar to how traditional databases offer a materialized view feature to declaratively manage expensive aggregation and join operations.
Process Overview
The process is straightforward:- Define a query on table, optionally including UDFs in the select clause.
- Create the materialized view using
db.create_materialized_view(...). - Populate the new materialized view table using the
refreshoperation.
Example
Let’s walk through an example using a raw video table as a base. We want to create a materialized view off the table that adds transcription columns to a subset of the values.refresh.
add_columns, backfill particular columns and deriving other materialized views or views from them.
Reference:
FAQ
Do we copy the UDFs from the source table?
No. The UDF does not but any UDF calculated values in the original table come to the materialized table via refresh. New columns defined by the UDFs in the materialized view creation are attached only to the materialized view. They can be backfilled (since the UDF belongs to the view) or refreshed.On MV refresh, do we force materialization of UDFs cols on the source table?
No. They are managed at the source table only. If it is null the null values are propagated. Future options may force materialization/backfill “recursively”.API Reference
- Connection —
create_materialized_view(),create_view() - Table —
refresh(),plan_refresh() - Query —
create_materialized_view()on query builder