Skip to content

Commit

Permalink
default-cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
englefly committed Aug 15, 2023
1 parent e2b06cd commit 8e8d88f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -178,7 +179,7 @@ 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 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: "
Expand All @@ -193,6 +194,18 @@ private BoundStar bindQualifiedStar(List<String> qualifierStar, List<Slot> 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<Slot> bindSlot(UnboundSlot unboundSlot, List<Slot> boundSlots) {
return boundSlots.stream().distinct().filter(boundSlot -> {
List<String> nameParts = unboundSlot.getNameParts();
Expand All @@ -205,14 +218,14 @@ private List<Slot> bindSlot(UnboundSlot unboundSlot, List<Slot> 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down

0 comments on commit 8e8d88f

Please sign in to comment.