From baf98e992aaba9dfc72e960395bb2dedcc7661b4 Mon Sep 17 00:00:00 2001 From: Przemyslaw Motacki Date: Mon, 25 Mar 2024 10:51:24 +0100 Subject: [PATCH] SNOW-1259709 - add mapping for basic types for arrays and maps --- .../snowflake/client/core/ArrowSqlInput.java | 30 +++++++++---------- .../client/jdbc/SnowflakeBaseResultSet.java | 15 +--------- 2 files changed, 16 insertions(+), 29 deletions(-) diff --git a/src/main/java/net/snowflake/client/core/ArrowSqlInput.java b/src/main/java/net/snowflake/client/core/ArrowSqlInput.java index c63291f34..e25dbe360 100644 --- a/src/main/java/net/snowflake/client/core/ArrowSqlInput.java +++ b/src/main/java/net/snowflake/client/core/ArrowSqlInput.java @@ -4,8 +4,6 @@ package net.snowflake.client.core; -import static net.snowflake.client.jdbc.SnowflakeUtil.mapExceptions; - import java.math.BigDecimal; import java.sql.Date; import java.sql.SQLData; @@ -21,6 +19,8 @@ import net.snowflake.client.util.ThrowingBiFunction; import org.apache.arrow.vector.util.JsonStringHashMap; +import static net.snowflake.client.jdbc.SnowflakeUtil.mapSFExceptionToSQLException; + @SnowflakeJdbcInternalApi public class ArrowSqlInput extends BaseSqlInput { @@ -43,7 +43,7 @@ public String readString() throws SQLException { int columnType = ColumnTypeHelper.getColumnType(fieldMetadata.getType(), session); int columnSubType = fieldMetadata.getType(); int scale = fieldMetadata.getScale(); - return mapExceptions( + return mapSFExceptionToSQLException( () -> converters .getStringConverter() @@ -56,7 +56,7 @@ public boolean readBoolean() throws SQLException { return withNextValue( (value, fieldMetadata) -> { int columnType = ColumnTypeHelper.getColumnType(fieldMetadata.getType(), session); - return mapExceptions( + return mapSFExceptionToSQLException( () -> converters.getBooleanConverter().getBoolean(value, columnType)); }); } @@ -65,7 +65,7 @@ public boolean readBoolean() throws SQLException { public byte readByte() throws SQLException { return withNextValue( (value, fieldMetadata) -> - mapExceptions(() -> converters.getNumberConverter().getByte(value))); + mapSFExceptionToSQLException(() -> converters.getNumberConverter().getByte(value))); } @Override @@ -73,7 +73,7 @@ public short readShort() throws SQLException { return withNextValue( (value, fieldMetadata) -> { int columnType = ColumnTypeHelper.getColumnType(fieldMetadata.getType(), session); - return mapExceptions(() -> converters.getNumberConverter().getShort(value, columnType)); + return mapSFExceptionToSQLException(() -> converters.getNumberConverter().getShort(value, columnType)); }); } @@ -82,7 +82,7 @@ public int readInt() throws SQLException { return withNextValue( (value, fieldMetadata) -> { int columnType = ColumnTypeHelper.getColumnType(fieldMetadata.getType(), session); - return mapExceptions(() -> converters.getNumberConverter().getInt(value, columnType)); + return mapSFExceptionToSQLException(() -> converters.getNumberConverter().getInt(value, columnType)); }); } @@ -91,7 +91,7 @@ public long readLong() throws SQLException { return withNextValue( (value, fieldMetadata) -> { int columnType = ColumnTypeHelper.getColumnType(fieldMetadata.getType(), session); - return mapExceptions(() -> converters.getNumberConverter().getLong(value, columnType)); + return mapSFExceptionToSQLException(() -> converters.getNumberConverter().getLong(value, columnType)); }); } @@ -100,7 +100,7 @@ public float readFloat() throws SQLException { return withNextValue( (value, fieldMetadata) -> { int columnType = ColumnTypeHelper.getColumnType(fieldMetadata.getType(), session); - return mapExceptions(() -> converters.getNumberConverter().getFloat(value, columnType)); + return mapSFExceptionToSQLException(() -> converters.getNumberConverter().getFloat(value, columnType)); }); } @@ -109,7 +109,7 @@ public double readDouble() throws SQLException { return withNextValue( (value, fieldMetadata) -> { int columnType = ColumnTypeHelper.getColumnType(fieldMetadata.getType(), session); - return mapExceptions(() -> converters.getNumberConverter().getDouble(value, columnType)); + return mapSFExceptionToSQLException(() -> converters.getNumberConverter().getDouble(value, columnType)); }); } @@ -118,7 +118,7 @@ public BigDecimal readBigDecimal() throws SQLException { return withNextValue( (value, fieldMetadata) -> { int columnType = ColumnTypeHelper.getColumnType(fieldMetadata.getType(), session); - return mapExceptions( + return mapSFExceptionToSQLException( () -> converters.getNumberConverter().getBigDecimal(value, columnType)); }); } @@ -130,7 +130,7 @@ public byte[] readBytes() throws SQLException { int columnType = ColumnTypeHelper.getColumnType(fieldMetadata.getType(), session); int columnSubType = fieldMetadata.getType(); int scale = fieldMetadata.getScale(); - return mapExceptions( + return mapSFExceptionToSQLException( () -> converters.getBytesConverter().getBytes(value, columnType, columnSubType, scale)); }); @@ -140,7 +140,7 @@ public byte[] readBytes() throws SQLException { public Date readDate() throws SQLException { return withNextValue( (value, fieldMetadata) -> - mapExceptions( + mapSFExceptionToSQLException( () -> converters .getStructuredTypeDateTimeConverter() @@ -151,7 +151,7 @@ public Date readDate() throws SQLException { public Time readTime() throws SQLException { return withNextValue( (value, fieldMetadata) -> - mapExceptions( + mapSFExceptionToSQLException( () -> { int scale = fieldMetadata.getScale(); return converters @@ -168,7 +168,7 @@ public Timestamp readTimestamp(TimeZone tz) throws SQLException { return null; } int scale = fieldMetadata.getScale(); - return mapExceptions( + return mapSFExceptionToSQLException( () -> converters .getStructuredTypeDateTimeConverter() diff --git a/src/main/java/net/snowflake/client/jdbc/SnowflakeBaseResultSet.java b/src/main/java/net/snowflake/client/jdbc/SnowflakeBaseResultSet.java index d3e67d49f..1a4a1c82e 100644 --- a/src/main/java/net/snowflake/client/jdbc/SnowflakeBaseResultSet.java +++ b/src/main/java/net/snowflake/client/jdbc/SnowflakeBaseResultSet.java @@ -1406,7 +1406,7 @@ public T[] getArray(int columnIndex, Class type) throws SQLException { int counter = 0; for (Object value : objects) { if (SQLData.class.isAssignableFrom(type)) { - Map[] data = (Map[]) value; + Map data = (Map) value; SQLData instance = (SQLData) SQLDataCreationHelper.create(type); SQLInput sqlInput = new JsonSqlInput( @@ -1544,23 +1544,10 @@ public Map getMap(int columnIndex, Class type) throws SQLExcep Map map = OBJECT_MAPPER.convertValue(jsonNode, new TypeReference>() {}); Map resultMap = new HashMap<>(); - for (Map.Entry entry : map.entrySet()) { - SQLData instance = (SQLData) SQLDataCreationHelper.create(type); - SQLInput sqlInput = - new JsonSqlInput( - jsonNode.get(entry.getKey()), - session, - sfBaseResultSet.getConverters(), - sfBaseResultSet.getMetaData().getColumnMetadata().get(columnIndex - 1).getFields(), - sfBaseResultSet.getSessionTimezone()); - instance.readSQL(sqlInput, null); - resultMap.put(entry.getKey(), (T) instance); - if (SQLData.class.isAssignableFrom(type)) { SQLData instance = (SQLData) SQLDataCreationHelper.create(type); SQLInput sqlInput = - new JsonSqlInput( new JsonSqlInput( jsonNode.get(entry.getKey()), session,