Skip to content
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

NIFI-12313 - Update PutDatabaseRecord.java add property use database table column datatype #7981

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,14 @@ public class PutDatabaseRecord extends AbstractProcessor {
.expressionLanguageSupported(FLOWFILE_ATTRIBUTES)
.build();

static final PropertyDescriptor USE_DATABASE_TABLE_COLUMN_DATATYPE = new Builder()
.name("put-db-record-use-database-table-column-datatype")
.displayName("Use Database Table Column Data Types")
.description("Enabling this option will cause all column values to be formatted using database table column data types.")
.allowableValues("true", "false")
.defaultValue("true")
.build();

static final PropertyDescriptor DB_TYPE;

protected static final Map<String, DatabaseAdapter> dbAdapters;
Expand Down Expand Up @@ -399,6 +407,7 @@ public class PutDatabaseRecord extends AbstractProcessor {
pds.add(RollbackOnFailure.ROLLBACK_ON_FAILURE);
pds.add(TABLE_SCHEMA_CACHE_SIZE);
pds.add(MAX_BATCH_SIZE);
pds.add(USE_DATABASE_TABLE_COLUMN_DATATYPE);

propDescriptors = Collections.unmodifiableList(pds);
}
Expand Down Expand Up @@ -604,6 +613,7 @@ private void executeDML(final ProcessContext context, final ProcessSession sessi
final String updateKeys = context.getProperty(UPDATE_KEYS).evaluateAttributeExpressions(flowFile).getValue();
final int maxBatchSize = context.getProperty(MAX_BATCH_SIZE).evaluateAttributeExpressions(flowFile).asInteger();
final int timeoutMillis = context.getProperty(QUERY_TIMEOUT).evaluateAttributeExpressions().asTimePeriod(TimeUnit.MILLISECONDS).intValue();
final boolean useDatabaseTableColumnDatatype = context.getProperty(USE_DATABASE_TABLE_COLUMN_DATATYPE).asBoolean();

// Ensure the table name has been set, the generated SQL statements (and TableSchema cache) will need it
if (StringUtils.isEmpty(tableName)) {
Expand Down Expand Up @@ -740,7 +750,7 @@ private void executeDML(final ProcessContext context, final ProcessSession sessi
}

// Convert (if necessary) from field data type to column data type
if (fieldSqlType != sqlType) {
if ((fieldSqlType != sqlType) && useDatabaseTableColumnDatatype) {
try {
DataType targetDataType = DataTypeUtils.getDataTypeFromSQLTypeValue(sqlType);
// If sqlType is unsupported, fall back to the fieldSqlType instead
Expand Down