Skip to content

Commit b75c004

Browse files
guojn1githubgxll
authored andcommitted
[fix][dingo-exec] Resolve the issue of null values in join connection columns
1 parent 2a1343a commit b75c004

File tree

4 files changed

+49
-11
lines changed

4 files changed

+49
-11
lines changed

dingo-calcite/src/main/java/io/dingodb/calcite/visitor/function/DingoHashJoinVisitFun.java

+1
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ public static List<Vertex> visit(
112112
rel.getJoinType() == JoinRelType.LEFT || rel.getJoinType() == JoinRelType.FULL,
113113
rel.getJoinType() == JoinRelType.RIGHT || rel.getJoinType() == JoinRelType.FULL
114114
);
115+
param.setJoinType(rel.getJoinType().lowerName);
115116
param.setOtherExpr(otherCondition);
116117
Vertex vertex = new Vertex(HASH_JOIN, param);
117118
vertex.setId(idGenerator.getOperatorId(taskId));

dingo-exec/src/main/java/io/dingodb/exec/operator/HashJoinOperator.java

+27
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,15 @@ public boolean push(Context context, @Nullable Object[] tuple, Vertex vertex) {
6060
if (pin == 0) { // left
6161
waitRightFinFlag(param);
6262
TupleKey leftKey = new TupleKey(leftMapping.revMap(tuple));
63+
boolean isEmpty = isEmpty(leftKey, param);
64+
if (isEmpty && ("inner".equalsIgnoreCase(param.getJoinType()) || "right".equalsIgnoreCase(param.getJoinType()))) {
65+
return true;
66+
}
67+
if (isEmpty && "left".equalsIgnoreCase(param.getJoinType())) {
68+
Object[] newTuple = Arrays.copyOf(tuple, leftLength + rightLength);
69+
Arrays.fill(newTuple, leftLength, leftLength + rightLength, null);
70+
return pushToNext(param, edge, context, newTuple);
71+
}
6372
List<TupleWithJoinFlag> rightList = param.getHashMap().get(leftKey);
6473
if (rightList != null) {
6574
for (TupleWithJoinFlag t : rightList) {
@@ -77,6 +86,9 @@ public boolean push(Context context, @Nullable Object[] tuple, Vertex vertex) {
7786
}
7887
} else if (pin == 1) { //right
7988
TupleKey rightKey = new TupleKey(rightMapping.revMap(tuple));
89+
if (isEmpty(rightKey, param) && "inner".equalsIgnoreCase(param.getJoinType())) {
90+
return true;
91+
}
8092
List<TupleWithJoinFlag> list = param.getHashMap()
8193
.computeIfAbsent(rightKey, k -> Collections.synchronizedList(new LinkedList<>()));
8294
list.add(new TupleWithJoinFlag(tuple));
@@ -163,4 +175,19 @@ private static boolean pushToNext(HashJoinParam param, Edge edge, Context contex
163175
return edge.transformToNext(context, tuple);
164176
}
165177
}
178+
179+
public static boolean isEmpty(TupleKey tupleKey, HashJoinParam param) {
180+
if (param.rightMappingEmpty && param.leftMappingEmpty) {
181+
return false;
182+
}
183+
Object[] tuple = tupleKey.getTuple();
184+
if (tuple != null) {
185+
for (Object item : tuple) {
186+
if (item != null) {
187+
return false;
188+
}
189+
}
190+
}
191+
return true;
192+
}
166193
}

dingo-exec/src/main/java/io/dingodb/exec/operator/params/HashJoinParam.java

+8-3
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,20 @@ public class HashJoinParam extends AbstractParams {
5757
@Setter
5858
private transient CompletableFuture<Void> future;
5959

60-
@Getter
6160
@Setter
6261
public Profile profileLeft;
63-
@Getter
6462
@Setter
6563
public Profile profileRight;
6664

67-
@Getter
6865
@Setter
6966
public SqlExpr otherExpr;
7067

68+
@Setter
69+
public String joinType;
70+
71+
public boolean leftMappingEmpty;
72+
public boolean rightMappingEmpty;
73+
7174

7275
public HashJoinParam(
7376
TupleMapping leftMapping,
@@ -83,6 +86,8 @@ public HashJoinParam(
8386
this.rightLength = rightLength;
8487
this.leftRequired = leftRequired;
8588
this.rightRequired = rightRequired;
89+
this.leftMappingEmpty = this.leftMapping.size() == 0;
90+
this.rightMappingEmpty = this.rightMapping.size() == 0;
8691
}
8792

8893
@Override

dingo-executor/src/main/java/io/dingodb/server/executor/prepare/PrepareMeta.java

+13-8
Original file line numberDiff line numberDiff line change
@@ -629,14 +629,19 @@ public static void initTableByTemplate(String schema,
629629
}
630630

631631
public static void synchronizeTenant() {
632-
List<Object> tenantObjList = io.dingodb.meta.InfoSchemaService.root().listTenant();
633-
tenantObjList.forEach(object -> {
634-
Tenant tenant = (Tenant) object;
635-
if (!MetaService.ROOT.existsTenant(tenant.getId())) {
636-
MetaService.ROOT.createTenant(tenant);
637-
LogUtils.info(log, "synchronize tenant id to coordinator:{}", tenant.getId());
638-
}
639-
});
632+
try {
633+
List<Object> tenantObjList = io.dingodb.meta.InfoSchemaService.root().listTenant();
634+
tenantObjList.forEach(object -> {
635+
Tenant tenant = (Tenant) object;
636+
if (!MetaService.ROOT.existsTenant(tenant.getId())) {
637+
MetaService.ROOT.createTenant(tenant);
638+
LogUtils.info(log, "synchronize tenant id to coordinator:{}", tenant.getId());
639+
}
640+
});
641+
LogUtils.info(log, "synchronizeTenant done");
642+
} catch (Exception e) {
643+
LogUtils.error(log, e.getMessage(), e);
644+
}
640645
}
641646

642647
private static boolean continueRetry() {

0 commit comments

Comments
 (0)