Jackie-Jiang commented on code in PR #15692:
URL: https://github.com/apache/pinot/pull/15692#discussion_r2076531611


##########
pinot-query-planner/src/main/java/org/apache/pinot/query/QueryEnvironment.java:
##########
@@ -116,6 +117,13 @@
 @Value.Enclosing
 public class QueryEnvironment {
   private static final Logger LOGGER = 
LoggerFactory.getLogger(QueryEnvironment.class);
+  private static final CalciteConnectionConfig CONNECTION_CONFIG;
+
+  static {
+    Properties connectionConfigProperties = new Properties();
+    
connectionConfigProperties.setProperty(CalciteConnectionProperty.CASE_SENSITIVE.camelName(),
 "true");

Review Comment:
   Some comments might help explaining it why we keep it case sensitive here



##########
pinot-common/src/main/java/org/apache/pinot/common/catalog/PinotNameMatcher.java:
##########
@@ -0,0 +1,121 @@
+/**
+ * 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.pinot.common.catalog;
+
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeSet;
+import javax.annotation.Nullable;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rel.type.RelDataTypeField;
+import org.apache.calcite.sql.validate.SqlNameMatcher;
+import org.apache.pinot.common.utils.list.FlatViewList;
+
+
+/**
+ * A custom name matcher that, although matches names based on config-provided 
case-sensitiveness, always reports to be
+ * case-sensitive so Calcite does not transform identifiers to lower case.
+ */
+public class PinotNameMatcher implements SqlNameMatcher {
+
+  private final boolean _caseSensitive;
+
+  public PinotNameMatcher(boolean caseSensitive) {
+    _caseSensitive = caseSensitive;
+  }
+
+  @Override
+  public boolean isCaseSensitive() {
+    return true;
+  }
+
+  @Override
+  public boolean matches(String string, String name) {
+    return _caseSensitive ? string.equals(name) : 
string.equalsIgnoreCase(name);
+  }
+
+  @Nullable
+  @Override
+  public <K extends List<String>, V> V get(Map<K, V> map, List<String> 
prefixNames, List<String> names) {
+    if (_caseSensitive) {
+      List<String> key = concat(prefixNames, names);
+      return map.get(key);
+    } else {
+      for (Map.Entry<K, V> entry : map.entrySet()) {
+        if (listMatches(prefixNames, names, entry.getKey())) {
+          return entry.getValue();
+        }
+      }
+
+      return null;
+    }
+  }
+
+  @Override
+  public String bestString() {
+    throw new UnsupportedOperationException();
+  }
+
+  @Override
+  public @Nullable RelDataTypeField field(RelDataType rowType, String 
fieldName) {

Review Comment:
   (minor) Move `@Nullable` above `@Override`



##########
pinot-query-planner/src/main/java/org/apache/pinot/query/QueryEnvironment.java:
##########
@@ -116,6 +117,13 @@
 @Value.Enclosing
 public class QueryEnvironment {
   private static final Logger LOGGER = 
LoggerFactory.getLogger(QueryEnvironment.class);

Review Comment:
   (nit) Unused



##########
pinot-common/src/main/java/org/apache/pinot/common/catalog/PinotNameMatcher.java:
##########
@@ -0,0 +1,121 @@
+/**
+ * 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.pinot.common.catalog;
+
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeSet;
+import javax.annotation.Nullable;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rel.type.RelDataTypeField;
+import org.apache.calcite.sql.validate.SqlNameMatcher;
+import org.apache.pinot.common.utils.list.FlatViewList;
+
+
+/**
+ * A custom name matcher that, although matches names based on config-provided 
case-sensitiveness, always reports to be
+ * case-sensitive so Calcite does not transform identifiers to lower case.
+ */

Review Comment:
   Seems this is the same as `SqlNameMatchers.BaseMatcher` with the only 
difference in `isCaseSensitive()`. Let's put this as javadoc for future 
reference



##########
pinot-common/src/main/java/org/apache/pinot/common/catalog/PinotCatalogReader.java:
##########
@@ -0,0 +1,35 @@
+/**
+ * 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.pinot.common.catalog;
+
+import com.google.common.collect.ImmutableList;
+import java.util.List;
+import org.apache.calcite.config.CalciteConnectionConfig;
+import org.apache.calcite.jdbc.CalciteSchema;
+import org.apache.calcite.prepare.CalciteCatalogReader;
+import org.apache.calcite.rel.type.RelDataTypeFactory;
+
+
+public class PinotCatalogReader extends CalciteCatalogReader {

Review Comment:
   Smart!
   Let's add some javadoc here explaining why we need this class



##########
pinot-query-planner/src/main/java/org/apache/pinot/query/catalog/PinotCatalog.java:
##########
@@ -68,10 +67,15 @@ public Table getTable(String name) {
     String rawTableName = TableNameBuilder.extractRawTableName(name);
     String physicalTableName = DatabaseUtils.translateTableName(rawTableName, 
_databaseName);
     String tableName = _tableCache.getActualTableName(physicalTableName);
+    if (tableName == null) {
+      return null;

Review Comment:
   (minor) Annotate method as `@Nullable`



##########
pinot-common/src/main/java/org/apache/pinot/common/catalog/PinotNameMatcher.java:
##########
@@ -0,0 +1,121 @@
+/**
+ * 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.pinot.common.catalog;
+
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeSet;
+import javax.annotation.Nullable;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rel.type.RelDataTypeField;
+import org.apache.calcite.sql.validate.SqlNameMatcher;
+import org.apache.pinot.common.utils.list.FlatViewList;
+
+
+/**
+ * A custom name matcher that, although matches names based on config-provided 
case-sensitiveness, always reports to be
+ * case-sensitive so Calcite does not transform identifiers to lower case.
+ */
+public class PinotNameMatcher implements SqlNameMatcher {
+
+  private final boolean _caseSensitive;
+
+  public PinotNameMatcher(boolean caseSensitive) {
+    _caseSensitive = caseSensitive;
+  }
+
+  @Override
+  public boolean isCaseSensitive() {
+    return true;
+  }
+
+  @Override
+  public boolean matches(String string, String name) {
+    return _caseSensitive ? string.equals(name) : 
string.equalsIgnoreCase(name);
+  }
+
+  @Nullable
+  @Override
+  public <K extends List<String>, V> V get(Map<K, V> map, List<String> 
prefixNames, List<String> names) {
+    if (_caseSensitive) {
+      List<String> key = concat(prefixNames, names);
+      return map.get(key);
+    } else {
+      for (Map.Entry<K, V> entry : map.entrySet()) {
+        if (listMatches(prefixNames, names, entry.getKey())) {
+          return entry.getValue();
+        }
+      }
+
+      return null;
+    }
+  }
+
+  @Override
+  public String bestString() {
+    throw new UnsupportedOperationException();
+  }
+
+  @Override
+  public @Nullable RelDataTypeField field(RelDataType rowType, String 
fieldName) {
+    return rowType.getField(fieldName, _caseSensitive, false);
+  }
+
+  @Override
+  public int frequency(Iterable<String> names, String name) {
+    int n = 0;
+
+    for (String s : names) {
+      if (this.matches(s, name)) {
+        ++n;
+      }
+    }
+
+    return n;
+  }
+
+  @Override
+  public Set<String> createSet() {
+    return (this.isCaseSensitive() ? new LinkedHashSet<>() : new 
TreeSet<>(String.CASE_INSENSITIVE_ORDER));
+  }
+
+  private static List<String> concat(List<String> prefixNames, List<String> 
names) {
+    return new FlatViewList<>(prefixNames, names);

Review Comment:
   Is this borrowed from Calcite code, or customized? If it is customized, 
please add some javadoc for readability



##########
pinot-server/src/main/java/org/apache/pinot/server/starter/helix/HelixInstanceDataManager.java:
##########
@@ -80,7 +81,7 @@
 public class HelixInstanceDataManager implements InstanceDataManager {
   private static final Logger LOGGER = 
LoggerFactory.getLogger(HelixInstanceDataManager.class);
 
-  private final ConcurrentHashMap<String, TableDataManager> 
_tableDataManagerMap = new ConcurrentHashMap<>();
+  private final Map<String, TableDataManager> _tableDataManagerMap = new 
ConcurrentHashMap<>();

Review Comment:
   (nit) Seems unrelated



##########
pinot-query-planner/src/main/java/org/apache/pinot/query/planner/physical/PinotDispatchPlanner.java:
##########
@@ -75,6 +76,19 @@ public DispatchableSubPlan createDispatchableSubPlan(SubPlan 
subPlan) {
     return finalizeDispatchableSubPlan(rootFragment, context);
   }
 
+  private Set<String> resolveActualTableNames(Set<String> tableNames) {

Review Comment:
   Do we need to resolve table names here given the table name is already 
resolved in the scan node?



-- 
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: commits-unsubscr...@pinot.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org
For additional commands, e-mail: commits-h...@pinot.apache.org

Reply via email to