Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,18 @@ pub mod materialized;

/// An implementation of Query Rewriting, an optimization that rewrites queries to make use of materialized views.
pub mod rewrite;

/// Configuration options for materialized view related features.
#[derive(Debug, Clone)]
pub struct MaterializedConfig {
/// Whether or not query rewriting should exploit this materialized view.
pub use_in_query_rewrite: bool,
}

impl Default for MaterializedConfig {
fn default() -> Self {
Self {
use_in_query_rewrite: true,
}
}
}
8 changes: 8 additions & 0 deletions src/materialized.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ use datafusion::{
use datafusion_expr::LogicalPlan;
use itertools::Itertools;

use crate::MaterializedConfig;

/// The identifier of the column that [`RowMetadataSource`](row_metadata::RowMetadataSource) implementations should store row metadata in.
pub const META_COLUMN: &str = "__meta";

Expand Down Expand Up @@ -102,6 +104,12 @@ pub fn cast_to_listing_table(table: &dyn TableProvider) -> Option<&dyn ListingTa
pub trait Materialized: ListingTableLike {
/// The query that defines this materialized view.
fn query(&self) -> LogicalPlan;

/// Configuration to control materialized view related features.
/// By default, returns the default value for [`MaterializedConfig`]
fn config(&self) -> MaterializedConfig {
MaterializedConfig::default()
}
}

/// Register a [`Materialized`] implementation in this registry.
Expand Down
4 changes: 4 additions & 0 deletions src/rewrite/exploitation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ impl ViewMatcher {
continue;
};

if !mv.config().use_in_query_rewrite {
continue;
}

// Analyze the plan to normalize things such as wildcard expressions
let analyzed_plan = session_state.analyzer().execute_and_check(
mv.query(),
Expand Down
Loading