diff --git a/nifi-nar-bundles/nifi-extension-utils/nifi-database-utils/src/main/java/org/apache/nifi/util/db/JdbcCommon.java b/nifi-nar-bundles/nifi-extension-utils/nifi-database-utils/src/main/java/org/apache/nifi/util/db/JdbcCommon.java index b78408c912..ad7471a54c 100644 --- a/nifi-nar-bundles/nifi-extension-utils/nifi-database-utils/src/main/java/org/apache/nifi/util/db/JdbcCommon.java +++ b/nifi-nar-bundles/nifi-extension-utils/nifi-database-utils/src/main/java/org/apache/nifi/util/db/JdbcCommon.java @@ -650,6 +650,11 @@ public class JdbcCommon { builder.name(columnName).type().unionOf().nullBuilder().endNull().and().bytesType().endUnion().noDefault(); break; + case -150: // SQLServer may return -150 from the driver even though it's really -156 (sql_variant), treat as a union since we don't know what the values will actually be + case -156: + builder.name(columnName).type().unionOf().nullBuilder().endNull().and().stringType().and().intType().and().longType().and().booleanType().and().bytesType().and() + .doubleType().and().floatType().endUnion().noDefault(); + break; default: throw new IllegalArgumentException("createSchema: Unknown SQL type " + meta.getColumnType(i) + " / " + meta.getColumnTypeName(i) diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/PutDatabaseRecord.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/PutDatabaseRecord.java index 5e94200b44..3a1c8ca56e 100644 --- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/PutDatabaseRecord.java +++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/PutDatabaseRecord.java @@ -736,12 +736,20 @@ public class PutDatabaseRecord extends AbstractProcessor { } } else { sqlType = column.getDataType(); + // SQLServer returns -150 for sql_variant from DatabaseMetaData though the server expects -156 when setting a sql_variant parameter + if (sqlType == -150) { + sqlType = -156; + } } // Convert (if necessary) from field data type to column data type if (fieldSqlType != sqlType) { try { DataType targetDataType = DataTypeUtils.getDataTypeFromSQLTypeValue(sqlType); + // If sqlType is unsupported, fall back to the fieldSqlType instead + if (targetDataType == null) { + targetDataType = DataTypeUtils.getDataTypeFromSQLTypeValue(fieldSqlType); + } if (targetDataType != null) { if (sqlType == Types.BLOB || sqlType == Types.BINARY) { if (currentValue instanceof Object[]) {