-
Notifications
You must be signed in to change notification settings - Fork 74
MLE-26918 Added fromView support for incremental write #1897
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
79 changes: 79 additions & 0 deletions
79
...nt-api/src/main/java/com/marklogic/client/datamovement/filter/IncrementalWriteConfig.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| /* | ||
| * Copyright (c) 2010-2026 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved. | ||
| */ | ||
| package com.marklogic.client.datamovement.filter; | ||
|
|
||
| import com.marklogic.client.document.DocumentWriteOperation; | ||
|
|
||
| import java.util.Collections; | ||
| import java.util.Map; | ||
| import java.util.function.Consumer; | ||
|
|
||
| /** | ||
| * Configuration for incremental write filtering. | ||
| * | ||
| * @since 8.1.0 | ||
| */ | ||
| public class IncrementalWriteConfig { | ||
|
|
||
| private final String hashKeyName; | ||
| private final String timestampKeyName; | ||
| private final boolean canonicalizeJson; | ||
| private final Consumer<DocumentWriteOperation[]> skippedDocumentsConsumer; | ||
| private final String[] jsonExclusions; | ||
| private final String[] xmlExclusions; | ||
| private final Map<String, String> xmlNamespaces; | ||
| private final String schemaName; | ||
| private final String viewName; | ||
|
|
||
| public IncrementalWriteConfig(String hashKeyName, String timestampKeyName, boolean canonicalizeJson, | ||
| Consumer<DocumentWriteOperation[]> skippedDocumentsConsumer, | ||
| String[] jsonExclusions, String[] xmlExclusions, Map<String, String> xmlNamespaces, | ||
| String schemaName, String viewName) { | ||
| this.hashKeyName = hashKeyName; | ||
| this.timestampKeyName = timestampKeyName; | ||
| this.canonicalizeJson = canonicalizeJson; | ||
| this.skippedDocumentsConsumer = skippedDocumentsConsumer; | ||
| this.jsonExclusions = jsonExclusions; | ||
| this.xmlExclusions = xmlExclusions; | ||
| this.xmlNamespaces = xmlNamespaces != null ? Collections.unmodifiableMap(xmlNamespaces) : null; | ||
| this.schemaName = schemaName; | ||
| this.viewName = viewName; | ||
| } | ||
|
|
||
| public String getHashKeyName() { | ||
| return hashKeyName; | ||
| } | ||
|
|
||
| public String getTimestampKeyName() { | ||
| return timestampKeyName; | ||
| } | ||
|
|
||
| public boolean isCanonicalizeJson() { | ||
| return canonicalizeJson; | ||
| } | ||
|
|
||
| public Consumer<DocumentWriteOperation[]> getSkippedDocumentsConsumer() { | ||
| return skippedDocumentsConsumer; | ||
| } | ||
|
|
||
| public String[] getJsonExclusions() { | ||
| return jsonExclusions; | ||
| } | ||
|
|
||
| public String[] getXmlExclusions() { | ||
| return xmlExclusions; | ||
| } | ||
|
|
||
| public Map<String, String> getXmlNamespaces() { | ||
| return xmlNamespaces != null ? xmlNamespaces : Collections.emptyMap(); | ||
| } | ||
|
|
||
| public String getSchemaName() { | ||
| return schemaName; | ||
| } | ||
|
|
||
| public String getViewName() { | ||
| return viewName; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
...pi/src/main/java/com/marklogic/client/datamovement/filter/IncrementalWriteViewFilter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| /* | ||
| * Copyright (c) 2010-2026 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved. | ||
| */ | ||
| package com.marklogic.client.datamovement.filter; | ||
|
|
||
| import com.marklogic.client.FailedRequestException; | ||
| import com.marklogic.client.document.DocumentWriteOperation; | ||
| import com.marklogic.client.document.DocumentWriteSet; | ||
| import com.marklogic.client.row.RowTemplate; | ||
|
|
||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
|
|
||
| /** | ||
| * Uses an Optic query with fromView to get the existing hash values for a set of URIs from a TDE view. | ||
| * This implementation requires a TDE template to be deployed that extracts the URI and hash metadata. | ||
| * | ||
| * @since 8.1.0 | ||
| */ | ||
| class IncrementalWriteViewFilter extends IncrementalWriteFilter { | ||
|
|
||
| IncrementalWriteViewFilter(IncrementalWriteConfig config) { | ||
| super(config); | ||
| } | ||
|
|
||
| @Override | ||
| public DocumentWriteSet apply(Context context) { | ||
| final String[] uris = context.getDocumentWriteSet().stream() | ||
| .filter(op -> DocumentWriteOperation.OperationType.DOCUMENT_WRITE.equals(op.getOperationType())) | ||
| .map(DocumentWriteOperation::getUri) | ||
| .toArray(String[]::new); | ||
|
|
||
| RowTemplate rowTemplate = new RowTemplate(context.getDatabaseClient()); | ||
|
|
||
| try { | ||
| Map<String, String> existingHashes = rowTemplate.query(op -> | ||
| op.fromView(getConfig().getSchemaName(), getConfig().getViewName()) | ||
| .where(op.in(op.col("uri"), op.xs.stringSeq(uris))), | ||
|
|
||
| rows -> { | ||
| Map<String, String> map = new HashMap<>(); | ||
| rows.forEach(row -> { | ||
| String uri = row.getString("uri"); | ||
| String existingHash = row.getString("hash"); | ||
| map.put(uri, existingHash); | ||
| }); | ||
| return map; | ||
| } | ||
| ); | ||
|
|
||
| return filterDocuments(context, uri -> existingHashes.get(uri)); | ||
| } catch (FailedRequestException e) { | ||
| String message = "Unable to query for existing incremental write hashes from view " + getConfig().getSchemaName() + "." + getConfig().getViewName() + "; cause: " + e.getMessage(); | ||
| throw new FailedRequestException(message, e.getFailedRequest()); | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The rethrown
FailedRequestExceptiondrops the original exception as the cause, which makes debugging harder (stack trace/cause chain is lost). Prefer a constructor overload that accepts the cause, or initialize the cause on the newly created exception so the originaleis preserved.