olivrlee commented on code in PR #3984:
URL: https://github.com/apache/calcite/pull/3984#discussion_r1805578141


##########
core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java:
##########
@@ -1217,12 +1219,21 @@ protected void validateNamespace(final 
SqlValidatorNamespace namespace,
         // fields; these are neutralized if the consuming query filters on 
them.
         final ImmutableBitSet mustFilterFields =
             namespace.getMustFilterFields();
-        if (!mustFilterFields.isEmpty()) {
+        // Remnant must filter fields are fields that are not selected and 
cannot

Review Comment:
   I think it is necessary to handle the case where the bypass field is 
selected, but the must-filter fields are not selected. 
   
   Imagine this setup
   ```
   Table: EMP (empno, name, id)
   must_filters: empno
   bypass_filter: name
   ```
   Query:
   `select * from (select name from emp) where name = 'bob' `
   
   The inner query `select name from emp` can't error on `empno` not being 
filtered at this point because `name` was selected, and could be filtered on 
later. The must-filter for `empno` is not satisfied yet at this point. 
   
   When we get to the `select * from _ where name = 'bob'`, that's where we 
defuse the error for `empno` based on seeing `name` being filtered on. 
   
   
   If alternatively the query was 
   `select * from (select name, id from emp) where id = '12' `
   When we get to `select * from _ where id = '12'`, we're at the top-level, 
and remnantMustFilter's set is not empty, hence we throw an error. 
   
   
   



-- 
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]

Reply via email to