NIFI-2356 ConvertJSONToSQL assumes IS_AUTOINCREMENT

This closes #862.

Signed-off-by: Bryan Bende <bbende@apache.org>
This commit is contained in:
Peter Wicks 2016-08-15 10:49:37 -06:00 committed by Bryan Bende
parent fa5da543e6
commit 44057f097a
No known key found for this signature in database
GPG Key ID: A0DDA9ED50711C39
1 changed files with 14 additions and 1 deletions

View File

@ -23,6 +23,7 @@ import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
@ -668,6 +669,13 @@ public class ConvertJSONToSQL extends AbstractProcessor {
}
public static ColumnDescription from(final ResultSet resultSet) throws SQLException {
final ResultSetMetaData md = resultSet.getMetaData();
List<String> columns = new ArrayList<>();
for (int i = 1; i < md.getColumnCount() + 1; i++) {
columns.add(md.getColumnName(i));
}
final String columnName = resultSet.getString("COLUMN_NAME");
final int dataType = resultSet.getInt("DATA_TYPE");
final int colSize = resultSet.getInt("COLUMN_SIZE");
@ -675,7 +683,12 @@ public class ConvertJSONToSQL extends AbstractProcessor {
final String nullableValue = resultSet.getString("IS_NULLABLE");
final boolean isNullable = "YES".equalsIgnoreCase(nullableValue) || nullableValue.isEmpty();
final String defaultValue = resultSet.getString("COLUMN_DEF");
final String autoIncrementValue = resultSet.getString("IS_AUTOINCREMENT");
String autoIncrementValue = "NO";
if(columns.contains("IS_AUTOINCREMENT")){
autoIncrementValue = resultSet.getString("IS_AUTOINCREMENT");
}
final boolean isAutoIncrement = "YES".equalsIgnoreCase(autoIncrementValue);
final boolean required = !isNullable && !isAutoIncrement && defaultValue == null;