Skip to content

[core] Fix BranchesTable returning empty result for non Equal/IN predicates#7848

Merged
JingsongLi merged 2 commits into
apache:masterfrom
heye1005:fix-branches-table-empty-on-non-eq-in-predicate
May 14, 2026
Merged

[core] Fix BranchesTable returning empty result for non Equal/IN predicates#7848
JingsongLi merged 2 commits into
apache:masterfrom
heye1005:fix-branches-table-empty-on-non-eq-in-predicate

Conversation

@heye1005
Copy link
Copy Markdown
Contributor

@heye1005 heye1005 commented May 14, 2026

Purpose

BranchesRead#withFilter is a // TODO, and BranchesRead#branches()
only handles Equal / OR-IN on branch_name inside
if (predicate != null) with no else. Pushing any other predicate
into BranchesRead returns an empty result:

rb.withFilter(builder.notEqual(0, BinaryString.fromString("b2")));
// [] on master, expected: all branches except b2

@heye1005 heye1005 force-pushed the fix-branches-table-empty-on-non-eq-in-predicate branch from fbeb091 to 3044600 Compare May 14, 2026 04:58
…icates

BranchesRead#withFilter is currently a // TODO, and BranchesRead#branches()
only handles two scan-side fast paths (Equal and OR-IN on branch_name)
inside if (predicate != null) with no fallback. As a result, any caller
that pushes a non-Equal/IN predicate into BranchesRead gets an empty
result instead of "list all and let the post-filter refine":

    ReadBuilder rb = branchesTable.newReadBuilder()
            .withFilter(builder.notEqual(0, BinaryString.fromString("b2")));
    // returns 0 rows on master, should return all branches except b2

Today this is a latent issue at the SQL layer: Flink does not push
<>, LIKE, or cross-field OR into the paimon source for system tables,
so the filter is applied above the source and users see correct
results. But the InnerTableRead contract is still broken, and any
future caller (other engines, custom readers, or expanded Flink
push-down) that hands such a predicate to BranchesRead will silently
lose data.

Fix:
* drop the implicit else: each fast path now returns as soon as it
  fully consumes the predicate, and the listing loop sits at the end
  of the method, reached by any predicate shape no fast path can
  answer (Equal on a different field, AND, NotEqual, LIKE, etc.);
* tighten the OR fast path so it only short-circuits when
  InPredicateVisitor can actually flatten the OR back to an IN over
  branch_name; otherwise fall through to the listing fallback;
* implement BranchesRead#withFilter as a read-side post-filter that
  evaluates the predicate on the materialized row before projection.

Tests:
* BranchesTableTest drives InnerTableRead directly via PredicateBuilder
  (the bug is reproducible there: testReadWithBranchNameNotEqualFilter
  fails on master, passes after the fix).
* BranchSqlITCase#testBranchesTableFilter is extended with <>, LIKE,
  and "OR that is not an IN" cases. These also pass on master since
  Flink does not push these predicates down today; included as smoke
  tests to ensure the fix does not break the planner-level fallback
  path.
@heye1005 heye1005 force-pushed the fix-branches-table-empty-on-non-eq-in-predicate branch from 3044600 to 3490ad9 Compare May 14, 2026 06:10
@JingsongLi
Copy link
Copy Markdown
Contributor

+1

@JingsongLi JingsongLi merged commit be19168 into apache:master May 14, 2026
12 checks passed
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