Skip to content

Commit

Permalink
0005992: Added parameter to adjust how the conflict resolver handles …
Browse files Browse the repository at this point in the history
…null values when resolving a unique index violation
  • Loading branch information
evan-miller-jumpmind committed Sep 28, 2023
1 parent 7515ae0 commit f86b687
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 1 deletion.
Expand Up @@ -122,6 +122,7 @@ private ParameterConstants() {
public final static String AUTO_RESOLVE_FOREIGN_KEY_VIOLATION_REVERSE = "auto.resolve.foreign.key.violation.reverse";
public final static String AUTO_RESOLVE_FOREIGN_KEY_VIOLATION_REVERSE_PEERS = "auto.resolve.foreign.key.violation.reverse.peers";
public final static String AUTO_RESOLVE_FOREIGN_KEY_VIOLATION_REVERSE_RELOAD = "auto.resolve.foreign.key.violation.reverse.reload";
public final static String AUTO_RESOLVE_UNIQUE_INDEX_IGNORE_NULL_VALUES = "auto.resolve.unique.index.ignore.null.values";
public final static String AUTO_INSERT_REG_SVR_IF_NOT_FOUND = "auto.insert.registration.svr.if.not.found";
public final static String AUTO_SYNC_CONFIGURATION = "auto.sync.configuration";
public final static String AUTO_SYNC_CONFIGURATION_ON_INCOMING = "auto.sync.configuration.on.incoming";
Expand Down
Expand Up @@ -54,6 +54,8 @@ public DatabaseWriterSettings buildParameterDatabaseWriterSettings(List<? extend
settings.setSaveCurrentValueOnError(
parameterService.is(ParameterConstants.DATA_LOADER_ERROR_RECORD_CUR_VAL, false));
settings.setFitToColumn(parameterService.is(ParameterConstants.DATA_LOADER_FIT_TO_COLUMN, false));
settings.setAutoResolveUniqueIndexIgnoreNullValues(
parameterService.is(ParameterConstants.AUTO_RESOLVE_UNIQUE_INDEX_IGNORE_NULL_VALUES, true));
settings.setLogConflictResolution(parameterService.is(ParameterConstants.LOG_CONFLICT_RESOLUTION));
settings.setTextColumnExpression(
parameterService.getString(ParameterConstants.DATA_LOADER_TEXT_COLUMN_EXPRESSION));
Expand Down
Expand Up @@ -1091,6 +1091,15 @@ auto.resolve.foreign.key.violation.reverse=false
# Type: boolean
auto.resolve.foreign.key.violation.reverse.peers=false

# If this is true, when a batch receives a unique index violation,
# the blocking rows for each unique index will only be deleted
# if the unique index has a value that is not null.
#
# DatabaseOverridable: false
# Tags: load
# Type: boolean
auto.resolve.unique.index.ignore.null.values=true

# If this is true, when a reload batch receives a foreign key violation,
# the missing data will be automatically sent to resolve it.
# The resolution is done at the target node by sending a script
Expand Down
Expand Up @@ -46,6 +46,7 @@ public class DatabaseWriterSettings {
protected boolean ignoreMissingTables = true;
protected boolean saveCurrentValueOnError = false;
protected boolean fitToColumn = false;
protected boolean autoResolveUniqueIndexIgnoreNullValues = true;
protected boolean logConflictResolution = false;
protected boolean logSqlParamsOnError = true;
protected boolean loadOnlyNode = false;
Expand Down Expand Up @@ -266,6 +267,14 @@ public boolean isFitToColumn() {
return fitToColumn;
}

public boolean isAutoResolveUniqueIndexIgnoreNullValues() {
return autoResolveUniqueIndexIgnoreNullValues;
}

public void setAutoResolveUniqueIndexIgnoreNullValues(boolean autoResolveUniqueIndexIgnoreNullValues) {
this.autoResolveUniqueIndexIgnoreNullValues = autoResolveUniqueIndexIgnoreNullValues;
}

public void setLogConflictResolution(boolean logConflictResolution) {
this.logConflictResolution = logConflictResolution;
}
Expand Down
Expand Up @@ -515,9 +515,17 @@ protected int deleteUniqueConstraintRow(IDatabasePlatform platform, ISqlTemplate
Map<String, String> values = data.toColumnNameValuePairs(databaseWriter.getSourceTable().getColumnNames(), CsvData.ROW_DATA);
List<Column> whereColumns = new ArrayList<Column>();
List<String> whereValues = new ArrayList<String>();
boolean hasNotNullValue = false;
for (IndexColumn indexColumn : uniqueIndex.getColumns()) {
whereColumns.add(targetTable.getColumnWithName(indexColumn.getName()));
whereValues.add(values.get(indexColumn.getName()));
String value = values.get(indexColumn.getName());
whereValues.add(value);
hasNotNullValue = hasNotNullValue || (value != null);
}
if (!hasNotNullValue && databaseWriter.getWriterSettings().isAutoResolveUniqueIndexIgnoreNullValues()) {
log.debug("Did not issue correction for possible violation of unique index {} on table {} during {} with batch {} because null values are ignored",
uniqueIndex.getName(), targetTable.getName(), data.getDataEventType().toString(), databaseWriter.getContext().getBatch().getNodeBatchId());
return 0;
}
return deleteRow(platform, sqlTemplate, databaseWriter, targetTable, whereColumns, whereValues, true);
}
Expand Down

0 comments on commit f86b687

Please sign in to comment.