Repository: nifi Updated Branches: refs/heads/master a6d259ee0 -> b213ed95e
NIFI-2422: Fix SelectHiveQL handling of Number types This closes #744. Signed-off-by: Bryan Bende <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/nifi/repo Commit: http://git-wip-us.apache.org/repos/asf/nifi/commit/b213ed95 Tree: http://git-wip-us.apache.org/repos/asf/nifi/tree/b213ed95 Diff: http://git-wip-us.apache.org/repos/asf/nifi/diff/b213ed95 Branch: refs/heads/master Commit: b213ed95e02392093925c3f2195ef2382423f2b1 Parents: a6d259e Author: Matt Burgess <[email protected]> Authored: Fri Jul 29 10:07:04 2016 -0400 Committer: Bryan Bende <[email protected]> Committed: Fri Jul 29 15:38:32 2016 -0400 ---------------------------------------------------------------------- .../org/apache/nifi/util/hive/HiveJdbcCommon.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/nifi/blob/b213ed95/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 70e92ca..284eabb 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 @@ -102,7 +102,7 @@ public class HiveJdbcCommon { } for (int i = 1; i <= nrOfColumns; i++) { final int javaSqlType = meta.getColumnType(i); - final Object value = rs.getObject(i); + Object value = rs.getObject(i); if (value == null) { rec.put(i - 1, null); @@ -125,9 +125,21 @@ public class HiveJdbcCommon { // Avro can't handle BigDecimal and BigInteger as numbers - it will throw an AvroRuntimeException such as: "Unknown datum type: java.math.BigDecimal: 38" rec.put(i - 1, value.toString()); - } else if (value instanceof Number || value instanceof Boolean) { + } else if (value instanceof Number) { + // Need to call the right getXYZ() method (instead of the getObject() method above), since Doubles are sometimes returned + // when the JDBC type is 6 (Float) for example. + if (javaSqlType == FLOAT) { + value = rs.getFloat(i); + } else if (javaSqlType == DOUBLE) { + value = rs.getDouble(i); + } else if (javaSqlType == INTEGER || javaSqlType == TINYINT || javaSqlType == SMALLINT) { + value = rs.getInt(i); + } + rec.put(i - 1, value); + } else if (value instanceof Boolean) { + rec.put(i - 1, value); } else { // The different types that we support are numbers (int, long, double, float), // as well as boolean values and Strings. Since Avro doesn't provide
