Skip to content

Commit 971d42f

Browse files
committed
MLE-26428 More sensible null handling for incremental write
1 parent d7f4b7a commit 971d42f

File tree

2 files changed

+47
-4
lines changed

2 files changed

+47
-4
lines changed

marklogic-client-api/src/main/java/com/marklogic/client/datamovement/filter/IncrementalWriteFilter.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2010-2025 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
2+
* Copyright (c) 2010-2026 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
33
*/
44
package com.marklogic.client.datamovement.filter;
55

@@ -50,15 +50,21 @@ public static class Builder {
5050
* @param keyName the name of the MarkLogic metadata key that will hold the hash value; defaults to "incrementalWriteHash".
5151
*/
5252
public Builder hashKeyName(String keyName) {
53-
this.hashKeyName = keyName;
53+
// Don't let user shoot themselves in the foot with an empty key name.
54+
if (keyName != null && !keyName.trim().isEmpty()) {
55+
this.hashKeyName = keyName;
56+
}
5457
return this;
5558
}
5659

5760
/**
5861
* @param keyName the name of the MarkLogic metadata key that will hold the timestamp value; defaults to "incrementalWriteTimestamp".
5962
*/
6063
public Builder timestampKeyName(String keyName) {
61-
this.timestampKeyName = keyName;
64+
// Don't let user shoot themselves in the foot with an empty key name.
65+
if (keyName != null && !keyName.trim().isEmpty()) {
66+
this.timestampKeyName = keyName;
67+
}
6268
return this;
6369
}
6470

marklogic-client-api/src/test/java/com/marklogic/client/datamovement/filter/IncrementalWriteTest.java

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2010-2025 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
2+
* Copyright (c) 2010-2026 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
33
*/
44
package com.marklogic.client.datamovement.filter;
55

@@ -181,6 +181,43 @@ void noRangeIndexForFieldWithEval() {
181181
"fail with a helpful error message. Actual message: " + message);
182182
}
183183

184+
@Test
185+
void customTimestampKeyName() {
186+
filter = IncrementalWriteFilter.newBuilder()
187+
.hashKeyName("incrementalWriteHash")
188+
.timestampKeyName("myTimestamp")
189+
.build();
190+
191+
writeTenDocuments();
192+
193+
DocumentMetadataHandle metadata = Common.client.newDocumentManager().readMetadata("/incremental/test/doc-1.xml",
194+
new DocumentMetadataHandle());
195+
196+
assertNotNull(metadata.getMetadataValues().get("myTimestamp"));
197+
assertNotNull(metadata.getMetadataValues().get("incrementalWriteHash"));
198+
assertFalse(metadata.getMetadataValues().containsKey("incrementalWriteTimestamp"));
199+
}
200+
201+
/**
202+
* The thought for this test is that if the user passes null in (which could happen via our Spark connector),
203+
* they're breaking the feature. So don't let them do that - ignore null and use the default values.
204+
*/
205+
@Test
206+
void nullIsIgnoredForKeyNames() {
207+
filter = IncrementalWriteFilter.newBuilder()
208+
.hashKeyName(null)
209+
.timestampKeyName(null)
210+
.build();
211+
212+
writeTenDocuments();
213+
214+
DocumentMetadataHandle metadata = Common.client.newDocumentManager().readMetadata("/incremental/test/doc-1.xml",
215+
new DocumentMetadataHandle());
216+
217+
assertNotNull(metadata.getMetadataValues().get("incrementalWriteHash"));
218+
assertNotNull(metadata.getMetadataValues().get("incrementalWriteTimestamp"));
219+
}
220+
184221
private void verifyIncrementalWriteWorks() {
185222
writeTenDocuments();
186223
verifyDocumentsHasHashInMetadataKey();

0 commit comments

Comments
 (0)