Skip to content

Commit 942410f

Browse files
Ryan DewMarkLogic Builder
authored andcommitted
DHFPROD-10568: Only include 'latest' when matching temporal docs
1 parent 2b9f020 commit 942410f

File tree

3 files changed

+33
-4
lines changed

3 files changed

+33
-4
lines changed

marklogic-data-hub/src/main/resources/ml-modules/root/data-hub/5/impl/hub-utils/invoke-queue-write.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ if(writerQueue != null && Object.keys(writerQueue).length !== 0) {
8181
const quality = context.quality || 0;
8282

8383
if (temporalCollection) {
84+
if (!content.value) {
85+
content.value = cts.doc(content.uri);
86+
}
8487
// temporalDocURI is managed by the temporal package and must not be carried forward.
8588
if (metadata) {
8689
delete metadata.temporalDocURI;

marklogic-data-hub/src/main/resources/ml-modules/root/data-hub/5/mastering/matching/matchable.mjs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import httpUtils from "/data-hub/5/impl/http-utils.mjs";
44
import hubUtils from "/data-hub/5/impl/hub-utils.mjs";
55
import common from "/data-hub/5/mastering/common.mjs";
66
import {getEntityModel} from "/data-hub/core/models/entities.mjs";
7+
import temporalLib from "/data-hub/5/temporal/hub-temporal.mjs";
78

89
// matching XQuery module for performance
910
const matchingXqy = require("/data-hub/5/mastering/matching/matching.xqy");
@@ -113,7 +114,12 @@ export class Matchable {
113114
*/
114115
baselineQuery() {
115116
if (!this._baselineQuery) {
116-
const firstBaseline = this._model.instanceQuery();
117+
let firstBaseline = this._model.instanceQuery();
118+
const temporalCollections = temporalLib.getTemporalCollections().toArray();
119+
const includesTemporalDocuments = temporalCollections.some(collection => cts.exists(cts.andQuery([firstBaseline, cts.collectionQuery(collection)])));
120+
if (includesTemporalDocuments) {
121+
firstBaseline = cts.andQuery([firstBaseline, cts.collectionQuery("latest")]);
122+
}
117123
this._baselineQuery = common.applyInterceptors("Baseline Query Interceptor", firstBaseline, this.matchStep.baselineQueryInterceptors);
118124
if (matchingTraceEnabled) {
119125
xdmp.trace(matchingTraceEvent, `Initializing the baseline match query: ${xdmp.describe(this._baselineQuery, Sequence.from([]), Sequence.from([]))}`);

marklogic-data-hub/src/test/ml-modules/root/test/suites/data-hub/features/temporal/temporal.mjs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import temporalFeature from "/data-hub/features/temporal.mjs";
2-
const test = require("/test/test-helper.xqy");
32
import temporalLib from "/data-hub/5/temporal/hub-temporal.mjs";
43

4+
import { Matchable } from "/data-hub/5/mastering/matching/matchable.mjs";
5+
6+
const test = require("/test/test-helper.xqy");
7+
58
const myTempCollection = "koolTest";
69
function getTemporalCollection(tempCollection) {
710
const temporalCollections = temporalLib.getTemporalCollections().toArray();
@@ -37,15 +40,32 @@ const contentArray = [];
3740
contentArray.push({
3841
"uri": "/affiliate1.json",
3942
"value": { "meta": { "systemStart": "1601-01-01T13:59:00Z", "systemEnd": "9999-12-31T11:59:59Z", "validStart": fn.currentDateTime() , "validEnd": fn.currentDateTime().add(xs.yearMonthDuration('P1Y')) },"customerId": "1"} ,
40-
"context": { "collections":[myTempCollection]}});
43+
"context": { "collections":[myTempCollection, "AffiliateCustomer"]}});
4144
xdmp.invokeFunction(() =>{
42-
temporalFeature.onInstanceSave(stepContext, model, contentArray);
45+
temporalFeature.onInstanceSave(stepContext, model, contentArray);
4346
});
4447
xdmp.invokeFunction(() => {
4548
assertions.push(test.assertEqual(1,
4649
cts.estimate(cts.andQuery([cts.collectionQuery(["koolTest"]), cts.collectionQuery(["latest"])])),
4750
`One document must be found with collection: ${myTempCollection}.`));
4851
});
52+
53+
// Test matching with temporal collection
54+
xdmp.invokeFunction(() => {
55+
const matchable = new Matchable({ targetEntityType: "http://example.org/AffiliateCustomer-0.0.1/AffiliateCustomer" });
56+
const baselineQuery = matchable.baselineQuery();
57+
assertions.push(
58+
test.assertTrue(baselineQuery instanceof cts.andQuery, `Baseline for temporal query should be a cts.andQuery: ${xdmp.toJsonString(baselineQuery)}.`)
59+
);
60+
const latestQuery = cts.andQueryQueries(baselineQuery).toArray()[1];
61+
assertions.push(
62+
test.assertTrue(latestQuery instanceof cts.collectionQuery, `Second query in cts.andQuery should be a cts.collectionQuery: ${xdmp.toJsonString(latestQuery)}.`),
63+
test.assertEqual("latest",fn.head(cts.collectionQueryUris(latestQuery)))
64+
);
65+
66+
});
67+
68+
4969
const contentArrayDelete = [];
5070
contentArrayDelete.push({
5171
"uri": "/affiliate1.json",

0 commit comments

Comments
 (0)