Views in Spice are virtual tables defined by SQL queries. They help simplify complex queries and promote reuse across different applications by encapsulating query logic in a single, reusable entity.
To define a view in the spicepod.yaml configuration file, specify the views section. Each view definition must include a name and a sql field.
The following example demonstrates how to define a view named rankings that lists the top five products based on the total count of orders:
name: The view's identifier, used for referencing in queries.sql: The SQL query defining the view, supporting joins, subqueries, and aggregations.acceleration: Views can be locally accelerated.Views derive their schema from the SQL query that defines them. When a view is accelerated, Spice materializes this schema into the acceleration engine at startup.
If the underlying dataset schemas change while the runtime is running, the accelerated view will fail to refresh because the materialized schema no longer matches the source data. Restart the runtime to re-derive the view schema from the updated datasets.
For more detail on schema inference and runtime schema changes, see the Data Connectors schema inference documentation.