morrySnow commented on code in PR #61918:
URL: https://github.com/apache/doris/pull/61918#discussion_r3031238201


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/AddConstraintCommand.java:
##########
@@ -68,13 +70,25 @@ public AddConstraintCommand(String name, Constraint 
constraint) {
     public void run(ConnectContext ctx, StmtExecutor executor) throws 
Exception {
         Pair<ImmutableList<String>, TableIf> columnsAndTable = 
extractColumnsAndTable(ctx, constraint.toProject());
         TableIf table = columnsAndTable.second;
-        TableNameInfo tableNameInfo = new TableNameInfo(table);
+        String tableNameStr = table.getName();
+        if (GlobalVariable.isStoredTableNamesLowerCase()) {
+            tableNameStr = tableNameStr.toLowerCase();
+        }

Review Comment:
   move this logic into TableNameInfoUtils.fromCatalogDb



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/ForeignKeyContext.java:
##########
@@ -115,10 +127,19 @@ void putAllForeignKeys(TableIf table) {
     }
 
     void putAllPrimaryKeys(TableIf table) {
-        TableNameInfo tableNameInfo = TableNameInfo.createOrNull(table);
-        if (tableNameInfo == null) {
+        if (table == null || table.getName() == null || 
table.getName().isEmpty()) {
+            return;
+        }
+        DatabaseIf<?> db = table.getDatabase();
+        if (db == null) {
+            return;
+        }
+        CatalogIf<?> catalog = db.getCatalog();
+        if (catalog == null) {
             return;
         }
+        String tableName = table.getName();

Review Comment:
   move this logic into TableNameInfoUtils.fromCatalogDb



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/DropConstraintCommand.java:
##########
@@ -62,7 +64,12 @@ public void run(ConnectContext ctx, StmtExecutor executor) 
throws Exception {
         TableNameInfo tableNameInfo;
         try {
             TableIf table = extractTable(ctx, plan);
-            tableNameInfo = new TableNameInfo(table);
+            String tblName = table.getName();
+            if (GlobalVariable.isStoredTableNamesLowerCase()) {
+                tblName = tblName.toLowerCase();
+            }

Review Comment:
   move this logic into TableNameInfoUtils.fromCatalogDb



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/AddConstraintCommand.java:
##########
@@ -68,13 +70,25 @@ public AddConstraintCommand(String name, Constraint 
constraint) {
     public void run(ConnectContext ctx, StmtExecutor executor) throws 
Exception {
         Pair<ImmutableList<String>, TableIf> columnsAndTable = 
extractColumnsAndTable(ctx, constraint.toProject());
         TableIf table = columnsAndTable.second;
-        TableNameInfo tableNameInfo = new TableNameInfo(table);
+        String tableNameStr = table.getName();
+        if (GlobalVariable.isStoredTableNamesLowerCase()) {
+            tableNameStr = tableNameStr.toLowerCase();
+        }
+        TableNameInfo tableNameInfo = TableNameInfoUtils.fromCatalogDb(
+                table.getDatabase().getCatalog(), table.getDatabase(), 
tableNameStr);
         ImmutableList<String> columns = columnsAndTable.first;
 
         if (constraint.isForeignKey()) {
             Pair<ImmutableList<String>, TableIf> refColumnsAndTable
                     = extractColumnsAndTable(ctx, 
constraint.toReferenceProject());
-            TableNameInfo refTableInfo = new 
TableNameInfo(refColumnsAndTable.second);
+            TableIf refTable = refColumnsAndTable.second;
+            String refTableNameStr = refTable.getName();
+            if (GlobalVariable.isStoredTableNamesLowerCase()) {
+                refTableNameStr = refTableNameStr.toLowerCase();
+            }

Review Comment:
   move this logic into TableNameInfoUtils.fromCatalogDb



##########
fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java:
##########
@@ -1037,8 +1039,13 @@ public boolean unprotectDropTable(Database db, Table 
table, boolean isForceDrop,
         
Env.getCurrentEnv().getAnalysisManager().removeTableStats(table.getId());
         
Env.getCurrentEnv().getDictionaryManager().dropTableDictionaries(db.getName(), 
table.getName());
         
Env.getCurrentEnv().getQueryStats().clear(Env.getCurrentInternalCatalog().getId(),
 db.getId(), table.getId());
+        String tableNameStr = table.getName();
+        if (GlobalVariable.isStoredTableNamesLowerCase()) {
+            tableNameStr = tableNameStr.toLowerCase();
+        }

Review Comment:
   move this code block into TableNameInfoUtils.fromDb



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/physical/PhysicalCatalogRelation.java:
##########
@@ -211,10 +213,22 @@ public String shapeInfo() {
     @Override
     public void computeUnique(DataTrait.Builder builder) {
         Set<Slot> outputSet = Utils.fastToImmutableSet(getOutputSet());
-        TableNameInfo tableNameInfo = TableNameInfo.createOrNull(table);
-        if (tableNameInfo == null) {
+        if (table == null || table.getName() == null || 
table.getName().isEmpty()) {
             return;
         }
+        DatabaseIf<?> db = table.getDatabase();
+        if (db == null) {
+            return;
+        }
+        CatalogIf<?> catalog = db.getCatalog();
+        if (catalog == null) {
+            return;
+        }
+        String tableName = table.getName();
+        if (GlobalVariable.isStoredTableNamesLowerCase()) {
+            tableName = tableName.toLowerCase();
+        }

Review Comment:
   move this logic into TableNameInfoUtils.fromCatalogDb



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalCatalogRelation.java:
##########
@@ -196,10 +198,22 @@ public String getTableAlias() {
     @Override
     public void computeUnique(DataTrait.Builder builder) {
         Set<Slot> outputSet = Utils.fastToImmutableSet(getOutputSet());
-        TableNameInfo tableNameInfo = TableNameInfo.createOrNull(table);
-        if (tableNameInfo == null) {
+        if (table == null || table.getName() == null || 
table.getName().isEmpty()) {
             return;
         }
+        DatabaseIf<?> db = table.getDatabase();
+        if (db == null) {
+            return;
+        }
+        CatalogIf<?> catalog = db.getCatalog();
+        if (catalog == null) {
+            return;
+        }
+        String tableName = table.getName();
+        if (GlobalVariable.isStoredTableNamesLowerCase()) {
+            tableName = tableName.toLowerCase();
+        }

Review Comment:
   move this logic into TableNameInfoUtils.fromCatalogDb



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/ForeignKeyContext.java:
##########
@@ -102,10 +105,19 @@ public Void visitLogicalFilter(LogicalFilter<?> filter, 
ForeignKeyContext contex
     }
 
     void putAllForeignKeys(TableIf table) {
-        TableNameInfo tableNameInfo = TableNameInfo.createOrNull(table);
-        if (tableNameInfo == null) {
+        if (table == null || table.getName() == null || 
table.getName().isEmpty()) {
             return;
         }
+        DatabaseIf<?> db = table.getDatabase();
+        if (db == null) {
+            return;
+        }
+        CatalogIf<?> catalog = db.getCatalog();
+        if (catalog == null) {
+            return;
+        }
+        String tableName = table.getName();

Review Comment:
   move this logic into TableNameInfoUtils.fromCatalogDb



##########
fe/fe-core/src/main/java/org/apache/doris/info/TableNameInfoUtils.java:
##########
@@ -0,0 +1,69 @@
+// 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.doris.info;
+
+import org.apache.doris.catalog.Database;
+import org.apache.doris.catalog.DatabaseIf;
+import org.apache.doris.catalog.NameSpaceContext;
+import org.apache.doris.catalog.TableIf;
+import org.apache.doris.datasource.CatalogIf;
+
+/**
+ * Utility methods for creating {@link TableNameInfo} from catalog objects.
+ * Kept separate from {@code TableNameInfo} to avoid coupling that class to
+ * {@code Database}/{@code TableIf}/{@code CatalogIf}.
+ */
+public class TableNameInfoUtils {

Review Comment:
   add unit test for this class



##########
fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVService.java:
##########
@@ -214,12 +218,29 @@ public void processEvent(Event event) throws 
EventException {
     private boolean shouldRefreshOnBaseTableDataChange(MTMV mtmv, TableIf 
table) {
         TableNameInfo tableName = null;
         try {
-            tableName = new TableNameInfo(table);
-        } catch (org.apache.doris.nereids.exceptions.AnalysisException e) {
+            if (table != null && !table.getName().isEmpty()) {
+                DatabaseIf<?> db = table.getDatabase();
+                if (db != null) {
+                    CatalogIf<?> catalog = db.getCatalog();
+                    if (catalog != null) {
+                        String tblName = table.getName();
+                        if (GlobalVariable.isStoredTableNamesLowerCase()) {
+                            tblName = tblName.toLowerCase();
+                        }

Review Comment:
   move this logic into TableNameInfoUtils.fromCatalogDb



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to