From e66afe1930d20b61b4fad6faf2ec8334b6e33d0b Mon Sep 17 00:00:00 2001 From: Ralph Gasser Date: Mon, 1 Jul 2019 13:23:13 +0200 Subject: [PATCH 1/3] [CALCITE-3163] AbstractCursor#convertValue() now adheres to JDBC specification. --- .../java/org/apache/calcite/avatica/util/AbstractCursor.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/apache/calcite/avatica/util/AbstractCursor.java b/core/src/main/java/org/apache/calcite/avatica/util/AbstractCursor.java index 5559f60bf7..194f8440a2 100644 --- a/core/src/main/java/org/apache/calcite/avatica/util/AbstractCursor.java +++ b/core/src/main/java/org/apache/calcite/avatica/util/AbstractCursor.java @@ -1318,8 +1318,9 @@ private Object convertValue() throws SQLException { return componentAccessor.getInt(); case Types.BIGINT: return componentAccessor.getLong(); - case Types.FLOAT: + case Types.REAL: return componentAccessor.getFloat(); + case Types.FLOAT: case Types.DOUBLE: return componentAccessor.getDouble(); case Types.ARRAY: From 29a3b8b5eb1669a6114491502fa0f977291b359d Mon Sep 17 00:00:00 2001 From: Ralph Gasser Date: Wed, 3 Jul 2019 13:53:51 +0200 Subject: [PATCH 2/3] [CALCITE-3162] Fixed issue that arise when reading Arrays from Calcite through JdbcMeta by handling all exceptions thrown by JdbcResultSet#extractUsingResultSet() --- .../org/apache/calcite/avatica/remote/TypedValue.java | 11 ++++------- .../apache/calcite/avatica/jdbc/JdbcResultSet.java | 5 ++--- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/core/src/main/java/org/apache/calcite/avatica/remote/TypedValue.java b/core/src/main/java/org/apache/calcite/avatica/remote/TypedValue.java index 9b98d2abb2..6e3c090b12 100644 --- a/core/src/main/java/org/apache/calcite/avatica/remote/TypedValue.java +++ b/core/src/main/java/org/apache/calcite/avatica/remote/TypedValue.java @@ -724,16 +724,15 @@ public static Object getSerialFromProto(Common.TypedValue protoValue) { return Float.intBitsToFloat((int) protoValue.getNumberValue()); case INTEGER: case PRIMITIVE_INT: + case JAVA_SQL_DATE: + case JAVA_SQL_TIME: return Long.valueOf(protoValue.getNumberValue()).intValue(); case PRIMITIVE_SHORT: case SHORT: return Long.valueOf(protoValue.getNumberValue()).shortValue(); case LONG: case PRIMITIVE_LONG: - return Long.valueOf(protoValue.getNumberValue()); - case JAVA_SQL_DATE: - case JAVA_SQL_TIME: - return Long.valueOf(protoValue.getNumberValue()).intValue(); + case NUMBER: case JAVA_SQL_TIMESTAMP: case JAVA_UTIL_DATE: return protoValue.getNumberValue(); @@ -747,8 +746,6 @@ public static Object getSerialFromProto(Common.TypedValue protoValue) { return new BigDecimal(bigInt, (int) protoValue.getNumberValue()); } return new BigDecimal(protoValue.getStringValueBytes().toStringUtf8()); - case NUMBER: - return Long.valueOf(protoValue.getNumberValue()); case NULL: return null; case ARRAY: @@ -802,7 +799,7 @@ public static Common.Rep toProto(Common.TypedValue.Builder builder, Object o) { writeToProtoWithType(builder, o, Common.Rep.DOUBLE); return Common.Rep.DOUBLE; } else if (o instanceof Float) { - writeToProtoWithType(builder, ((Float) o).longValue(), Common.Rep.FLOAT); + writeToProtoWithType(builder, o, Common.Rep.FLOAT); return Common.Rep.FLOAT; } else if (o instanceof BigDecimal) { writeToProtoWithType(builder, o, Common.Rep.BIG_DECIMAL); diff --git a/server/src/main/java/org/apache/calcite/avatica/jdbc/JdbcResultSet.java b/server/src/main/java/org/apache/calcite/avatica/jdbc/JdbcResultSet.java index 7aa7a731db..4ae162a69c 100644 --- a/server/src/main/java/org/apache/calcite/avatica/jdbc/JdbcResultSet.java +++ b/server/src/main/java/org/apache/calcite/avatica/jdbc/JdbcResultSet.java @@ -32,7 +32,6 @@ import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.sql.SQLException; -import java.sql.SQLFeatureNotSupportedException; import java.sql.Struct; import java.sql.Time; import java.sql.Timestamp; @@ -226,8 +225,8 @@ private static Object getValue(ResultSet resultSet, int type, int j, try { // Recursively extracts an Array using its ResultSet-representation return extractUsingResultSet(array, calendar); - } catch (UnsupportedOperationException | SQLFeatureNotSupportedException e) { - // Not every database might implement Array.getResultSet(). This call + } catch (Exception e) { + // Not every database might implement Array.getResultSet() using the expected structure. This call // assumes a non-nested array (depends on the db if that's a valid assumption) return extractUsingArray(array, calendar); } From 23027e453679d9c362b61e40a19d04810ac632b5 Mon Sep 17 00:00:00 2001 From: Ralph Gasser Date: Wed, 3 Jul 2019 16:16:12 +0200 Subject: [PATCH 3/3] Fixed line length of comment. --- .../java/org/apache/calcite/avatica/jdbc/JdbcResultSet.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/src/main/java/org/apache/calcite/avatica/jdbc/JdbcResultSet.java b/server/src/main/java/org/apache/calcite/avatica/jdbc/JdbcResultSet.java index 4ae162a69c..0b2da5d5a9 100644 --- a/server/src/main/java/org/apache/calcite/avatica/jdbc/JdbcResultSet.java +++ b/server/src/main/java/org/apache/calcite/avatica/jdbc/JdbcResultSet.java @@ -226,8 +226,8 @@ private static Object getValue(ResultSet resultSet, int type, int j, // Recursively extracts an Array using its ResultSet-representation return extractUsingResultSet(array, calendar); } catch (Exception e) { - // Not every database might implement Array.getResultSet() using the expected structure. This call - // assumes a non-nested array (depends on the db if that's a valid assumption) + // Not every database might implement Array.getResultSet() using the expected structure. + // This call assumes a non-nested array (depends on the db if that's a valid assumption) return extractUsingArray(array, calendar); } case Types.STRUCT: