Skip to content

Commit e70ae28

Browse files
githubgxllguojn1
authored andcommitted
[fix][dingo-executor] Fix hash join filters out null values issue
1 parent 38caa4b commit e70ae28

File tree

2 files changed

+36
-5
lines changed

2 files changed

+36
-5
lines changed

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

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,17 @@ public boolean push(Context context, @Nullable Object[] tuple, Vertex vertex) {
6161
if (pin == 0) { // left
6262
waitRightFinFlag(param);
6363
TupleKey leftKey = HashJoinParam.rtrimTupleKey(new TupleKey(leftMapping.revMap(tuple)));
64+
65+
if (HashJoinParam.containsNull(leftKey)) {
66+
if ("inner".equalsIgnoreCase(param.getJoinType()) || "right".equalsIgnoreCase(param.getJoinType())) {
67+
return true;
68+
} else if ("left".equalsIgnoreCase(param.getJoinType()) || "full".equalsIgnoreCase(param.getJoinType())) {
69+
Object[] newTuple = Arrays.copyOf(tuple, leftLength + rightLength);
70+
Arrays.fill(newTuple, leftLength, leftLength + rightLength, null);
71+
return pushToNext(param, edge, context, newTuple);
72+
}
73+
}
74+
6475
boolean isEmpty = isEmpty(leftKey, param);
6576
if (isEmpty && ("inner".equalsIgnoreCase(param.getJoinType()) || "right".equalsIgnoreCase(param.getJoinType()))) {
6677
return true;
@@ -87,12 +98,23 @@ public boolean push(Context context, @Nullable Object[] tuple, Vertex vertex) {
8798
}
8899
} else if (pin == 1) { //right
89100
TupleKey rightKey = HashJoinParam.rtrimTupleKey(new TupleKey(rightMapping.revMap(tuple)));
90-
if (isEmpty(rightKey, param) && "inner".equalsIgnoreCase(param.getJoinType())) {
91-
return true;
101+
if (HashJoinParam.containsNull(rightKey)) {
102+
if ("inner".equalsIgnoreCase(param.getJoinType()) || "left".equalsIgnoreCase(param.getJoinType())) {
103+
return true;
104+
} else if ("right".equalsIgnoreCase(param.getJoinType()) || "full".equalsIgnoreCase(param.getJoinType())) {
105+
List<TupleWithJoinFlag> list = param.getHashMap()
106+
.computeIfAbsent(rightKey, k -> Collections.synchronizedList(new LinkedList<>()));
107+
list.add(new TupleWithJoinFlag(tuple));
108+
}
109+
} else {
110+
if (isEmpty(rightKey, param) && "inner".equalsIgnoreCase(param.getJoinType())) {
111+
return true;
112+
}
113+
List<TupleWithJoinFlag> list = param.getHashMap()
114+
.computeIfAbsent(rightKey, k -> Collections.synchronizedList(new LinkedList<>()));
115+
list.add(new TupleWithJoinFlag(tuple));
92116
}
93-
List<TupleWithJoinFlag> list = param.getHashMap()
94-
.computeIfAbsent(rightKey, k -> Collections.synchronizedList(new LinkedList<>()));
95-
list.add(new TupleWithJoinFlag(tuple));
117+
96118
}
97119
return true;
98120
} finally {

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,15 @@ public static Object[] rtrimTuple(Object[] tuple) {
144144
return arrayList.toArray();
145145
}
146146

147+
public static boolean containsNull(TupleKey key) {
148+
for (Object item : key.getTuple()) {
149+
if (item == null) {
150+
return true;
151+
}
152+
}
153+
return false;
154+
}
155+
147156
@Override
148157
public void init(Vertex vertex) {
149158
rightFinFlag = false;

0 commit comments

Comments
 (0)