Skip to content

Commit 1183d06

Browse files
authored
Merge pull request MaterializeInc#10435 from aalexandrov/qgm-rejected-nulls
2 parents 9b8d6a4 + 7910d6b commit 1183d06

File tree

4 files changed

+600
-15
lines changed

4 files changed

+600
-15
lines changed

src/sql/src/query_model/attribute/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@
1010
//! Derived attributes framework and definitions.
1111
1212
pub mod core;
13-
pub mod non_null_requirements;
13+
pub mod propagated_nulls;
14+
pub mod rejected_nulls;

src/sql/src/query_model/attribute/non_null_requirements.rs renamed to src/sql/src/query_model/attribute/propagated_nulls.rs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
// the Business Source License, use of this software will be governed
88
// by the Apache License, Version 2.0.
99

10-
//! Defines the [`NonNullRequirements`] attribute.
10+
//! Defines the [`PropagatedNulls`] attribute.
1111
//!
1212
//! The attribute value is a vector of column references corresponding
1313
//! to the columns of the associated `QueryBox`.
@@ -20,15 +20,15 @@ use crate::query_model::model::{BoxId, BoxScalarExpr, ColumnReference, Model};
2020
use std::collections::HashSet;
2121

2222
#[derive(Debug, PartialEq, Eq, Clone, Hash)]
23-
pub(crate) struct NonNullRequirements;
23+
pub(crate) struct PropagatedNulls;
2424

25-
impl AttributeKey for NonNullRequirements {
25+
impl AttributeKey for PropagatedNulls {
2626
type Value = Vec<HashSet<ColumnReference>>;
2727
}
2828

29-
impl Attribute for NonNullRequirements {
29+
impl Attribute for PropagatedNulls {
3030
fn attr_id(&self) -> &'static str {
31-
"NonNullRequirements"
31+
"PropagatedNulls"
3232
}
3333

3434
fn requires(&self) -> Vec<Box<dyn Attribute>> {
@@ -41,19 +41,19 @@ impl Attribute for NonNullRequirements {
4141
let value = r#box
4242
.columns
4343
.iter()
44-
.map(|x| non_null_requirements(&x.expr))
44+
.map(|x| propagated_nulls(&x.expr))
4545
.collect::<Vec<_>>();
4646

4747
// TODO: remove this
4848
// println!("|box[{}].columns| = {:?}", box_id, r#box.columns.len());
4949
// println!("attr[{}] = {:?}", box_id, value);
5050

51-
r#box.attributes.set::<NonNullRequirements>(value);
51+
r#box.attributes.set::<PropagatedNulls>(value);
5252
}
5353
}
5454

5555
/// Returns all columns that *must* be non-Null for the `expr` to be non-Null.
56-
pub(crate) fn non_null_requirements(expr: &BoxScalarExpr) -> HashSet<ColumnReference> {
56+
pub(crate) fn propagated_nulls(expr: &BoxScalarExpr) -> HashSet<ColumnReference> {
5757
use BoxScalarExpr::*;
5858
let mut result = HashSet::new();
5959

@@ -86,9 +86,12 @@ pub(crate) fn non_null_requirements(expr: &BoxScalarExpr) -> HashSet<ColumnRefer
8686
Some(vec![])
8787
}
8888
}
89-
// The branches of an if are computed lazily, but the condition is not
90-
// so we can descend into it safely
91-
If { cond, .. } => Some(vec![cond]),
89+
// The branches of an if are computed lazily, but the condition is not.
90+
// However, nulls propagate to the condition are cast to false.
91+
// Consequently, we currently don't do anything here.
92+
// TODO: I think we might be able to take use the intersection of the
93+
// results in the two branches.
94+
If { .. } => Some(vec![]),
9295
// TODO the non-null requeriments of an aggregate expression can
9396
// be pused down to, for example, convert an outer join into an
9497
// inner join
@@ -133,19 +136,19 @@ mod tests {
133136
exp::gt(exp::cref(q_id, 0), exp::cref(q_id, 1)),
134137
exp::gt(exp::cref(q_id, 2), exp::cref(q_id, 3)),
135138
));
136-
// C1: (#0 > #1) && isnull(#1)
139+
// C2: (#0 > #1) && isnull(#1)
137140
b.add_column(exp::and(
138141
exp::gt(exp::cref(q_id, 0), exp::cref(q_id, 1)),
139142
exp::not(exp::isnull(exp::cref(q_id, 1))),
140143
));
141144
}
142145

143-
NonNullRequirements.derive(&mut model, s_id);
146+
PropagatedNulls.derive(&mut model, s_id);
144147

145148
{
146149
let s_box = model.get_box(s_id);
147150

148-
let act_value = s_box.attributes.get::<NonNullRequirements>();
151+
let act_value = s_box.attributes.get::<PropagatedNulls>();
149152
let exp_value = &vec![
150153
HashSet::from([cref(q_id, 0), cref(q_id, 1), cref(q_id, 2), cref(q_id, 3)]),
151154
HashSet::from([]),

0 commit comments

Comments
 (0)