Fix IbisSource IntegrityError on Snowflake with ibis >= 12 (filter before projecting categorical stats) - #282
Merged
Conversation
The categorical-stats subquery applied .filter() after .select(), leaving a NotNull predicate bound to the base table on a Filter whose parent is the projection. Snowflake (ibis >= 12) rejects this with IntegrityError. Filter before projecting instead.
cpsievert
force-pushed
the
fix/ibis-categorical-stats-integrity-error
branch
from
August 31, 2026 21:45
b256efd to
2e1a26e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
IbisSource.populate_column_stats()raises on Snowflake withibis-framework >= 12 when a table has 2+ low-cardinality text columns:
The categorical-stats subqueries were built as:
The
NotNullpredicate belongs to the basetablerelation, but.filter()is called on the projection returned by.select(). Ibis 12'sFilter.__init__rejects predicates whose relations don't include thefilter's parent, and Snowflake's compile path constructs that invalid
Filternode directly.Two details made this easy to miss:
ibis.union()with one argumentreturns its input unchanged, so the union path that exposes the issue is
never hit.
predicate and pushes the filter below the projection, masking the bug.
Fix
Filter before projecting, so the predicate belongs to the relation being
filtered:
The subquery construction is extracted into
IbisSource._categorical_values_subquery()so the invariant is directlytestable. No behavior change otherwise.
Tests
Filternode's parent is thebase
DatabaseTable(not aProject). This is the faithful repro —verified it fails on the old expression shape and passes on the new one.
A behavioral DuckDB test alone cannot catch this bug.
populate_column_statspopulates categories for 2+low-cardinality text columns and excludes nulls.
Notes
categorical_threshold=0toQueryChat().than ibis expression graphs.