Skip to content
Merged
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 @@ -124,7 +124,8 @@ public static void recursiveMerge(
mergeFilter,
topLevel,
1,
updateKeyDiffInfos
updateKeyDiffInfos,
extractMainTableKeys(mergeBundle, topLevel)
);
}

Expand All @@ -142,6 +143,39 @@ public static void recursiveMerge(
int topLevel,
int loopTime,
List<MapDiffUtil.KeyDiffInfo> updateKeyDiffInfos
) {
recursiveMerge(mergeBundle, properties, mergeResults, mergeLookupResults, mergeResult, unsetResult,
updateJoinKeys, sharedJoinKeys, parentProperties, mergeFilter, topLevel, loopTime,
updateKeyDiffInfos, extractMainTableKeys(mergeBundle, topLevel));
}

private static Set<String> extractMainTableKeys(MergeBundle mergeBundle, int topLevel) {
if (topLevel != 1 || mergeBundle == null) {
return Collections.emptySet();
}
Map<String, Object> after = mergeBundle.getAfter();
Map<String, Object> source = MapUtils.isNotEmpty(after) ? after : mergeBundle.getBefore();
if (MapUtils.isEmpty(source)) {
return Collections.emptySet();
}
return new HashSet<>(source.keySet());
}

private static void recursiveMerge(
MergeBundle mergeBundle,
MergeTableProperties properties,
List<MergeResult> mergeResults,
List<MergeLookupResult> mergeLookupResults,
MergeResult mergeResult,
MergeResult unsetResult,
Map<String, MergeInfo.UpdateJoinKey> updateJoinKeys,
Set<String> sharedJoinKeys,
MergeTableProperties parentProperties,
MergeFilter mergeFilter,
int topLevel,
int loopTime,
List<MapDiffUtil.KeyDiffInfo> updateKeyDiffInfos,
Set<String> mainTableKeys
) {
boolean unsetResultNull = null == unsetResult;
MergeResult updateKeyDiff = null;
Expand All @@ -153,7 +187,7 @@ public static void recursiveMerge(
}
break;
case updateWrite:
unsetResult = updateWriteUnsetMerge(mergeBundle, properties, updateJoinKeys, unsetResult, sharedJoinKeys, mergeFilter, topLevel);
unsetResult = updateWriteUnsetMerge(mergeBundle, properties, updateJoinKeys, unsetResult, sharedJoinKeys, mergeFilter, topLevel, mainTableKeys);
if (unsetResultNull) {
addUnsetMerge(mergeResults, unsetResult);
}
Expand Down Expand Up @@ -198,7 +232,8 @@ public static void recursiveMerge(
mergeFilter,
topLevel,
privateLoopTime,
null
null,
mainTableKeys
);
recursiveOnce = true;
}
Expand Down Expand Up @@ -266,7 +301,8 @@ private static MergeResult addMergeResults(List<MergeResult> mergeResults, Merge
private static MergeResult updateWriteUnsetMerge(
MergeBundle mergeBundle, MergeTableProperties currentProperty,
Map<String, MergeInfo.UpdateJoinKey> updateJoinKeys,
MergeResult mergeResult, Set<String> sharedJoinKeys, MergeFilter mergeFilter, int topLevel) {
MergeResult mergeResult, Set<String> sharedJoinKeys, MergeFilter mergeFilter, int topLevel,
Set<String> mainTableKeys) {
if (null == currentProperty) {
return mergeResult;
}
Expand Down Expand Up @@ -314,7 +350,15 @@ private static MergeResult updateWriteUnsetMerge(
if (null == mergeResult.getOperation()) {
mergeResult.setOperation(MergeResult.Operation.UPDATE);
}
Document unsetDoc = buildUnsetDocument(sharedJoinKeys, after, targetPath, isArray, firstMergeResult);
Set<String> effectiveSharedJoinKeys = sharedJoinKeys;
if (EmptyKit.isEmpty(targetPath) && CollectionUtils.isNotEmpty(mainTableKeys)) {
effectiveSharedJoinKeys = new HashSet<>();
if (sharedJoinKeys != null) {
effectiveSharedJoinKeys.addAll(sharedJoinKeys);
}
effectiveSharedJoinKeys.addAll(mainTableKeys);
}
Document unsetDoc = buildUnsetDocument(effectiveSharedJoinKeys, after, targetPath, isArray, firstMergeResult);
Document update = mergeResult.getUpdate();
if (update.containsKey(UNSET_KEY)) {
update.get(UNSET_KEY, Document.class).putAll(unsetDoc);
Expand Down Expand Up @@ -854,12 +898,7 @@ protected static Document unsetFilter(Map<String, Object> before, Map<String, Ob
Document document = new Document();
for (Map<String, String> joinKey : joinKeys) {
String key = joinKey.get("target");
Object value;
if (topLevel == 1) {
value = MapUtil.getValueByKey(after, key);
} else {
value = MapUtil.getValueByKey(before, key);
}
Object value = MapUtil.getValueByKey(before, key);
document.put(key, value);
}
return document;
Expand Down