Skip to content

Commit

Permalink
SNOW-1232333 - add mapping for basic types form arrays and maps (#1679)
Browse files Browse the repository at this point in the history
* SNOW-1259709 - add mapping for basic types for arrays and maps
  • Loading branch information
sfc-gh-pmotacki authored Mar 27, 2024
1 parent 63b654d commit 7d7b16c
Show file tree
Hide file tree
Showing 6 changed files with 388 additions and 54 deletions.
33 changes: 19 additions & 14 deletions src/main/java/net/snowflake/client/core/ArrowSqlInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

package net.snowflake.client.core;

import static net.snowflake.client.jdbc.SnowflakeUtil.mapExceptions;
import static net.snowflake.client.jdbc.SnowflakeUtil.mapSFExceptionToSQLException;

import java.math.BigDecimal;
import java.sql.Date;
Expand Down Expand Up @@ -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()
Expand All @@ -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));
});
}
Expand All @@ -65,15 +65,16 @@ 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
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));
});
}

Expand All @@ -82,7 +83,8 @@ 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));
});
}

Expand All @@ -91,7 +93,8 @@ 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));
});
}

Expand All @@ -100,7 +103,8 @@ 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));
});
}

Expand All @@ -109,7 +113,8 @@ 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));
});
}

Expand All @@ -118,7 +123,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));
});
}
Expand All @@ -130,7 +135,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));
});
Expand All @@ -140,7 +145,7 @@ public byte[] readBytes() throws SQLException {
public Date readDate() throws SQLException {
return withNextValue(
(value, fieldMetadata) ->
mapExceptions(
mapSFExceptionToSQLException(
() ->
converters
.getStructuredTypeDateTimeConverter()
Expand All @@ -151,7 +156,7 @@ public Date readDate() throws SQLException {
public Time readTime() throws SQLException {
return withNextValue(
(value, fieldMetadata) ->
mapExceptions(
mapSFExceptionToSQLException(
() -> {
int scale = fieldMetadata.getScale();
return converters
Expand All @@ -168,7 +173,7 @@ public Timestamp readTimestamp(TimeZone tz) throws SQLException {
return null;
}
int scale = fieldMetadata.getScale();
return mapExceptions(
return mapSFExceptionToSQLException(
() ->
converters
.getStructuredTypeDateTimeConverter()
Expand Down
34 changes: 22 additions & 12 deletions src/main/java/net/snowflake/client/core/JsonSqlInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
package net.snowflake.client.core;

import static net.snowflake.client.jdbc.SnowflakeUtil.mapExceptions;
import static net.snowflake.client.jdbc.SnowflakeUtil.mapSFExceptionToSQLException;

import com.fasterxml.jackson.databind.JsonNode;
import java.math.BigDecimal;
Expand Down Expand Up @@ -55,7 +55,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()
Expand All @@ -68,7 +68,7 @@ public boolean readBoolean() throws SQLException {
return withNextValue(
(value, jsonNode, fieldMetadata) -> {
int columnType = ColumnTypeHelper.getColumnType(fieldMetadata.getType(), session);
return mapExceptions(
return mapSFExceptionToSQLException(
() -> converters.getBooleanConverter().getBoolean(value, columnType));
});
}
Expand All @@ -77,15 +77,16 @@ public boolean readBoolean() throws SQLException {
public byte readByte() throws SQLException {
return withNextValue(
(value, jsonNode, fieldMetadata) ->
mapExceptions(() -> converters.getNumberConverter().getByte(value)));
mapSFExceptionToSQLException(() -> converters.getNumberConverter().getByte(value)));
}

@Override
public short readShort() throws SQLException {
return withNextValue(
(value, jsonNode, fieldMetadata) -> {
int columnType = ColumnTypeHelper.getColumnType(fieldMetadata.getType(), session);
return mapExceptions(() -> converters.getNumberConverter().getShort(value, columnType));
return mapSFExceptionToSQLException(
() -> converters.getNumberConverter().getShort(value, columnType));
});
}

Expand All @@ -94,7 +95,8 @@ public int readInt() throws SQLException {
return withNextValue(
(value, jsonNode, fieldMetadata) -> {
int columnType = ColumnTypeHelper.getColumnType(fieldMetadata.getType(), session);
return mapExceptions(() -> converters.getNumberConverter().getInt(value, columnType));
return mapSFExceptionToSQLException(
() -> converters.getNumberConverter().getInt(value, columnType));
});
}

Expand All @@ -103,7 +105,8 @@ public long readLong() throws SQLException {
return withNextValue(
(value, jsonNode, fieldMetadata) -> {
int columnType = ColumnTypeHelper.getColumnType(fieldMetadata.getType(), session);
return mapExceptions(() -> converters.getNumberConverter().getLong(value, columnType));
return mapSFExceptionToSQLException(
() -> converters.getNumberConverter().getLong(value, columnType));
});
}

Expand All @@ -112,7 +115,8 @@ public float readFloat() throws SQLException {
return withNextValue(
(value, jsonNode, fieldMetadata) -> {
int columnType = ColumnTypeHelper.getColumnType(fieldMetadata.getType(), session);
return mapExceptions(() -> converters.getNumberConverter().getFloat(value, columnType));
return mapSFExceptionToSQLException(
() -> converters.getNumberConverter().getFloat(value, columnType));
});
}

Expand All @@ -121,7 +125,8 @@ public double readDouble() throws SQLException {
return withNextValue(
(value, jsonNode, fieldMetadata) -> {
int columnType = ColumnTypeHelper.getColumnType(fieldMetadata.getType(), session);
return mapExceptions(() -> converters.getNumberConverter().getDouble(value, columnType));
return mapSFExceptionToSQLException(
() -> converters.getNumberConverter().getDouble(value, columnType));
});
}

Expand All @@ -130,7 +135,7 @@ public BigDecimal readBigDecimal() throws SQLException {
return withNextValue(
(value, jsonNode, fieldMetadata) -> {
int columnType = ColumnTypeHelper.getColumnType(fieldMetadata.getType(), session);
return mapExceptions(
return mapSFExceptionToSQLException(
() -> converters.getNumberConverter().getBigDecimal(value, columnType));
});
}
Expand All @@ -142,7 +147,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));
});
Expand Down Expand Up @@ -170,6 +175,11 @@ public Time readTime() throws SQLException {
});
}

@Override
public Timestamp readTimestamp() throws SQLException {
return readTimestamp(null);
}

@Override
public Timestamp readTimestamp(TimeZone tz) throws SQLException {
return withNextValue(
Expand All @@ -186,7 +196,7 @@ public Timestamp readTimestamp(TimeZone tz) throws SQLException {
if (result != null) {
return result;
}
return mapExceptions(
return mapSFExceptionToSQLException(
() ->
converters
.getDateTimeConverter()
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/net/snowflake/client/core/SFBaseResultSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -208,4 +208,9 @@ public Converters getConverters() {
logger.debug("Json converters weren't created");
return null;
}

@SnowflakeJdbcInternalApi
public TimeZone getSessionTimeZone() {
return resultSetSerializable.getTimeZone();
}
}
Loading

0 comments on commit 7d7b16c

Please sign in to comment.