You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by mo...@apache.org on 2021/08/07 13:33:40 UTC

[incubator-doris] branch master updated: [BUG] Fix query failure caused by using case-insensitive system view names in information_schema. (#6374)

This is an automated email from the ASF dual-hosted git repository.

morningman pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-doris.git


The following commit(s) were added to refs/heads/master by this push:
     new 36fe112  [BUG] Fix query failure caused by using case-insensitive system view names in information_schema. (#6374)
36fe112 is described below

commit 36fe112eb70c149e58edaf21acc333f57e91a578
Author: luozenglin <37...@users.noreply.github.com>
AuthorDate: Sat Aug 7 21:33:29 2021 +0800

    [BUG] Fix query failure caused by using case-insensitive system view names in information_schema. (#6374)
    
    The system view names in information_schema are case-insensitive,
    but we should not refer to one of these using different cases within the same statement.
    
    The following sql is correct:
    ```
    select * from information_schema.TAbles where TAbles.ENGINE = 'Doris';
    ```
    
    The following sql is wrong because `TAbles` and `tables` are used:
    ```
    select * from information_schema.TAbles order by tables.CREATE_TIME;
    ```
---
 .../main/java/org/apache/doris/analysis/Analyzer.java | 13 +++++++------
 .../java/org/apache/doris/analysis/BaseTableRef.java  |  2 +-
 .../org/apache/doris/analysis/SelectStmtTest.java     | 19 +++++++++++++++++++
 3 files changed, 27 insertions(+), 7 deletions(-)

diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/Analyzer.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/Analyzer.java
index 48b147a..2a30367 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/Analyzer.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/Analyzer.java
@@ -20,7 +20,6 @@ package org.apache.doris.analysis;
 import org.apache.doris.catalog.Catalog;
 import org.apache.doris.catalog.Column;
 import org.apache.doris.catalog.Database;
-import org.apache.doris.catalog.InfoSchemaDb;
 import org.apache.doris.catalog.OlapTable;
 import org.apache.doris.catalog.OlapTable.OlapTableState;
 import org.apache.doris.catalog.Table;
@@ -555,7 +554,13 @@ public class Analyzer {
             ErrorReport.reportAnalysisException(ErrorCode.ERR_BAD_TABLE_STATE, "RESTORING");
         }
 
-        TableName tblName = new TableName(database.getFullName(), table.getName());
+        // tableName.getTbl() stores the table name specified by the user in the from statement.
+        // In the case of case-sensitive table names, the value of tableName.getTbl() is the same as table.getName().
+        // However, since the system view is not case-sensitive, table.getName() gets the lowercase view name,
+        // which may not be the same as the user's reference to the table name, causing the table name not to be found
+        // in registerColumnRef(). So here the tblName is constructed using tableName.getTbl()
+        // instead of table.getName().
+        TableName tblName = new TableName(dbName, tableName.getTbl());
         if (table instanceof View) {
             return new InlineViewRef((View) table, tableRef);
         } else {
@@ -620,10 +625,6 @@ public class Analyzer {
         if (newTblName == null) {
             d = resolveColumnRef(colName);
         } else {
-            if (InfoSchemaDb.isInfoSchemaDb(newTblName.getDb())
-                    || (newTblName.getDb() == null && InfoSchemaDb.isInfoSchemaDb(getDefaultDb()))) {
-                newTblName = new TableName(newTblName.getDb(), newTblName.getTbl().toLowerCase());
-            }
             d = resolveColumnRef(newTblName, colName);
         }
         /*
diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/BaseTableRef.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/BaseTableRef.java
index 3eceea0..f46e60a 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/BaseTableRef.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/BaseTableRef.java
@@ -38,7 +38,7 @@ public class BaseTableRef extends TableRef {
         this.name = tableName;
         // Set implicit aliases if no explicit one was given.
         if (hasExplicitAlias()) return;
-        aliases_ = new String[] { name.toString(), tableName.getNoClusterString(), table.getName() };
+        aliases_ = new String[] { name.toString(), tableName.getNoClusterString(), tableName.getTbl() };
     }
 
     protected BaseTableRef(BaseTableRef other) {
diff --git a/fe/fe-core/src/test/java/org/apache/doris/analysis/SelectStmtTest.java b/fe/fe-core/src/test/java/org/apache/doris/analysis/SelectStmtTest.java
index ddc4771..07b8ae1 100755
--- a/fe/fe-core/src/test/java/org/apache/doris/analysis/SelectStmtTest.java
+++ b/fe/fe-core/src/test/java/org/apache/doris/analysis/SelectStmtTest.java
@@ -696,4 +696,23 @@ public class SelectStmtTest {
             Assert.fail(e.getMessage());
         }
     }
+
+    @Test
+    public void testSystemViewCaseInsensitive() throws Exception {
+        String sql1 = "SELECT ROUTINE_SCHEMA, ROUTINE_NAME FROM information_schema.ROUTINES WHERE ROUTINE_SCHEMA = " +
+                "'ech_dw' ORDER BY ROUTINES.ROUTINE_SCHEMA\n";
+        // The system view names in information_schema are case-insensitive,
+        dorisAssert.query(sql1).explainQuery();
+
+        String sql2 = "SELECT ROUTINE_SCHEMA, ROUTINE_NAME FROM information_schema.ROUTINES WHERE ROUTINE_SCHEMA = " +
+                "'ech_dw' ORDER BY routines.ROUTINE_SCHEMA\n";
+        try {
+            // Should not refer to one of system views using different cases within the same statement.
+            // sql2 is wrong because 'ROUTINES' and 'routines' are used.
+            dorisAssert.query(sql2).explainQuery();
+            Assert.fail("Refer to one of system views using different cases within the same statement is wrong.");
+        } catch (AnalysisException e) {
+            System.out.println(e.getMessage());
+        }
+    }
 }

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org