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


##########
core/src/main/java/org/apache/calcite/sql/validate/MustFilterRequirements.java:
##########
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.calcite.sql.validate;
+
+import org.apache.calcite.util.ImmutableBitSet;
+
+import com.google.common.collect.ImmutableSet;
+
+import java.util.Set;
+
+/**
+ * Class that encapsulates filtering requirements when overloading 
SemanticTable.
+ *
+ * <p>mustFilterFields: the ordinals (in the row type) of the "must-filter" 
fields,
+ * fields that must be filtered in a query.
+ * <p> mustFilterBypassFields: the ordinals (in the row type) of the "bypass" 
fields,
+ * fields that can defuse validation errors on mustFilterFields if filtered on.
+ * <p> remnantMustFilterFields: Set of mustFilterField SqlQualifieds that have 
not been defused
+ * in the current query, but can still be defused by filtering on a bypass 
field in the
+ * enclosing query.
+ */
+public class MustFilterRequirements {

Review Comment:
   Must the class be `public`?
   
   Class names should not be plural (except utility classes). It becomes 
problematic to name collections of such classes.
   
   'Must' and 'Requirement' seem redundant. So I suggest 'FilterRequirement'.
   
   Maybe `mustFilterFields` &rarr; `filterFields`, `mustFilterBypassFields` 
&rarr; `bypassFields`; `remnantMustFilterFields` &rarr; `filterAnyFields`.
   
   Could the fields be `final`? (Public final fields are fine, but if you must 
have non-final fields they should probably be `private`.)
   
   Immutable classes are much easier to reason about. Consider adding 'withXxx' 
methods.



##########
core/src/main/java/org/apache/calcite/sql/validate/TableNamespace.java:
##########
@@ -61,22 +61,19 @@ private TableNamespace(SqlValidatorImpl validator, 
SqlValidatorTable table,
   }
 
   @Override protected RelDataType validateImpl(RelDataType targetRowType) {
-    this.mustFilterFields = ImmutableBitSet.of();
     table.maybeUnwrap(SemanticTable.class)
-        .ifPresent(semanticTable ->
-            this.mustFilterFields =
-                table.getRowType().getFieldList().stream()
-                    .map(RelDataTypeField::getIndex)
-                    .filter(semanticTable::mustFilter)
-                    .collect(toImmutableBitSet()));
-    table.maybeUnwrap(SemanticTable.class)
-        .ifPresent(semanticTable ->
-            this.mustFilterBypassFields = semanticTable.bypassFieldList()
-                .stream().collect(toImmutableBitSet()));
-    table.maybeUnwrap(SemanticTable.class)
-        .ifPresent(semanticTable ->
-            this.remnantMustFilterFields = new 
HashSet<>(semanticTable.remnantMustFilterFields()));
-
+        .ifPresent(semanticTable -> {
+          ImmutableBitSet mustFilterFields = 
table.getRowType().getFieldList().stream()
+              .map(RelDataTypeField::getIndex)
+              .filter(semanticTable::mustFilter)
+              .collect(toImmutableBitSet());
+          ImmutableBitSet bypassFieldList = 
semanticTable.bypassFieldList().stream()
+              .collect(toImmutableBitSet());
+          // We pass in an empty set for remnantMustFilterFields here because 
it isn't exposed to

Review Comment:
   ```
   semanticTable.bypassFieldList().stream()
                 .collect(toImmutableBitSet())
   ```
   could be `semanticTable.bypassFieldList()` or 
`ImmutableBitSet.of(semanticTable.bypassFieldList())`



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