Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -673,10 +673,10 @@ private BoundStar bindQualifiedStar(List<String> qualifierStar, List<Slot> bound
case 1: // bound slot is `table`.`column`
return false;
case 2:// bound slot is `db`.`table`.`column`
return compareDbName(qualifierStar.get(0), boundSlotQualifier.get(0))
return compareDbNameIgnoreClusterName(qualifierStar.get(0), boundSlotQualifier.get(0))
&& qualifierStar.get(1).equalsIgnoreCase(boundSlotQualifier.get(1));
case 3:// bound slot is `catalog`.`db`.`table`.`column`
return compareDbName(qualifierStar.get(0), boundSlotQualifier.get(1))
return compareDbNameIgnoreClusterName(qualifierStar.get(0), boundSlotQualifier.get(1))
&& qualifierStar.get(1).equalsIgnoreCase(boundSlotQualifier.get(2));
default:
throw new AnalysisException("Not supported qualifier: "
Expand All @@ -692,7 +692,7 @@ private BoundStar bindQualifiedStar(List<String> qualifierStar, List<Slot> bound
return false;
case 3:// bound slot is `catalog`.`db`.`table`.`column`
return qualifierStar.get(0).equalsIgnoreCase(boundSlotQualifier.get(0))
&& compareDbName(qualifierStar.get(1), boundSlotQualifier.get(1))
&& compareDbNameIgnoreClusterName(qualifierStar.get(1), boundSlotQualifier.get(1))
&& qualifierStar.get(2).equalsIgnoreCase(boundSlotQualifier.get(2));
default:
throw new AnalysisException("Not supported qualifier: "
Expand Down Expand Up @@ -860,7 +860,7 @@ private List<Slot> bindSingleSlotByDb(String db, String table, String name, Scop
List<String> boundSlotQualifier = boundSlot.getQualifier();
String boundSlotDb = boundSlotQualifier.get(boundSlotQualifier.size() - 2);
String boundSlotTable = boundSlotQualifier.get(boundSlotQualifier.size() - 1);
if (!compareDbName(boundSlotDb, db) || !sameTableName(boundSlotTable, table)) {
if (!compareDbNameIgnoreClusterName(boundSlotDb, db) || !sameTableName(boundSlotTable, table)) {
continue;
}
// set sql case as alias
Expand All @@ -881,7 +881,7 @@ private List<Slot> bindSingleSlotByCatalog(String catalog, String db, String tab
String boundSlotDb = boundSlotQualifier.get(boundSlotQualifier.size() - 2);
String boundSlotTable = boundSlotQualifier.get(boundSlotQualifier.size() - 1);
if (!boundSlotCatalog.equalsIgnoreCase(catalog)
|| !compareDbName(boundSlotDb, db)
|| !compareDbNameIgnoreClusterName(boundSlotDb, db)
|| !sameTableName(boundSlotTable, table)) {
continue;
}
Expand All @@ -890,4 +890,22 @@ private List<Slot> bindSingleSlotByCatalog(String catalog, String db, String tab
}
return usedSlots.build();
}

/**compareDbNameIgnoreClusterName.*/
public static boolean compareDbNameIgnoreClusterName(String name1, String name2) {
if (name1.equalsIgnoreCase(name2)) {
return true;
}
String ignoreClusterName1 = name1;
int idx1 = name1.indexOf(":");
if (idx1 > -1) {
ignoreClusterName1 = name1.substring(idx1 + 1);
}
String ignoreClusterName2 = name2;
int idx2 = name2.indexOf(":");
if (idx2 > -1) {
ignoreClusterName2 = name2.substring(idx2 + 1);
}
return ignoreClusterName1.equalsIgnoreCase(ignoreClusterName2);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,8 @@ private void checkAssignmentColumn(ConnectContext ctx, List<String> columnNamePa
}
List<String> tableQualifier = RelationUtil.getQualifierName(ctx, nameParts);
if (!ExpressionAnalyzer.sameTableName(tableAlias == null ? tableQualifier.get(2) : tableAlias, tableName)
|| (dbName != null && ExpressionAnalyzer.compareDbName(tableQualifier.get(1), dbName))) {
|| (dbName != null
&& !ExpressionAnalyzer.compareDbNameIgnoreClusterName(tableQualifier.get(1), dbName))) {
throw new AnalysisException("column in assignment list is invalid, " + String.join(".", columnNameParts));
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- This file is automatically generated. You should know what you did if you want to edit this
-- !test_update --
2 10

Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// 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.
suite("test_db_name_ignore_cluster") {
String db = context.config.getDbNameByFile(new File(context.file.parent))
sql 'set enable_nereids_planner=true'
sql 'set enable_nereids_distribute_planner=false'
sql "use ${db}"
sql "drop table if exists ${db}.test_db_name_ignore_cluster"
sql """create table ${db}.test_db_name_ignore_cluster(a int, b int) unique key(a) distributed by hash(a)
properties("replication_num"="1");"""
sql "select ${db}.test_db_name_ignore_cluster.a from `default_cluster:${db}`.test_db_name_ignore_cluster;"
sql "select ${db}.test_db_name_ignore_cluster.* from `default_cluster:${db}`.test_db_name_ignore_cluster;"

sql "select `default_cluster:${db}`.test_db_name_ignore_cluster.a from `${db}`.test_db_name_ignore_cluster;"
sql "select `default_cluster:${db}`.test_db_name_ignore_cluster.* from `${db}`.test_db_name_ignore_cluster;"

sql "select `default_cluster:${db}`.test_db_name_ignore_cluster.a from `default_cluster:${db}`.test_db_name_ignore_cluster;"
sql "select `default_cluster:${db}`.test_db_name_ignore_cluster.* from `default_cluster:${db}`.test_db_name_ignore_cluster;"

sql "select internal.`${db}`.test_db_name_ignore_cluster.a from internal.`default_cluster:${db}`.test_db_name_ignore_cluster;"
sql "select internal.`default_cluster:${db}`.test_db_name_ignore_cluster.* from internal.`${db}`.test_db_name_ignore_cluster;"

sql "insert into ${db}.test_db_name_ignore_cluster values(2,4)"
sql "update `default_cluster:${db}`.test_db_name_ignore_cluster set `${db}`.test_db_name_ignore_cluster.b=10;"
sql "update `${db}`.test_db_name_ignore_cluster set `${db}`.test_db_name_ignore_cluster.b=10;"
qt_test_update "select * from ${db}.test_db_name_ignore_cluster"
}