Skip to content

Commit

Permalink
SNOW-1259709 - add mapping for basic types for arrays and maps
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-pmotacki committed Mar 25, 2024
1 parent f531d93 commit c91f0b1
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 37 deletions.
24 changes: 12 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.mapThrowingCallableExceptions;
import static net.snowflake.client.jdbc.SnowflakeUtil.mapSFExceptionToSQLException;

import com.fasterxml.jackson.databind.JsonNode;
import java.math.BigDecimal;
Expand Down Expand Up @@ -56,7 +56,7 @@ public String readString() throws SQLException {
int columnType = ColumnTypeHelper.getColumnType(fieldMetadata.getType(), session);
int columnSubType = fieldMetadata.getType();
int scale = fieldMetadata.getScale();
return mapThrowingCallableExceptions(
return mapSFExceptionToSQLException(
() ->
converters
.getStringConverter()
Expand All @@ -69,7 +69,7 @@ public boolean readBoolean() throws SQLException {
return withNextValue(
(value, jsonNode, fieldMetadata) -> {
int columnType = ColumnTypeHelper.getColumnType(fieldMetadata.getType(), session);
return mapThrowingCallableExceptions(
return mapSFExceptionToSQLException(
() -> converters.getBooleanConverter().getBoolean(value, columnType));
});
}
Expand All @@ -78,15 +78,15 @@ public boolean readBoolean() throws SQLException {
public byte readByte() throws SQLException {
return withNextValue(
(value, jsonNode, fieldMetadata) ->
mapThrowingCallableExceptions(() -> 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 mapThrowingCallableExceptions(
return mapSFExceptionToSQLException(
() -> converters.getNumberConverter().getShort(value, columnType));
});
}
Expand All @@ -96,7 +96,7 @@ public int readInt() throws SQLException {
return withNextValue(
(value, jsonNode, fieldMetadata) -> {
int columnType = ColumnTypeHelper.getColumnType(fieldMetadata.getType(), session);
return mapThrowingCallableExceptions(
return mapSFExceptionToSQLException(
() -> converters.getNumberConverter().getInt(value, columnType));
});
}
Expand All @@ -106,7 +106,7 @@ public long readLong() throws SQLException {
return withNextValue(
(value, jsonNode, fieldMetadata) -> {
int columnType = ColumnTypeHelper.getColumnType(fieldMetadata.getType(), session);
return mapThrowingCallableExceptions(
return mapSFExceptionToSQLException(
() -> converters.getNumberConverter().getLong(value, columnType));
});
}
Expand All @@ -116,7 +116,7 @@ public float readFloat() throws SQLException {
return withNextValue(
(value, jsonNode, fieldMetadata) -> {
int columnType = ColumnTypeHelper.getColumnType(fieldMetadata.getType(), session);
return mapThrowingCallableExceptions(
return mapSFExceptionToSQLException(
() -> converters.getNumberConverter().getFloat(value, columnType));
});
}
Expand All @@ -126,7 +126,7 @@ public double readDouble() throws SQLException {
return withNextValue(
(value, jsonNode, fieldMetadata) -> {
int columnType = ColumnTypeHelper.getColumnType(fieldMetadata.getType(), session);
return mapThrowingCallableExceptions(
return mapSFExceptionToSQLException(
() -> converters.getNumberConverter().getDouble(value, columnType));
});
}
Expand All @@ -136,7 +136,7 @@ public BigDecimal readBigDecimal() throws SQLException {
return withNextValue(
(value, jsonNode, fieldMetadata) -> {
int columnType = ColumnTypeHelper.getColumnType(fieldMetadata.getType(), session);
return mapThrowingCallableExceptions(
return mapSFExceptionToSQLException(
() -> converters.getNumberConverter().getBigDecimal(value, columnType));
});
}
Expand All @@ -148,7 +148,7 @@ public byte[] readBytes() throws SQLException {
int columnType = ColumnTypeHelper.getColumnType(fieldMetadata.getType(), session);
int columnSubType = fieldMetadata.getType();
int scale = fieldMetadata.getScale();
return mapThrowingCallableExceptions(
return mapSFExceptionToSQLException(
() ->
converters.getBytesConverter().getBytes(value, columnType, columnSubType, scale));
});
Expand Down Expand Up @@ -197,7 +197,7 @@ public Timestamp readTimestamp(TimeZone tz) throws SQLException {
if (result != null) {
return result;
}
return mapThrowingCallableExceptions(
return mapSFExceptionToSQLException(
() ->
converters
.getDateTimeConverter()
Expand Down
48 changes: 24 additions & 24 deletions src/main/java/net/snowflake/client/jdbc/SnowflakeBaseResultSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

package net.snowflake.client.jdbc;

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

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonNode;
Expand Down Expand Up @@ -1419,7 +1419,7 @@ public <T> T[] getArray(int columnIndex, Class<T> type) throws SQLException {
arr[counter++] = (T) instance;
} else if (String.class.isAssignableFrom(type)) {
arr[counter++] =
mapThrowingCallableExceptions(
mapSFExceptionToSQLException(
() ->
(T)
sfBaseResultSet
Expand All @@ -1428,7 +1428,7 @@ public <T> T[] getArray(int columnIndex, Class<T> type) throws SQLException {
.getString(value, columnType, columnSubType, scale));
} else if (Boolean.class.isAssignableFrom(type)) {
arr[counter++] =
mapThrowingCallableExceptions(
mapSFExceptionToSQLException(
() ->
(T)
sfBaseResultSet
Expand All @@ -1437,7 +1437,7 @@ public <T> T[] getArray(int columnIndex, Class<T> type) throws SQLException {
.getBoolean(value, columnType));
} else if (Byte.class.isAssignableFrom(type)) {
arr[counter++] =
mapThrowingCallableExceptions(
mapSFExceptionToSQLException(
() ->
(T)
sfBaseResultSet
Expand All @@ -1446,7 +1446,7 @@ public <T> T[] getArray(int columnIndex, Class<T> type) throws SQLException {
.getBytes(value, columnType, columnSubType, scale));
} else if (Short.class.isAssignableFrom(type)) {
arr[counter++] =
mapThrowingCallableExceptions(
mapSFExceptionToSQLException(
() ->
(T)
Short.valueOf(
Expand All @@ -1456,7 +1456,7 @@ public <T> T[] getArray(int columnIndex, Class<T> type) throws SQLException {
.getShort(value, columnType)));
} else if (Integer.class.isAssignableFrom(type)) {
arr[counter++] =
mapThrowingCallableExceptions(
mapSFExceptionToSQLException(
() ->
(T)
Integer.valueOf(
Expand All @@ -1466,7 +1466,7 @@ public <T> T[] getArray(int columnIndex, Class<T> type) throws SQLException {
.getInt(value, columnType)));
} else if (Long.class.isAssignableFrom(type)) {
arr[counter++] =
mapThrowingCallableExceptions(
mapSFExceptionToSQLException(
() ->
(T)
Long.valueOf(
Expand All @@ -1476,7 +1476,7 @@ public <T> T[] getArray(int columnIndex, Class<T> type) throws SQLException {
.getLong(value, columnType)));
} else if (Float.class.isAssignableFrom(type)) {
arr[counter++] =
mapThrowingCallableExceptions(
mapSFExceptionToSQLException(
() ->
(T)
Float.valueOf(
Expand All @@ -1486,7 +1486,7 @@ public <T> T[] getArray(int columnIndex, Class<T> type) throws SQLException {
.getFloat(value, columnType)));
} else if (Double.class.isAssignableFrom(type)) {
arr[counter++] =
mapThrowingCallableExceptions(
mapSFExceptionToSQLException(
() ->
(T)
Double.valueOf(
Expand All @@ -1496,7 +1496,7 @@ public <T> T[] getArray(int columnIndex, Class<T> type) throws SQLException {
.getDouble(value, columnType)));
} else if (Date.class.isAssignableFrom(type)) {
arr[counter++] =
mapThrowingCallableExceptions(
mapSFExceptionToSQLException(
() ->
(T)
sfBaseResultSet
Expand All @@ -1505,15 +1505,15 @@ public <T> T[] getArray(int columnIndex, Class<T> type) throws SQLException {
.getDate(value, columnType, columnSubType, tz, scale));
} else if (Time.class.isAssignableFrom(type)) {
arr[counter++] =
mapThrowingCallableExceptions(
mapSFExceptionToSQLException(
() ->
(T)
sfBaseResultSet
.getConverters()
.getDateTimeConverter()
.getTime(value, columnType, columnSubType, tz, scale));
} else if (Timestamp.class.isAssignableFrom(type)) {
mapThrowingCallableExceptions(
mapSFExceptionToSQLException(
() ->
(T)
sfBaseResultSet
Expand Down Expand Up @@ -1572,7 +1572,7 @@ public <T> Map<String, T> getMap(int columnIndex, Class<T> type) throws SQLExcep
} else if (String.class.isAssignableFrom(type)) {
resultMap.put(
entry.getKey(),
mapThrowingCallableExceptions(
mapSFExceptionToSQLException(
() ->
(T)
sfBaseResultSet
Expand All @@ -1582,7 +1582,7 @@ public <T> Map<String, T> getMap(int columnIndex, Class<T> type) throws SQLExcep
} else if (Boolean.class.isAssignableFrom(type)) {
resultMap.put(
entry.getKey(),
mapThrowingCallableExceptions(
mapSFExceptionToSQLException(
() ->
(T)
sfBaseResultSet
Expand All @@ -1592,7 +1592,7 @@ public <T> Map<String, T> getMap(int columnIndex, Class<T> type) throws SQLExcep
} else if (Byte.class.isAssignableFrom(type)) {
resultMap.put(
entry.getKey(),
mapThrowingCallableExceptions(
mapSFExceptionToSQLException(
() ->
(T)
sfBaseResultSet
Expand All @@ -1602,7 +1602,7 @@ public <T> Map<String, T> getMap(int columnIndex, Class<T> type) throws SQLExcep
} else if (Short.class.isAssignableFrom(type)) {
resultMap.put(
entry.getKey(),
mapThrowingCallableExceptions(
mapSFExceptionToSQLException(
() ->
(T)
(Short)
Expand All @@ -1613,7 +1613,7 @@ public <T> Map<String, T> getMap(int columnIndex, Class<T> type) throws SQLExcep
} else if (Integer.class.isAssignableFrom(type)) {
resultMap.put(
entry.getKey(),
mapThrowingCallableExceptions(
mapSFExceptionToSQLException(
() ->
(T)
(Integer)
Expand All @@ -1624,7 +1624,7 @@ public <T> Map<String, T> getMap(int columnIndex, Class<T> type) throws SQLExcep
} else if (Long.class.isAssignableFrom(type)) {
resultMap.put(
entry.getKey(),
mapThrowingCallableExceptions(
mapSFExceptionToSQLException(
() ->
(T)
(Long)
Expand All @@ -1635,7 +1635,7 @@ public <T> Map<String, T> getMap(int columnIndex, Class<T> type) throws SQLExcep
} else if (Float.class.isAssignableFrom(type)) {
resultMap.put(
entry.getKey(),
mapThrowingCallableExceptions(
mapSFExceptionToSQLException(
() ->
(T)
(Float)
Expand All @@ -1646,7 +1646,7 @@ public <T> Map<String, T> getMap(int columnIndex, Class<T> type) throws SQLExcep
} else if (Double.class.isAssignableFrom(type)) {
resultMap.put(
entry.getKey(),
mapThrowingCallableExceptions(
mapSFExceptionToSQLException(
() ->
(T)
(Double)
Expand All @@ -1657,7 +1657,7 @@ public <T> Map<String, T> getMap(int columnIndex, Class<T> type) throws SQLExcep
} else if (BigDecimal.class.isAssignableFrom(type)) {
resultMap.put(
entry.getKey(),
mapThrowingCallableExceptions(
mapSFExceptionToSQLException(
() ->
(T)
sfBaseResultSet
Expand All @@ -1667,7 +1667,7 @@ public <T> Map<String, T> getMap(int columnIndex, Class<T> type) throws SQLExcep
} else if (Date.class.isAssignableFrom(type)) {
resultMap.put(
entry.getKey(),
mapThrowingCallableExceptions(
mapSFExceptionToSQLException(
() ->
(T)
sfBaseResultSet
Expand All @@ -1677,7 +1677,7 @@ public <T> Map<String, T> getMap(int columnIndex, Class<T> type) throws SQLExcep
} else if (Time.class.isAssignableFrom(type)) {
resultMap.put(
entry.getKey(),
mapThrowingCallableExceptions(
mapSFExceptionToSQLException(
() ->
(T)
sfBaseResultSet
Expand All @@ -1687,7 +1687,7 @@ public <T> Map<String, T> getMap(int columnIndex, Class<T> type) throws SQLExcep
} else if (Timestamp.class.isAssignableFrom(type)) {
resultMap.put(
entry.getKey(),
mapThrowingCallableExceptions(
mapSFExceptionToSQLException(
() ->
(T)
sfBaseResultSet
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/snowflake/client/jdbc/SnowflakeUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,7 @@ public static boolean convertSystemPropertyToBooleanValue(
}

@SnowflakeJdbcInternalApi
public static <T> T mapThrowingCallableExceptions(ThrowingCallable<T, SFException> action)
public static <T> T mapSFExceptionToSQLException(ThrowingCallable<T, SFException> action)
throws SQLException {
try {
return action.call();
Expand Down

0 comments on commit c91f0b1

Please sign in to comment.