Skip to content

Commit 5b40539

Browse files
ryanjdewSameeraPriyathamTadikonda
authored andcommitted
DHFPROD-4830: Check for false positives on search for multiple merge actions on document (#4009)
1 parent 3fe37b3 commit 5b40539

File tree

4 files changed

+120
-4
lines changed

4 files changed

+120
-4
lines changed

marklogic-data-hub/src/main/resources/ml-modules/root/data-hub/5/builtins/steps/mastering/default/merging.sjs

+10-4
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,16 @@ function main(content, options) {
5555
uriRangeQuery
5656
),
5757
['unfiltered',cts.indexOrder(datahubCreatedOnRef, 'descending')]
58-
).toArray().map(
59-
(result) => result.xpath(`/matchSummary/actionDetails/*[action = 'merge']`).toArray()
60-
.filter((actionNode) => cts.contains(actionNode, urisQuery))[0].toObject()
61-
);
58+
).toArray()
59+
// get the actionNode for the URI
60+
.map(
61+
(result) => result.xpath(`/matchSummary/actionDetails/*[action = 'merge']`).toArray()
62+
.filter((actionNode) => cts.contains(actionNode, urisQuery))[0]
63+
)
64+
// filter out false positives that don't have merge actions for the given URI
65+
.filter((actionNode) => !!actionNode)
66+
// convert node to JSON object
67+
.map((actionNode) => actionNode.toObject());
6268
if (otherMergesForURI.some((otherMerge) => otherMerge.uris.length > uriActionDetails.uris.length)) {
6369
return Sequence.from([]);
6470
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const merging = require("/data-hub/5/builtins/steps/mastering/default/merging.sjs");
2+
const test = require("/test/test-helper.xqy");
3+
4+
const assertions = [];
5+
let caughtException = null;
6+
try {
7+
merging.main({uri: '/merge-with-doc1.json'}, {mergeOptions: {}});
8+
} catch (e) {
9+
caughtException = e;
10+
}
11+
assertions.push(test.assertFalse(!!caughtException, `Call threw exception unexpectedly. (Exception: ${caughtException})`));
12+
assertions;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
declareUpdate();
2+
3+
// Inserting documents into final database
4+
xdmp.documentInsert("/matchSummary1.json",
5+
{
6+
"matchSummary": {
7+
"URIsToProcess": [
8+
"/merge-with-doc1.json",
9+
"/doc2.json"
10+
],
11+
"actionDetails": {
12+
"/merge-with-doc1.json": {
13+
"action": "merge",
14+
"uris": [
15+
"/match1.json",
16+
"/match2.json"
17+
]
18+
},
19+
"/doc2.json": {
20+
"action": "notify",
21+
"uris": [
22+
"/match3.json",
23+
"/match4.json"
24+
]
25+
}
26+
}
27+
}
28+
},
29+
{
30+
permissions: xdmp.defaultPermissions(),
31+
collections: ["datahubMasteringMatchSummary"],
32+
metadata: {
33+
// add 1 hr to ensure this is selected first
34+
"datahubCreatedOn": fn.currentDateTime().add(xs.dayTimeDuration('P0DT1H'))
35+
}
36+
});
37+
38+
xdmp.documentInsert("/matchSummary2.json",
39+
{
40+
"matchSummary": {
41+
"URIsToProcess": [
42+
"/notify-with-doc1.json",
43+
"/doc2.json"
44+
],
45+
"actionDetails": {
46+
"/notify-with-doc1.json": {
47+
"action": "notify",
48+
"uris": [
49+
"/match1.json",
50+
"/match2.json"
51+
]
52+
},
53+
"/doc2.json": {
54+
"action": "merge",
55+
"uris": [
56+
"/match3.json",
57+
"/match4.json"
58+
]
59+
}
60+
}
61+
}
62+
},
63+
{
64+
permissions: xdmp.defaultPermissions(),
65+
collections: ["datahubMasteringMatchSummary"],
66+
metadata: {
67+
"datahubCreatedOn": fn.currentDateTime()
68+
}
69+
});
70+
71+
xdmp.documentInsert('/match1.json',
72+
{
73+
envelope: { instance: { minimalDoc: 'value'}}
74+
},
75+
{
76+
permissions: xdmp.defaultPermissions(),
77+
collections: ["test-doc"],
78+
metadata: {
79+
"datahubCreatedOn": fn.currentDateTime()
80+
}
81+
});
82+
83+
xdmp.documentInsert('/match2.json',
84+
{
85+
envelope: { instance: { minimalDoc: 'value'}}
86+
},
87+
{
88+
permissions: xdmp.defaultPermissions(),
89+
collections: ["test-doc"],
90+
metadata: {
91+
"datahubCreatedOn": fn.currentDateTime()
92+
}
93+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
declareUpdate();
2+
3+
xdmp.collectionDelete('test-doc');
4+
5+
xdmp.collectionDelete('datahubMasteringMatchSummary');

0 commit comments

Comments
 (0)