diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/SlotBinder.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/SlotBinder.java index 94c4b4f07dfdb64..dfa2528793e9e89 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/SlotBinder.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/SlotBinder.java @@ -17,6 +17,7 @@ package org.apache.doris.nereids.rules.analysis; +import org.apache.doris.cluster.ClusterNamespace; import org.apache.doris.common.util.Util; import org.apache.doris.nereids.CascadesContext; import org.apache.doris.nereids.analyzer.Scope; @@ -178,7 +179,7 @@ private BoundStar bindQualifiedStar(List qualifierStar, List bound case 1: // bound slot is `table`.`column` return false; case 2:// bound slot is `db`.`table`.`column` - return qualifierStar.get(0).equalsIgnoreCase(boundSlotQualifier.get(0)) + return compareDbNameIgnoreClusterName(qualifierStar.get(0), boundSlotQualifier.get(0)) && qualifierStar.get(1).equalsIgnoreCase(boundSlotQualifier.get(1)); default: throw new AnalysisException("Not supported qualifier: " @@ -193,6 +194,18 @@ private BoundStar bindQualifiedStar(List qualifierStar, List bound return new BoundStar(slots); } + private boolean compareDbNameIgnoreClusterName(String unBoundDbName, String boundedDbName) { + if (unBoundDbName.equalsIgnoreCase(boundedDbName)) { + return true; + } + // boundedDbName example + int idx = boundedDbName.indexOf(ClusterNamespace.CLUSTER_DELIMITER); + if (idx > -1) { + return unBoundDbName.equalsIgnoreCase(boundedDbName.substring(idx + 1)); + } + return false; + } + private List bindSlot(UnboundSlot unboundSlot, List boundSlots) { return boundSlots.stream().distinct().filter(boundSlot -> { List nameParts = unboundSlot.getNameParts(); @@ -205,14 +218,14 @@ private List bindSlot(UnboundSlot unboundSlot, List boundSlots) { return nameParts.get(0).equalsIgnoreCase(boundSlot.getName()); } if (namePartsSize == 2) { - String qualifierDbName = boundSlot.getQualifier().get(qualifierSize - 1); - return qualifierDbName.equalsIgnoreCase(nameParts.get(0)) + String qualifierTableName = boundSlot.getQualifier().get(qualifierSize - 1); + return qualifierTableName.equalsIgnoreCase(nameParts.get(0)) && boundSlot.getName().equalsIgnoreCase(nameParts.get(1)); } else if (nameParts.size() == 3) { - String qualifierDbName = boundSlot.getQualifier().get(qualifierSize - 1); - String qualifierClusterName = boundSlot.getQualifier().get(qualifierSize - 2); - return qualifierClusterName.equalsIgnoreCase(nameParts.get(0)) - && qualifierDbName.equalsIgnoreCase(nameParts.get(1)) + String qualifierTableName = boundSlot.getQualifier().get(qualifierSize - 1); + String qualifierDbName = boundSlot.getQualifier().get(qualifierSize - 2); + return compareDbNameIgnoreClusterName(nameParts.get(0), qualifierDbName) + && qualifierTableName.equalsIgnoreCase(nameParts.get(1)) && boundSlot.getName().equalsIgnoreCase(nameParts.get(2)); } //TODO: handle name parts more than three. diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/ExpressionTrait.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/ExpressionTrait.java index f76e242dbb62389..2d76c78f4cc06c0 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/ExpressionTrait.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/ExpressionTrait.java @@ -66,7 +66,7 @@ default DataType getArgumentType(int index) { } default DataType getDataType() throws UnboundException { - throw new UnboundException("dataType"); + throw new UnboundException(toSql() + ".getDataType()"); } default String toSql() throws UnboundException { 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 a63326c0fba481a..4b8835c1bb0c0db 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 @@ -508,14 +508,12 @@ public void testImplicitConvertSupport() throws Exception { @Test public void testDeleteSign() throws Exception { - String sql1 = "SELECT * FROM db1.table1 LEFT ANTI JOIN db1.table2 ON db1.table1.siteid = db1.table2.siteid;"; + String sql1 = "SELECT /*+ SET_VAR(enable_nereids_planner=true, ENABLE_FALLBACK_TO_ORIGINAL_PLANNER=false) */ * FROM db1.table1 LEFT ANTI JOIN db1.table2 ON db1.table1.siteid = db1.table2.siteid;"; String explain = dorisAssert.query(sql1).explainQuery(); Assert.assertTrue(explain - .contains("PREDICATES: `default_cluster:db1`.`table1`.`__DORIS_DELETE_SIGN__` = 0")); - Assert.assertTrue(explain - .contains("PREDICATES: `default_cluster:db1`.`table2`.`__DORIS_DELETE_SIGN__` = 0")); + .contains("PREDICATES: __DORIS_DELETE_SIGN__ = 0")); Assert.assertFalse(explain.contains("other predicates:")); - String sql2 = "SELECT * FROM db1.table1 JOIN db1.table2 ON db1.table1.siteid = db1.table2.siteid;"; + String sql2 = "SELECT /*+ SET_VAR(enable_nereids_planner=false) */ * FROM db1.table1 JOIN db1.table2 ON db1.table1.siteid = db1.table2.siteid;"; explain = dorisAssert.query(sql2).explainQuery(); Assert.assertTrue(explain .contains("PREDICATES: `default_cluster:db1`.`table1`.`__DORIS_DELETE_SIGN__` = 0"));