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 c91f0b1 commit baf98e9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 29 deletions.
30 changes: 15 additions & 15 deletions src/main/java/net/snowflake/client/core/ArrowSqlInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {

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

Expand All @@ -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));
});
}

Expand All @@ -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));
});
}

Expand All @@ -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));
});
}

Expand All @@ -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));
});
}
Expand All @@ -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));
});
Expand All @@ -140,7 +140,7 @@ public byte[] readBytes() throws SQLException {
public Date readDate() throws SQLException {
return withNextValue(
(value, fieldMetadata) ->
mapExceptions(
mapSFExceptionToSQLException(
() ->
converters
.getStructuredTypeDateTimeConverter()
Expand All @@ -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
Expand All @@ -168,7 +168,7 @@ public Timestamp readTimestamp(TimeZone tz) throws SQLException {
return null;
}
int scale = fieldMetadata.getScale();
return mapExceptions(
return mapSFExceptionToSQLException(
() ->
converters
.getStructuredTypeDateTimeConverter()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1406,7 +1406,7 @@ public <T> T[] getArray(int columnIndex, Class<T> 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(
Expand Down Expand Up @@ -1544,23 +1544,10 @@ public <T> Map<String, T> getMap(int columnIndex, Class<T> type) throws SQLExcep
Map<String, Object> map =
OBJECT_MAPPER.convertValue(jsonNode, new TypeReference<Map<String, Object>>() {});
Map<String, T> resultMap = new HashMap<>();

for (Map.Entry<String, Object> 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,
Expand Down

0 comments on commit baf98e9

Please sign in to comment.