exmy opened a new pull request, #12818:
URL: https://github.com/apache/gluten/pull/12818

   
   ## What changes are proposed in this pull request?
   
   This PR fixes incorrect nullable filtering after Expand in the ClickHouse
   backend.
   
   The changes:
   
   - Materialize constant selection columns in regular Expand.
   - Apply the same behavior to AdvancedExpand.
   - Preserve nullable types for NULL literals.
   - Add regression tests for both regular and lazy aggregate Expand paths.
   
   Expand emits each grouping-set projection as a separate chunk.
   
   When a selected input column originates from a SQL literal, `castColumn`
   may preserve it as a `ColumnConst`. In the reproducing query, the first
   chunk contains a constant non-null `msg_type`, so `isNotNull(msg_type)`
   produces a constant true filter.
   
   The ClickHouse `FilterTransform` version used by the backend preserves
   `ConstantFilterDescription` between chunks. It checks the previous
   `always_true` state before recalculating the filter for the current chunk.
   
   As a result, the following chunk, whose `msg_type` is a real nullable NULL,
   can bypass filtering and produce extra grouping-set rows.
   
   For example:
   
   ```sql
   select msg_type, os, count(*) as cnt
   from (
     select 'file' as msg_type, 'Android' as os, id from range(10)
     union all
     select 'file' as msg_type, 'iOS' as os, id from range(10)
   ) t
   group by grouping sets ((msg_type), (os))
   having msg_type is not null
   order by msg_type, os, cnt
   ```
   
   the incorrect result was:
   
   
   ```text
   NULL  Android  10
   NULL  iOS      10
   file  NULL     20
   ```
   
   The expected result is:
   ```text
   file  NULL  20
   ```
   
   Materialize constant selection columns in regular and advanced Expand to 
prevent stale constant filter state from leaking null rows. Preserve nullable 
types for null literals and add regression coverage for both Expand paths.
   
   ## How was this patch tested?
   
   add ut
   
   ## Was this patch authored or co-authored using generative AI tooling?
   
   Codex
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to