Skip to content

fix: preserve mandatory read and post-join filters - #1260

Draft
bvolpato wants to merge 1 commit into
substrait-io:mainfrom
bvolpato:bvolpato/fix-mandatory-predicates
Draft

fix: preserve mandatory read and post-join filters#1260
bvolpato wants to merge 1 commit into
substrait-io:mainfrom
bvolpato:bvolpato/fix-mandatory-predicates

Conversation

@bvolpato

@bvolpato bvolpato commented Sep 3, 2026

Copy link
Copy Markdown
Member

Mandatory ReadRel filters and JoinRel post-join filters are currently dropped when converting plans to Calcite or Spark. A read carrying FALSE therefore returns its input rows, and an outer join loses predicates that should inspect its null-extended output.

For example, this scan must produce no rows, but Isthmus currently returns an unrestricted TableScan:

NamedScan scan = NamedScan.builder()
    .addNames("t")
    .initialSchema(NamedStruct.of(
        List.of("id"), TypeCreator.REQUIRED.struct(TypeCreator.REQUIRED.I32)))
    .filter(ExpressionCreator.bool(false, false))
    .build();
new SubstraitToCalcite(ConverterProvider.DEFAULT).convert(scan);

Apply mandatory scan filters before emit remapping and post-join filters after the join, using the actual output schema. Decode protobuf post-join references against that same schema so outer-join nullability is preserved and IS NULL cannot be incorrectly simplified away. These semantics follow spec v0.102.0.

Partially addresses #1204 for mandatory read filtering.

Apply embedded read predicates before emit remapping and post-join
predicates against the actual join output in Isthmus and Spark. Decode
post-join references using the output schema so outer-join nullability
survives protobuf conversion.
@alexandrefimov

Copy link
Copy Markdown
Contributor

Heads-up on an overlap: ReadRel.projection, one of the three fields #1204 names, is in #1280 -- it applies the mask in visit(NamedScan) and visit(VirtualTableScan), where your applyFilter calls also sit.

The two compose: the filter stays on the scan, the mask goes above it, the emit mapping above that -- a filter is read against the direct schema, before the projection (spec v0.102.0, Read Filtering). Whichever of us lands second rebases, and I am glad to be that one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants