Materialized Datasets
Here’s a rundown of how dataset materialization works, what to expect, and when to use it.
What are Materialized Datasets
By default, a SQL Transformation based dataset is published as a database view: its SQL runs every time an agent, report, or app queries it. This keeps results current, but large or complex statements can be slow.
Enabling Materialization stores the results as physical rows that contains the output of the full SQL. It then refreshes automatically in the background based on an interval or as data changes. Queries against the dataset then read those stored results, making them faster. The trade-off is that the data is only as fresh as the last refresh.
Due to possible cost and complexity, materialization can only be enabled by Ninjacat Support.
What to expect when we turn it on — or change its SQL
Temporary downtime: When a transformation for a materialized dataset changes, the physical copy of the data must be immediately rebuilt. Until the first build finishes, anything querying it—including agents and scheduled runs—may fail with an error like “does not exist or not authorized.”
Build time depends on size and complexity of the SQL and source datasets: smaller datasets may take minutes; very large ones can take longer.
Every SQL edit triggers a full rebuild, even a one-line change, so the same downtime applies after each edit. Plan materializations and SQL changes for a quiet time, rather than right before a scheduled agent run. Once the dataset preview loads again, it’s ready.
How refreshing works
The system will attempt to create the materialized dataset that will prioritize freshness whenever possible. However limitations imposed by Snowflake may cause slower refresh cycles. You can see the refresh schedule in the Dataset Details page:
Modes:
Incremental: (Preferred) - When the SQL allows, the dataset will refresh Incrementally - only updating when source data changes and only modifying output rows that would be impacted by the source change. This is generally fast and have a low latency (lag) for refresh.
Auto: Tries to process only new or changed data—called an “incremental” refresh. If the SQL doesn’t support that, it recomputes the entire dataset.
- Full: Recomputes the entire dataset every time. This uses more compute, so it’s best reserved for cases that need it.
- Refresh interval: Defaults are approximately every 20 minutes for incremental refreshes and every 2 hours for full refreshes. The interval can be set between 20 minutes and 12 hours; this determines the expected freshness of the stored data.
Notes on refresh modes
Time-based functions: CURRENT_TIMESTAMP and CURRENT_DATE prevent incremental refresh. That’s why a dataset that filters on CURRENT_DATE rebuilds in full each time. Filtering on dates in the data itself, or moving the “today” logic into the agent or report, can allow incremental refresh.
Dataset chains: If one materialized dataset feeds another, the upstream dataset refreshes when the downstream dataset needs fresh data. Plan Materialized chains from upstream to downstream.
When materialization is a good fit
- Large or computationally heavy datasets with complex joins, window functions, many CTEs, or UNIONs
- Datasets queried frequently by agents, scheduled runs, or dashboards
- Stable SQL where some delay in data freshness is acceptable
When to keep a view
- Small or lightweight datasets that are already fast
- SQL you’re still actively building or changing
- Use cases that need up-to-the-minute data
Best practices
- Finish and test the SQL as a view before requesting materialization.
- Schedule materializations and SQL edits during a quiet period, and confirm the preview loads before the next scheduled run.
- Avoid CURRENT_TIMESTAMP and CURRENT_DATE where possible to support incremental refresh.
- Choose the longest refresh interval your use case can tolerate (via Support).
- If an agent errors immediately after a dataset change, let the rebuild finish, then retry. A temporary error during the rebuild is expected.
- In Data Management, look for the “M” icon in the lineage graph. The dataset’s details page shows its refresh mode and last refresh.
Monitor Materialization Refresh Status
For transformation datasets that have been enabled with materialization (set up with NinjaCat support), the Dataset Details page shows an additional Materialization panel alongside the publish status. This panel surfaces the current state of the materialized dataset's refresh pipeline directly in the UI — no need to contact support or inspect backend logs.
NoteThe Materialization panel only appears for datasets that have been flagged as materialized. It will not be visible on standard transformation datasets. This feature can only be enabled by the Ninjacat team, on an as-needed basis.
The Materialization panel
The panel contains the following fields, displayed using their exact UI labels:
| Field | Description |
|---|---|
| Refresh Mode: | How the materialized dataset refreshes — for example, INCREMENTAL or AUTO. |
| Reason: | Shown when Incremental mode could not be used. You can use this as a hint to improve the SQL statements to enable incremental refreshes. |
| Last Refresh: | The result of the most recent refresh attempt — for example, SUCCEEDED or FAILED. |
| Error: | When Last Refresh is FAILED, an Error: line appears beneath it with the specific error detail. |
| Freshness: | How current the materialized data is. |
| Lag vs Target: | How far behind the target lag the data currently is. An Over target indicator appears when the lag exceeds the configured target. This is an average, so freshly built/fixed datasets may take a while before this number reflects current health. |
| Scheduling: | Whether refreshes are currently Scheduled or Suspended. Suspended materialized datasets are no longer refreshing and require intervention. See the note below. |
| Estimated Rows: | The estimated row count of the materialized dataset. |
| Size: | The storage size of the materialized dataset. |
Refresh Mode cost note
INCREMENTAL refreshes are preferred as only portions of the data that have been modified need to be computed for change. This means that updates to data are available more quickly and with a lower compute cost.
However, several factors can prevent INCREMENTAL refreshes. When Refresh Mode is not INCREMENTAL (AUTO or another full-refresh mode), the frequency of data refreshes is reduced, and changes to source data require that the full target table be rebuilt. When running in an AUTO or FULL refresh mode the panel may display the following notice:
"Full/Auto refresh mode may incur additional costs due to compute requirements."
Review this with your NinjaCat account team if you have questions about the performance or compute cost implications for your materialized datasets.
Suspended refreshes
When Scheduling is Suspended, the panel displays a Refreshes Suspended callout. Suspended refreshes mean the materialized dataset is no longer being updated on its schedule. This is typically due to errors in the SQL or input datasets. Fix the underlying error(s) in the SQL, based on the errors noted in the materialization block. If the source of the error is due to a change to a parent (input) dataset, fix the upstream issues and then click "Republish Latest" on the suspended dataset. Contact NinjaCat support if this does not resolve the issues with a materialized transformation.
Served as a view
If a materialized dataset is currently being served as a view rather than a materialized table, this means the Transformation is unable to be processed as a Materialized view. The panel will display the following notice instead of the standard refresh fields:
"This materialized transformation is currently served as a view, so there is no dynamic-table refresh status."
This typically occurs during initial setup or following a refresh failure that caused a downgrade from materialized table to view. Contact support for assistance with this issue.
Troubleshooting with the Materialization panel
| Scenario | What to check |
|---|---|
| Data appears stale | Check Freshness and Lag vs Target. An Over target indicator means data is behind schedule. |
| Last refresh failed | Review the Error: detail line beneath Last Refresh for the specific failure reason. |
| Refreshes stopped running | Check Scheduling — a Refreshes Suspended callout means the refresh schedule is paused. Try editing the transformation to correct any errors and re-save. Contact NinjaCat support for additional assistance. |
| Panel shows "served as a view" | The dataset has been downgraded from a materialized table to a view. Check the Error: line (if visible) and contact NinjaCat support. |
| Unexpected compute costs | Review Refresh Mode — AUTO or full-refresh modes consume more compute. Check the message for why Snowflake is unable to enable incremental updates and attempt to modify the query to address the underlying issues. |
Common issues that force FULL or AUTO refresh
To reduce data latency and compute, it's best to structure any SQL transformation so that INCREMENTAL refreshes can be applied.
- Avoid the use of DOUBLE or FLOAT data types. When building queries make sure to avoid the use of floating point numbers. Use a static precision/scale NUMBER(scale, precision) data type (ie:
NUMBER(20, 4)) - Use Common Table Expressions (CTEs) instead of nested SQL statements. Meaning, avoid `SELECT ... FROM ( SELECT ... ) WHERE ...
- Don't use non-deterministic functions or keywords like
CURRENT_TIMESTAMP,ANY_VALUE(...), etc that change on every execution
Implementation notes
If you want to do additional research on how to optimize SQL or build ETL processes using materialized datasets, they are implemented in snowflake as Dynamic Tables. All snowflake documentation on optimizing dynamic tables applies to materialized datasets.
Related articles
- Track Changes to Transformation Datasets with Version History
- Transform Data with SQL Transform Builder
- Managing Your Datasets in Data Cloud
Updated 9 days ago