Repository: nifi
Updated Branches:
  refs/heads/master 8cc670c8a -> fbec3b9c1


NIFI-2623: Fixed support for binary types in SelectHiveQL

This closes #920.

Signed-off-by: Bryan Bende <bbe...@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/nifi/repo
Commit: http://git-wip-us.apache.org/repos/asf/nifi/commit/fbec3b9c
Tree: http://git-wip-us.apache.org/repos/asf/nifi/tree/fbec3b9c
Diff: http://git-wip-us.apache.org/repos/asf/nifi/diff/fbec3b9c

Branch: refs/heads/master
Commit: fbec3b9c13dce360a501790b8e215646101d4e77
Parents: 8cc670c
Author: Matt Burgess <mattyb...@apache.org>
Authored: Tue Aug 23 10:17:14 2016 -0400
Committer: Bryan Bende <bbe...@apache.org>
Committed: Tue Aug 23 11:43:46 2016 -0400

----------------------------------------------------------------------
 .../org/apache/nifi/util/hive/HiveJdbcCommon.java | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/nifi/blob/fbec3b9c/nifi-nar-bundles/nifi-hive-bundle/nifi-hive-processors/src/main/java/org/apache/nifi/util/hive/HiveJdbcCommon.java
----------------------------------------------------------------------
diff --git 
a/nifi-nar-bundles/nifi-hive-bundle/nifi-hive-processors/src/main/java/org/apache/nifi/util/hive/HiveJdbcCommon.java
 
b/nifi-nar-bundles/nifi-hive-bundle/nifi-hive-processors/src/main/java/org/apache/nifi/util/hive/HiveJdbcCommon.java
index fb4ac84..afb8104 100644
--- 
a/nifi-nar-bundles/nifi-hive-bundle/nifi-hive-processors/src/main/java/org/apache/nifi/util/hive/HiveJdbcCommon.java
+++ 
b/nifi-nar-bundles/nifi-hive-bundle/nifi-hive-processors/src/main/java/org/apache/nifi/util/hive/HiveJdbcCommon.java
@@ -103,11 +103,19 @@ public class HiveJdbcCommon {
                     if (value == 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
-                        byte[] bytes = rs.getBytes(i);
-                        ByteBuffer bb = ByteBuffer.wrap(bytes);
-                        rec.put(i - 1, bb);
+                        ByteBuffer bb = null;
+                        if (value instanceof byte[]) {
+                            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) {
                         // tinyint(1) type is returned by JDBC driver as 
java.sql.Types.TINYINT
@@ -202,6 +210,7 @@ public class HiveJdbcCommon {
                 case NCHAR:
                 case NVARCHAR:
                 case VARCHAR:
+                case ARRAY:
                     
builder.name(columnName).type().unionOf().nullBuilder().endNull().and().stringType().endUnion().noDefault();
                     break;
 
@@ -265,7 +274,6 @@ public class HiveJdbcCommon {
                 case BINARY:
                 case VARBINARY:
                 case LONGVARBINARY:
-                case ARRAY:
                 case BLOB:
                 case CLOB:
                     
builder.name(columnName).type().unionOf().nullBuilder().endNull().and().bytesType().endUnion().noDefault();

Reply via email to