DonnyZone commented on a change in pull request #1792: [CALCITE-3775] Implicit 
lookup methods in SimpleCalciteSchema ignore case sensitivity parameter
URL: https://github.com/apache/calcite/pull/1792#discussion_r381769788
 
 

 ##########
 File path: core/src/main/java/org/apache/calcite/jdbc/SimpleCalciteSchema.java
 ##########
 @@ -67,33 +69,72 @@ public CalciteSchema add(String name, Schema schema) {
     return calciteSchema;
   }
 
+  private String caseInsensitiveLookup(Set<String> candidates, String name) {
+    // Exact string lookup
+    if (candidates.contains(name)) {
+      return name;
+    }
+    // Upper case string lookup
+    final String upperCaseName = name.toUpperCase(Locale.ROOT);
+    if (candidates.contains(upperCaseName)) {
+      return upperCaseName;
+    }
+    // Lower case string lookup
+    final String lowerCaseName = name.toLowerCase(Locale.ROOT);
+    if (candidates.contains(lowerCaseName)) {
+      return lowerCaseName;
+    }
+    // Fall through: Set iteration
+    for (String candidate: candidates) {
+      if (candidate.equalsIgnoreCase(name)) {
+        return candidate;
+      }
+    }
+    return null;
+  }
+
   protected CalciteSchema getImplicitSubSchema(String schemaName,
       boolean caseSensitive) {
     // Check implicit schemas.
-    Schema s = schema.getSubSchema(schemaName);
-    if (s != null) {
-      return new SimpleCalciteSchema(this, s, schemaName);
+    final String schemaName2 = caseSensitive ? schemaName : 
caseInsensitiveLookup(
+        schema.getSubSchemaNames(), schemaName);
+    if (schemaName2 == null) {
+      return null;
     }
-    return null;
+    final Schema s = schema.getSubSchema(schemaName2);
+    if (s == null) {
+      return null;
+    }
+    return new SimpleCalciteSchema(this, s, schemaName2);
   }
 
   protected TableEntry getImplicitTable(String tableName,
       boolean caseSensitive) {
     // Check implicit tables.
-    Table table = schema.getTable(tableName);
-    if (table != null) {
-      return tableEntry(tableName, table);
+    final String tableName2 = caseSensitive ? tableName : 
caseInsensitiveLookup(
+        schema.getTableNames(), tableName);
+    if (tableName2 == null) {
 
 Review comment:
   >  can we just keep it as it is now and do not support the case-sensitivity 
look-up
   
    Case-insensitive? Current SimpleCalciteSchema supports only case-sensitive 
lookup.
   
   >  keep the SimpleCalciteSchema as simple as possible
   
    Do you mean the simple code style? In logic, this PR adds a branch for 
case-insensitive, bringing no burden to case-sensitive branch.
    
   In our production environment, we use the default `CachingCalciteSchema`. 
Therefore, I do not have strong requirement for this feature. The only worry is 
that users may get incorrect result when using `SimpleCalciteSchema` for 
case-insensitive lookup.
   Since this Jira issue is filed by @zabetak, how about your opinion?

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to