gortiz commented on code in PR #15692:
URL: https://github.com/apache/pinot/pull/15692#discussion_r2072928903


##########
pinot-common/src/main/java/org/apache/pinot/common/catalog/PinotNameMatcher.java:
##########
@@ -0,0 +1,119 @@
+/**
+ * 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.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeSet;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rel.type.RelDataTypeField;
+import org.apache.calcite.sql.validate.SqlNameMatcher;
+import org.checkerframework.checker.nullness.qual.Nullable;
+
+
+/**
+ * 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);
+  }
+
+  @Override
+  public <K extends List<String>, V> @Nullable V get(Map<K, V> map, 
List<String> prefixNames, List<String> names) {
+    List<String> key = concat(prefixNames, names);
+    if (_caseSensitive) {
+      return map.get(key);
+    } else {
+      for (Map.Entry<K, V> entry : map.entrySet()) {
+        if (this.listMatches(key, 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 (List<String>) (prefixNames.isEmpty() ? names : 
ImmutableList.builder()
+        .addAll(prefixNames).addAll(names).build());

Review Comment:
   This concat function is very expensive if prefixNames is not empty. Couldn't 
we use a custom class here that concatenates these lists as a view? Even 
better, given we need to iterate over the map elements in the case insensitive 
case, we could do that directly over the two lists (prefixes and names) so we 
we can implement that without any allocation



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