Skip to content

Commit

Permalink
Conflicts resolved
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-dheyman committed Mar 28, 2024
2 parents 73c0f05 + e4f2f94 commit 155aaf7
Show file tree
Hide file tree
Showing 12 changed files with 224 additions and 158 deletions.
31 changes: 18 additions & 13 deletions src/main/java/net/snowflake/client/core/ArrowSqlInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

package net.snowflake.client.core;

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

import java.math.BigDecimal;
import java.sql.Date;
import java.sql.SQLData;
Expand All @@ -20,12 +22,10 @@
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 {

private final JsonStringHashMap<String, Object> input;
private final JsonStringHashMap<String, Object> input;
private final Iterator<Object> structuredTypeFields;
private int currentIndex = 0;

Expand All @@ -36,11 +36,11 @@ public ArrowSqlInput(
List<FieldMetadata> fields) {
super(session, converters, fields);
this.structuredTypeFields = input.values().iterator();
this.input = input;
this.input = input;
}

public Map<String, Object> getInput() {
return input;
return input;
}

@Override
Expand Down Expand Up @@ -80,7 +80,8 @@ public short readShort() throws SQLException {
return withNextValue(
(value, fieldMetadata) -> {
int columnType = ColumnTypeHelper.getColumnType(fieldMetadata.getType(), session);
return mapSFExceptionToSQLException(() -> converters.getNumberConverter().getShort(value, columnType));
return mapSFExceptionToSQLException(
() -> converters.getNumberConverter().getShort(value, columnType));
});
}

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

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

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

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

Expand Down Expand Up @@ -174,8 +179,8 @@ public Timestamp readTimestamp(TimeZone tz) throws SQLException {
if (value == null) {
return null;
}
int columnType = ColumnTypeHelper.getColumnType(fieldMetadata.getType(), session);
int columnSubType = fieldMetadata.getType();
int columnType = ColumnTypeHelper.getColumnType(fieldMetadata.getType(), session);
int columnSubType = fieldMetadata.getType();
int scale = fieldMetadata.getScale();
return mapSFExceptionToSQLException(
() ->
Expand All @@ -184,7 +189,7 @@ public Timestamp readTimestamp(TimeZone tz) throws SQLException {
.getTimestamp(
(JsonStringHashMap<String, Object>) value,
columnType,
columnSubType,
columnSubType,
tz,
scale));
});
Expand Down
1 change: 0 additions & 1 deletion src/main/java/net/snowflake/client/core/JsonSqlInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
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
4 changes: 2 additions & 2 deletions src/main/java/net/snowflake/client/core/SFArrowResultSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ private Object createJsonSqlInput(int columnIndex, Object obj) throws SFExceptio
return new JsonSqlInput(
jsonNode,
session,
converters,
converters,
resultSetMetaData.getColumnMetadata().get(columnIndex - 1).getFields(),
sessionTimezone);
} catch (JsonProcessingException e) {
Expand All @@ -540,7 +540,7 @@ private Object createArrowSqlInput(int columnIndex, JsonStringHashMap<String, Ob
return new ArrowSqlInput(
input,
session,
converters,
converters,
resultSetMetaData.getColumnMetadata().get(columnIndex - 1).getFields());
}

Expand Down
38 changes: 20 additions & 18 deletions src/main/java/net/snowflake/client/core/arrow/MapConverter.java
Original file line number Diff line number Diff line change
@@ -1,31 +1,33 @@
package net.snowflake.client.core.arrow;

import java.util.List;
import java.util.stream.Collectors;
import net.snowflake.client.core.DataConversionContext;
import net.snowflake.client.core.SFException;
import net.snowflake.client.jdbc.SnowflakeType;
import org.apache.arrow.vector.complex.MapVector;
import org.apache.arrow.vector.util.JsonStringHashMap;

import java.util.List;
import java.util.stream.Collectors;

public class MapConverter extends AbstractArrowVectorConverter{
public class MapConverter extends AbstractArrowVectorConverter {

private final MapVector vector;
private final MapVector vector;

public MapConverter(MapVector valueVector, int columnIndex, DataConversionContext context) {
super(SnowflakeType.MAP.name(), valueVector, columnIndex, context);
this.vector = valueVector;
}
public MapConverter(MapVector valueVector, int columnIndex, DataConversionContext context) {
super(SnowflakeType.MAP.name(), valueVector, columnIndex, context);
this.vector = valueVector;
}

@Override
public Object toObject(int index) throws SFException {
List<JsonStringHashMap<String, Object>> entriesList = (List<JsonStringHashMap<String, Object>>) vector.getObject(index);
return entriesList.stream().collect(Collectors.toMap(entry-> entry.get("key").toString(), entry -> entry.get("value")));
}
@Override
public Object toObject(int index) throws SFException {
List<JsonStringHashMap<String, Object>> entriesList =
(List<JsonStringHashMap<String, Object>>) vector.getObject(index);
return entriesList.stream()
.collect(
Collectors.toMap(entry -> entry.get("key").toString(), entry -> entry.get("value")));
}

@Override
public String toString(int index) throws SFException {
return vector.getObject(index).toString();
}
@Override
public String toString(int index) throws SFException {
return vector.getObject(index).toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import net.snowflake.client.core.SFException;
import net.snowflake.client.core.SnowflakeJdbcInternalApi;
import net.snowflake.client.jdbc.ErrorCode;
import net.snowflake.client.jdbc.SnowflakeType;
import net.snowflake.client.jdbc.SnowflakeUtil;
import org.apache.arrow.vector.util.JsonStringHashMap;

Expand Down Expand Up @@ -47,23 +46,33 @@ public StructuredTypeDateTimeConverter(
}

public Timestamp getTimestamp(
JsonStringHashMap<String, Object> obj, int columnType, int columnSubType, TimeZone tz, int scale)
JsonStringHashMap<String, Object> obj,
int columnType,
int columnSubType,
TimeZone tz,
int scale)
throws SFException {
if (tz == null) {
tz = TimeZone.getDefault();
}
if ( Types.TIMESTAMP == columnType) {
if (Types.TIMESTAMP == columnType) {
if (SnowflakeUtil.EXTRA_TYPES_TIMESTAMP_LTZ == columnSubType) {
return convertTimestampLtz(obj, scale);
} else {
return convertTimestampNtz(obj, tz, scale);
}
} else if (Types.TIMESTAMP_WITH_TIMEZONE == columnType && SnowflakeUtil.EXTRA_TYPES_TIMESTAMP_TZ == columnSubType) {
} else if (Types.TIMESTAMP_WITH_TIMEZONE == columnType
&& SnowflakeUtil.EXTRA_TYPES_TIMESTAMP_TZ == columnSubType) {
return convertTimestampTz(obj, scale);
}
throw new SFException(
ErrorCode.INVALID_VALUE_CONVERT,
"Unexpected Arrow Field for columnType " + columnType + " , column subtype " + columnSubType + " , and object type " + obj.getClass());
"Unexpected Arrow Field for columnType "
+ columnType
+ " , column subtype "
+ columnSubType
+ " , and object type "
+ obj.getClass());
}

public Date getDate(int value, TimeZone tz) throws SFException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
@SnowflakeJdbcInternalApi
public class StructureTypeHelper {
private static final String STRUCTURED_TYPE_ENABLED_PROPERTY_NAME = "STRUCTURED_TYPE_ENABLED";
private static boolean structuredTypeEnabled = true;
private static boolean structuredTypeEnabled =
Boolean.valueOf(System.getProperty(STRUCTURED_TYPE_ENABLED_PROPERTY_NAME));

public static boolean isStructureTypeEnabled() {
return structuredTypeEnabled;
Expand Down
27 changes: 26 additions & 1 deletion src/main/java/net/snowflake/client/jdbc/ArrowResultChunk.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,32 @@
import net.snowflake.client.core.DataConversionContext;
import net.snowflake.client.core.SFBaseSession;
import net.snowflake.client.core.SFException;
import net.snowflake.client.core.arrow.*;
import net.snowflake.client.core.arrow.ArrowResultChunkIndexSorter;
import net.snowflake.client.core.arrow.ArrowVectorConverter;
import net.snowflake.client.core.arrow.BigIntToFixedConverter;
import net.snowflake.client.core.arrow.BigIntToScaledFixedConverter;
import net.snowflake.client.core.arrow.BigIntToTimeConverter;
import net.snowflake.client.core.arrow.BigIntToTimestampLTZConverter;
import net.snowflake.client.core.arrow.BigIntToTimestampNTZConverter;
import net.snowflake.client.core.arrow.BitToBooleanConverter;
import net.snowflake.client.core.arrow.DateConverter;
import net.snowflake.client.core.arrow.DecimalToScaledFixedConverter;
import net.snowflake.client.core.arrow.DoubleToRealConverter;
import net.snowflake.client.core.arrow.IntToFixedConverter;
import net.snowflake.client.core.arrow.IntToScaledFixedConverter;
import net.snowflake.client.core.arrow.IntToTimeConverter;
import net.snowflake.client.core.arrow.MapConverter;
import net.snowflake.client.core.arrow.SmallIntToFixedConverter;
import net.snowflake.client.core.arrow.SmallIntToScaledFixedConverter;
import net.snowflake.client.core.arrow.StructConverter;
import net.snowflake.client.core.arrow.ThreeFieldStructToTimestampTZConverter;
import net.snowflake.client.core.arrow.TinyIntToFixedConverter;
import net.snowflake.client.core.arrow.TinyIntToScaledFixedConverter;
import net.snowflake.client.core.arrow.TwoFieldStructToTimestampLTZConverter;
import net.snowflake.client.core.arrow.TwoFieldStructToTimestampNTZConverter;
import net.snowflake.client.core.arrow.TwoFieldStructToTimestampTZConverter;
import net.snowflake.client.core.arrow.VarBinaryToBinaryConverter;
import net.snowflake.client.core.arrow.VarCharConverter;
import net.snowflake.client.log.SFLogger;
import net.snowflake.client.log.SFLoggerFactory;
import net.snowflake.common.core.SqlState;
Expand Down
Loading

0 comments on commit 155aaf7

Please sign in to comment.