-
Notifications
You must be signed in to change notification settings - Fork 7
Consolidate Dataclass data update methods - use DIB for update only #7483
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
base: develop
Are you sure you want to change the base?
Changes from 3 commits
e661698
09dd6b0
b5e2ac2
dc19ef1
4d9ff01
a678378
a68e8a8
9d5aa75
4893660
4b5e0ef
d3aea2b
44f7811
a35f233
28142df
04f83ff
3446ba4
2a91cc6
312a13c
60898fa
988d5fd
22745ed
e07508c
896c5cb
53b876f
edca844
3080753
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,7 @@ | |
| package org.labkey.api.query; | ||
|
|
||
| import org.apache.commons.beanutils.ConversionException; | ||
| import org.apache.commons.collections4.MapUtils; | ||
| import org.apache.commons.lang3.StringUtils; | ||
| import org.apache.logging.log4j.LogManager; | ||
| import org.jetbrains.annotations.NotNull; | ||
|
|
@@ -122,6 +123,8 @@ | |
| import static org.labkey.api.audit.TransactionAuditProvider.DB_SEQUENCE_NAME; | ||
| import static org.labkey.api.dataiterator.DetailedAuditLogDataIterator.AuditConfigs.AuditBehavior; | ||
| import static org.labkey.api.dataiterator.DetailedAuditLogDataIterator.AuditConfigs.AuditUserComment; | ||
| import static org.labkey.api.exp.query.ExpMaterialTable.Column.Name; | ||
| import static org.labkey.api.exp.query.ExpMaterialTable.Column.RowId; | ||
| import static org.labkey.api.files.FileContentService.UPLOADED_FILE; | ||
| import static org.labkey.api.util.FileUtil.toFileForRead; | ||
| import static org.labkey.api.util.FileUtil.toFileForWrite; | ||
|
|
@@ -453,6 +456,9 @@ protected int _pump(DataIteratorBuilder etl, final @Nullable ArrayList<Map<Strin | |
| { | ||
| DataIterator it = etl.getDataIterator(context); | ||
|
|
||
| if (null == it) | ||
| return 0; | ||
|
|
||
| try | ||
| { | ||
| if (null != rows) | ||
|
|
@@ -900,6 +906,102 @@ public List<Map<String, Object>> updateRows(User user, Container container, List | |
| return result; | ||
| } | ||
|
|
||
| protected void validatePartitionedRowKeys(Collection<String> columns) | ||
| { | ||
| // do nothing | ||
| } | ||
|
|
||
| public List<Map<String, Object>> updateRowsUsingPartitionedDIB( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| DbScope.Transaction tx, | ||
| User user, | ||
| Container container, | ||
| List<Map<String, Object>> rows, | ||
| BatchValidationException errors, | ||
| @Nullable Map<Enum, Object> configParameters, | ||
| Map<String, Object> extraScriptContext | ||
| ) | ||
| { | ||
| int index = 0; | ||
| int numPartitions = 0; | ||
| List<Map<String, Object>> ret = new ArrayList<>(); | ||
|
|
||
| Set<Long> observedRowIds = new HashSet<>(); | ||
| Set<String> observedNames = new CaseInsensitiveHashSet(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Abstraction is leaking a bit here. If some other structure (e.g., Lists) were to use this it doesn't support "Name" in the same way data classes and sample types do. |
||
|
|
||
| while (index < rows.size()) | ||
| { | ||
| CaseInsensitiveHashSet rowKeys = new CaseInsensitiveHashSet(rows.get(index).keySet()); | ||
|
|
||
| validatePartitionedRowKeys(rowKeys); | ||
|
|
||
| int nextIndex = index + 1; | ||
| while (nextIndex < rows.size() && rowKeys.equals(new CaseInsensitiveHashSet(rows.get(nextIndex).keySet()))) | ||
| nextIndex++; | ||
|
|
||
| List<Map<String, Object>> rowsToProcess = rows.subList(index, nextIndex); | ||
| index = nextIndex; | ||
| numPartitions++; | ||
|
|
||
| DataIteratorContext context = getDataIteratorContext(errors, InsertOption.UPDATE, configParameters); | ||
|
|
||
| // skip audit summary for the partitions, we will perform it once at the end | ||
| context.putConfigParameter(ConfigParameters.SkipAuditSummary, true); | ||
|
|
||
| List<Map<String, Object>> subRet = _updateRowsUsingDIB(user, container, rowsToProcess, context, extraScriptContext); | ||
|
|
||
| // we need to throw if we don't want executeWithRetry() attempt commit() | ||
| if (context.getErrors().hasErrors()) | ||
| throw new DbScope.RetryPassthroughException(context.getErrors()); | ||
|
|
||
| if (subRet != null) | ||
| { | ||
| ret.addAll(subRet); | ||
|
|
||
| // Check if duplicate rows have been processed across the partitions | ||
| // Only start checking for duplicates after the first partition has been processed. | ||
| if (numPartitions > 1) | ||
| { | ||
| // If we are on the second partition, then lazily check all previous rows, otherwise check only the current partition | ||
| checkPartitionForDuplicates(numPartitions == 2 ? ret : subRet, observedRowIds, observedNames, errors); | ||
| } | ||
|
|
||
| if (errors.hasErrors()) | ||
| throw new DbScope.RetryPassthroughException(errors); | ||
| } | ||
| } | ||
|
|
||
| if (numPartitions > 1) | ||
| { | ||
| var auditEvent = tx.getAuditEvent(); | ||
| if (auditEvent != null) | ||
| auditEvent.addDetail(TransactionAuditProvider.TransactionDetail.DataIteratorPartitions, numPartitions); | ||
| } | ||
|
|
||
| _addSummaryAuditEvent(container, user, getDataIteratorContext(errors, InsertOption.UPDATE, configParameters), ret.size()); | ||
|
|
||
| return ret; | ||
| } | ||
|
|
||
| private void checkPartitionForDuplicates(List<Map<String, Object>> partitionRows, Set<Long> globalRowIds, Set<String> globalNames, BatchValidationException errors) | ||
| { | ||
| for (Map<String, Object> row : partitionRows) | ||
| { | ||
| Long rowId = MapUtils.getLong(row, RowId.name()); | ||
| if (rowId != null && !globalRowIds.add(rowId)) | ||
| { | ||
| errors.addRowError(new ValidationException("Duplicate key provided: " + rowId)); | ||
| return; | ||
| } | ||
|
|
||
| Object nameObj = row.get(Name.name()); | ||
| if (nameObj != null && !globalNames.add(nameObj.toString())) | ||
| { | ||
| errors.addRowError(new ValidationException("Duplicate key provided: " + nameObj)); | ||
| return; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| protected void checkDuplicateUpdate(Object pkVals) throws ValidationException | ||
| { | ||
| if (pkVals == null) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| SELECT core.executeJavaUpgradeCode('dropProvisionedDataClassLsidColumn'); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| EXEC core.executeJavaUpgradeCode 'dropProvisionedDataClassLsidColumn'; |
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.
Provide a description for this method that describes its purpose/intent.