NIFI-2623: Fixed support for binary types in SelectHiveQL

This closes #920.

Signed-off-by: Bryan Bende <bbende@apache.org>
This commit is contained in:
Matt Burgess 2016-08-23 10:17:14 -04:00 committed by Bryan Bende
parent 8cc670c8a6
commit fbec3b9c13
No known key found for this signature in database
GPG Key ID: A0DDA9ED50711C39
1 changed files with 13 additions and 5 deletions

View File

@ -103,11 +103,19 @@ public class HiveJdbcCommon {
if (value == null) { if (value == null) {
rec.put(i - 1, null); rec.put(i - 1, null);
} else if (javaSqlType == BINARY || javaSqlType == VARBINARY || javaSqlType == LONGVARBINARY || javaSqlType == ARRAY || javaSqlType == BLOB || javaSqlType == CLOB) { } else if (javaSqlType == BINARY || javaSqlType == VARBINARY || javaSqlType == LONGVARBINARY || javaSqlType == BLOB || javaSqlType == CLOB) {
// bytes requires little bit different handling // bytes requires little bit different handling
byte[] bytes = rs.getBytes(i); ByteBuffer bb = null;
ByteBuffer bb = ByteBuffer.wrap(bytes); if (value instanceof byte[]) {
rec.put(i - 1, bb); bb = ByteBuffer.wrap((byte[]) value);
} else if (value instanceof ByteBuffer) {
bb = (ByteBuffer) value;
}
if (bb != null) {
rec.put(i - 1, bb);
} else {
throw new IOException("Could not process binary object of type " + value.getClass().getName());
}
} else if (value instanceof Byte) { } else if (value instanceof Byte) {
// tinyint(1) type is returned by JDBC driver as java.sql.Types.TINYINT // tinyint(1) type is returned by JDBC driver as java.sql.Types.TINYINT
@ -202,6 +210,7 @@ public class HiveJdbcCommon {
case NCHAR: case NCHAR:
case NVARCHAR: case NVARCHAR:
case VARCHAR: case VARCHAR:
case ARRAY:
builder.name(columnName).type().unionOf().nullBuilder().endNull().and().stringType().endUnion().noDefault(); builder.name(columnName).type().unionOf().nullBuilder().endNull().and().stringType().endUnion().noDefault();
break; break;
@ -265,7 +274,6 @@ public class HiveJdbcCommon {
case BINARY: case BINARY:
case VARBINARY: case VARBINARY:
case LONGVARBINARY: case LONGVARBINARY:
case ARRAY:
case BLOB: case BLOB:
case CLOB: case CLOB:
builder.name(columnName).type().unionOf().nullBuilder().endNull().and().bytesType().endUnion().noDefault(); builder.name(columnName).type().unionOf().nullBuilder().endNull().and().bytesType().endUnion().noDefault();