From 2e1a26ec42dc8685f539f167c6afa7c665b3178f Mon Sep 17 00:00:00 2001 From: Carson Date: Mon, 31 Aug 2026 16:42:08 -0500 Subject: [PATCH] fix(python): filter before projecting in IbisSource categorical stats 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. --- pkg-py/src/querychat/_datasource.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pkg-py/src/querychat/_datasource.py b/pkg-py/src/querychat/_datasource.py index 556bfac6..cffcf154 100644 --- a/pkg-py/src/querychat/_datasource.py +++ b/pkg-py/src/querychat/_datasource.py @@ -1182,12 +1182,15 @@ def _add_column_stats( subqueries: list[ibis.Table] = [] for col in categorical_cols: + # Filter before projecting: the predicate must belong to the + # relation being filtered, else Snowflake (ibis >= 12) raises + # IntegrityError. subq = ( - table.select( + table.filter(table[col.name].notnull()) + .select( ibis.literal(col.name).name("_col_name"), table[col.name].cast("string").name("_value"), ) - .filter(table[col.name].notnull()) .distinct() ) subqueries.append(subq)