Skip to content

Commit

Permalink
fix: add note to summary of read relation about filter (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
mbrobbel authored Sep 21, 2022
1 parent 7e80632 commit a3a2fbc
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 43 deletions.
13 changes: 12 additions & 1 deletion rs/src/parse/relations/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ pub fn parse_read_rel(x: &substrait::ReadRel, y: &mut context::Context) -> diagn
y.set_schema(schema.clone());

// Handle filter.
proto_boxed_field!(x, y, filter, expressions::parse_predicate);
let filter = proto_boxed_field!(x, y, filter, expressions::parse_predicate);

// Handle projection.
if x.projection.is_some() {
Expand All @@ -353,6 +353,17 @@ pub fn parse_read_rel(x: &substrait::ReadRel, y: &mut context::Context) -> diagn
(true, true) => describe!(y, Relation, "Filtered partial read from {}", source.name),
}

// Add filter summary.
if let (Some(filter_node), Some(filter_expr)) = filter {
let nullable = filter_node.data_type().nullable();
summary!(
y,
"This relation discards all rows for which the expression {} yields {}.",
filter_expr,
if nullable { "false or null" } else { "false" }
);
}

// Handle the common field.
handle_rel_common!(x, y);

Expand Down
68 changes: 45 additions & 23 deletions tests/tests/relations/read/filter-project/both.yaml
Original file line number Diff line number Diff line change
@@ -1,26 +1,48 @@
name: read-filter-project
plan:
__test: [ level: i ]
__test: [level: i]
relations:
- rel:
read:
baseSchema:
names: [a, b]
struct:
nullability: NULLABILITY_REQUIRED
types:
- string: { nullability: NULLABILITY_REQUIRED }
- bool: { nullability: NULLABILITY_REQUIRED }
namedTable:
names:
- test
filter:
selection:
rootReference: {}
directReference: { structField: { field: 1 } }
projection:
maintain_singular_struct: true
select:
structItems:
- field: 0
__test: [ type: "STRUCT<string>" ]
- rel:
read:
baseSchema:
names: [a, b]
struct:
nullability: NULLABILITY_REQUIRED
types:
- string: { nullability: NULLABILITY_REQUIRED }
- bool: { nullability: NULLABILITY_REQUIRED }
namedTable:
names:
- test
filter:
selection:
rootReference: {}
directReference: { structField: { field: 1 } }
projection:
maintain_singular_struct: true
select:
structItems:
- field: 0
__test: [comment: "*yields false.", type: "STRUCT<string>"]
- rel:
read:
baseSchema:
names: [a, b]
struct:
nullability: NULLABILITY_REQUIRED
types:
- string: { nullability: NULLABILITY_REQUIRED }
- bool: { nullability: NULLABILITY_NULLABLE }
namedTable:
names:
- test
filter:
selection:
rootReference: {}
directReference: { structField: { field: 1 } }
projection:
maintain_singular_struct: true
select:
structItems:
- field: 0
__test: [comment: "*yields false or null.", type: "STRUCT<string>"]
38 changes: 19 additions & 19 deletions tests/tests/relations/read/filter-project/projection-multiple.yaml
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
name: read-projection-multiple
plan:
__test: [ level: i ]
__test: [level: i]
relations:
- rel:
read:
baseSchema:
names: [a, b]
struct:
nullability: NULLABILITY_REQUIRED
types:
- string: { nullability: NULLABILITY_REQUIRED }
- bool: { nullability: NULLABILITY_REQUIRED }
namedTable:
names:
- test
projection:
select:
structItems:
- field: 1
- field: 0
__test: [ type: "STRUCT<boolean, string>" ]
- rel:
read:
baseSchema:
names: [a, b]
struct:
nullability: NULLABILITY_REQUIRED
types:
- string: { nullability: NULLABILITY_REQUIRED }
- bool: { nullability: NULLABILITY_REQUIRED }
namedTable:
names:
- test
projection:
select:
structItems:
- field: 1
- field: 0
__test: [comment: "", type: "STRUCT<boolean, string>"]

0 comments on commit a3a2fbc

Please sign in to comment.