You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+15-3Lines changed: 15 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,9 +2,9 @@
2
2
3
3
An implementation of incremental view maintenance & query rewriting for materialized views in DataFusion.
4
4
5
-
A **materialized view** is a view whose query has been pre-computed and saved for later use. This can drastically speed up workloads by pre-computing at least a large fragment of a user-provided query. Furthermore, by implementing a _view matching_ algorithm, we can implement an optimizer that rewrites queries to automatically make use of materialized views where possible and beneficial, a concept known as *query rewriting*.
5
+
A **materialized view** is a view whose query has been pre-computed and saved for later use. This can drastically speed up workloads by pre-computing at least a large fragment of a user-provided query. Furthermore, by implementing a _view matching_ algorithm, we can implement an optimizer that rewrites queries to automatically make use of materialized views where possible and beneficial, a concept known as _query rewriting_.
6
6
7
-
Efficiently maintaining the up-to-dateness of a materialized view is a problem known as *incremental view maintenance*. It is a hard problem in general, but we make some simplifying assumptions:
7
+
Efficiently maintaining the up-to-dateness of a materialized view is a problem known as _incremental view maintenance_. It is a hard problem in general, but we make some simplifying assumptions:
8
8
9
9
* Data is stored as Hive-partitioned files in object storage.
10
10
* The smallest unit of data that can be updated is a single file.
@@ -14,7 +14,7 @@ This is a typical pattern with DataFusion, as files in object storage usually ar
14
14
## Example
15
15
16
16
Here we walk through a hypothetical example of setting up a materialized view, to illustrate
17
-
what this library offers. The core of the incremental view maintenance implementation is a UDTF (User-Defined Table Function),
17
+
what this library offers. The core of the incremental view maintenance implementation is a UDTF (User-Defined Table Function),
18
18
called `mv_dependencies`, that outputs a build graph for a materialized view. This gives users the information they need to determine
19
19
when partitions of the materialized view need to be recomputed.
20
20
@@ -52,3 +52,15 @@ SELECT * FROM mv_dependencies('m1');
As of now, actually implementing materialized views is somewhat complicated, as the library is initially focused on providing a minimal kernel of functionality that can be shared across multiple implementations of materialized views. Broadly, the process includes these steps:
58
+
59
+
* Define a custom `MaterializedListingTable` type that implements `Materialized`
60
+
* Register the type globally using the `register_materialized` global function
61
+
* Initialize the `FileMetadata` component
62
+
* Initialize the `RowMetadataRegistry`
63
+
* Register the `mv_dependencies` and `stale_files` UDTFs (User Defined Table Functions) in your DataFusion `SessionContext`
64
+
* Periodically regenerate directories marked as stale by `stale_files`
65
+
66
+
A full walkthrough of this process including implementation can be seen in an integration test, under [`tests/materialized_listing_table.rs`](tests/materialized_listing_table.rs).
0 commit comments