Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add note to summary of read relation about filter #54

Merged
merged 1 commit into from
Sep 21, 2022
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
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>"]