Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SNOW-1232333 - add mapping for basic types form arrays and maps #1679

Merged
merged 8 commits into from
Mar 27, 2024
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
35 changes: 23 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 All @@ -21,6 +21,7 @@
import net.snowflake.client.core.structs.SQLDataCreationHelper;
import net.snowflake.client.jdbc.FieldMetadata;
import net.snowflake.client.jdbc.SnowflakeLoggedFeatureNotSupportedException;
import net.snowflake.client.jdbc.SnowflakeUtil;
import net.snowflake.client.util.ThrowingTriFunction;
import net.snowflake.common.core.SFTimestamp;
import net.snowflake.common.core.SnowflakeDateTimeFormat;
Expand Down Expand Up @@ -55,7 +56,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 +69,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 +78,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 +96,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 +106,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 +116,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 +126,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 +136,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 +148,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 +176,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 +197,7 @@ public Timestamp readTimestamp(TimeZone tz) throws SQLException {
if (result != null) {
return result;
}
return mapExceptions(
return mapSFExceptionToSQLException(
() ->
converters
.getDateTimeConverter()
Expand Down
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
Loading