Module mz_transform::fusion::filter

source ·
Expand description

Fuses multiple Filter operators into one and canonicalizes predicates.

If the Filter operator is empty, removes it.

use mz_expr::{MirRelationExpr, MirScalarExpr};
use mz_repr::{ColumnType, Datum, RelationType, ScalarType};
use mz_repr::optimize::OptimizerFeatures;
use mz_transform::{typecheck, Transform, TransformCtx};
use mz_transform::dataflow::DataflowMetainfo;

use mz_transform::fusion::filter::Filter;

let input = MirRelationExpr::constant(vec![], RelationType::new(vec![
    ScalarType::Bool.nullable(false),
]));

let predicate0 = MirScalarExpr::Column(0);
let predicate1 = MirScalarExpr::Column(0);
let predicate2 = MirScalarExpr::Column(0);

let mut expr = input
    .clone()
    .filter(vec![predicate0.clone()])
    .filter(vec![predicate1.clone()])
    .filter(vec![predicate2.clone()]);

let features = OptimizerFeatures::default();
let typecheck_ctx = typecheck::empty_context();
let mut df_meta = DataflowMetainfo::default();
let mut transform_ctx = TransformCtx::local(&features, &typecheck_ctx, &mut df_meta);

// Filter.transform() will deduplicate any predicates
Filter.transform(&mut expr, &mut transform_ctx);

let correct = input.filter(vec![predicate0]);

assert_eq!(expr, correct);

Structs§

  • Fuses multiple Filter operators into one and deduplicates predicates.