Skip to content

Commit

Permalink
Merge branch 'master' into SNOW-1567156-bump-bouncy-castle-dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-mkubik authored Sep 30, 2024
2 parents d3294ba + bbc848c commit 7539767
Show file tree
Hide file tree
Showing 26 changed files with 694 additions and 308 deletions.
4 changes: 2 additions & 2 deletions FIPS/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
<parent>
<groupId>net.snowflake</groupId>
<artifactId>snowflake-jdbc-parent</artifactId>
<version>3.19.0</version>
<version>3.19.1-SNAPSHOT</version>
<relativePath>../parent-pom.xml</relativePath>
</parent>

<artifactId>snowflake-jdbc-fips</artifactId>
<version>3.19.0</version>
<version>3.19.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>snowflake-jdbc-fips</name>
Expand Down
2 changes: 2 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ timestamps {
}.collectEntries { jobDefinition ->
return [(jobDefinition.runName): { build job: jobDefinition.jobToRun, parameters: jobDefinition.params }]
}

jobDefinitions.put('JDBC-AIX-Unit', { build job: 'JDBC-AIX-UnitTests', parameters: [ string(name: 'BRANCH', value: scmInfo.GIT_BRANCH ) ] } )
stage('Test') {
parallel (jobDefinitions)
}
Expand Down
2 changes: 1 addition & 1 deletion parent-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>net.snowflake</groupId>
<artifactId>snowflake-jdbc-parent</artifactId>
<version>3.19.0</version>
<version>3.19.1-SNAPSHOT</version>
<packaging>pom</packaging>

<modules>
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
<parent>
<groupId>net.snowflake</groupId>
<artifactId>snowflake-jdbc-parent</artifactId>
<version>3.19.0</version>
<version>3.19.1-SNAPSHOT</version>
<relativePath>./parent-pom.xml</relativePath>
</parent>

<!-- Maven complains about using property here, but it makes install and deploy process easier to override final package names and localization -->
<artifactId>${artifactId}</artifactId>
<version>3.19.0</version>
<version>3.19.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>${artifactId}</name>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/snowflake/client/core/ResultUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ public static String getSFTimeAsString(
* @return boolean in string
*/
public static String getBooleanAsString(boolean bool) {
return bool ? "TRUE" : "FALSE";
return bool ? "true" : "false";
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

import net.snowflake.client.core.DataConversionContext;
import net.snowflake.client.core.SFException;
import net.snowflake.client.core.arrow.tostringhelpers.ArrowArrayStringRepresentationBuilder;
import net.snowflake.client.jdbc.SnowflakeSQLException;
import net.snowflake.client.jdbc.SnowflakeType;
import org.apache.arrow.vector.FieldVector;
import org.apache.arrow.vector.complex.ListVector;

public class ArrayConverter extends AbstractArrowVectorConverter {
Expand All @@ -21,6 +24,25 @@ public Object toObject(int index) throws SFException {

@Override
public String toString(int index) throws SFException {
return vector.getObject(index).toString();
FieldVector vectorUnpacked = vector.getChildrenFromFields().get(0);
SnowflakeType logicalType =
ArrowVectorConverterUtil.getSnowflakeTypeFromFieldMetadata(vectorUnpacked.getField());

ArrowArrayStringRepresentationBuilder builder =
new ArrowArrayStringRepresentationBuilder(logicalType);

final ArrowVectorConverter converter;

try {
converter = ArrowVectorConverterUtil.initConverter(vectorUnpacked, context, columnIndex);
} catch (SnowflakeSQLException e) {
return vector.getObject(index).toString();
}

for (int i = vector.getElementStartIndex(index); i < vector.getElementEndIndex(index); i++) {
builder.appendValue(converter.toString(i));
}

return builder.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,8 @@
import java.sql.Date;
import java.sql.Time;
import java.sql.Timestamp;
import java.util.Map;
import java.util.TimeZone;
import net.snowflake.client.core.DataConversionContext;
import net.snowflake.client.core.SFBaseSession;
import net.snowflake.client.core.SFException;
import net.snowflake.client.jdbc.ErrorCode;
import net.snowflake.client.jdbc.SnowflakeSQLException;
import net.snowflake.client.jdbc.SnowflakeSQLLoggedException;
import net.snowflake.client.jdbc.SnowflakeType;
import net.snowflake.common.core.SqlState;
import org.apache.arrow.vector.ValueVector;
import org.apache.arrow.vector.complex.FixedSizeListVector;
import org.apache.arrow.vector.complex.ListVector;
import org.apache.arrow.vector.complex.MapVector;
import org.apache.arrow.vector.complex.StructVector;
import org.apache.arrow.vector.types.Types;

/** Interface to convert from arrow vector values into java data types. */
public interface ArrowVectorConverter {
Expand Down Expand Up @@ -177,201 +163,4 @@ public interface ArrowVectorConverter {
* @param isUTC true or false value of whether NTZ timestamp should be set to UTC
*/
void setTreatNTZAsUTC(boolean isUTC);

/**
* Given an arrow vector (a single column in a single record batch), return an arrow vector
* converter. Note, converter is built on top of arrow vector, so that arrow data can be converted
* back to java data
*
* <p>
*
* <p>Arrow converter mappings for Snowflake fixed-point numbers
* ----------------------------------------------------------------------------------------- Max
* position and scale Converter
* -----------------------------------------------------------------------------------------
* number(3,0) {@link TinyIntToFixedConverter} number(3,2) {@link TinyIntToScaledFixedConverter}
* number(5,0) {@link SmallIntToFixedConverter} number(5,4) {@link SmallIntToScaledFixedConverter}
* number(10,0) {@link IntToFixedConverter} number(10,9) {@link IntToScaledFixedConverter}
* number(19,0) {@link BigIntToFixedConverter} number(19,18) {@link BigIntToFixedConverter}
* number(38,37) {@link DecimalToScaledFixedConverter}
* ------------------------------------------------------------------------------------------
*
* @param vector an arrow vector
* @param context data conversion context
* @param session SFBaseSession for purposes of logging
* @param idx the index of the vector in its batch
* @return A converter on top og the vector
*/
static ArrowVectorConverter initConverter(
ValueVector vector, DataConversionContext context, SFBaseSession session, int idx)
throws SnowflakeSQLException {
// arrow minor type
Types.MinorType type = Types.getMinorTypeForArrowType(vector.getField().getType());

// each column's metadata
Map<String, String> customMeta = vector.getField().getMetadata();
if (type == Types.MinorType.DECIMAL) {
// Note: Decimal vector is different from others
return new DecimalToScaledFixedConverter(vector, idx, context);
} else if (!customMeta.isEmpty()) {
SnowflakeType st = SnowflakeType.valueOf(customMeta.get("logicalType"));
switch (st) {
case ANY:
case CHAR:
case TEXT:
case VARIANT:
return new VarCharConverter(vector, idx, context);

case MAP:
if (vector instanceof MapVector) {
return new MapConverter((MapVector) vector, idx, context);
} else {
return new VarCharConverter(vector, idx, context);
}

case VECTOR:
return new VectorTypeConverter((FixedSizeListVector) vector, idx, context);

case ARRAY:
if (vector instanceof ListVector) {
return new ArrayConverter((ListVector) vector, idx, context);
} else {
return new VarCharConverter(vector, idx, context);
}

case OBJECT:
if (vector instanceof StructVector) {
return new StructConverter((StructVector) vector, idx, context);
} else {
return new VarCharConverter(vector, idx, context);
}

case BINARY:
return new VarBinaryToBinaryConverter(vector, idx, context);

case BOOLEAN:
return new BitToBooleanConverter(vector, idx, context);

case DATE:
boolean getFormatDateWithTimeZone = false;
if (context.getSession() != null) {
getFormatDateWithTimeZone = context.getSession().getFormatDateWithTimezone();
}
return new DateConverter(vector, idx, context, getFormatDateWithTimeZone);

case FIXED:
String scaleStr = vector.getField().getMetadata().get("scale");
int sfScale = Integer.parseInt(scaleStr);
switch (type) {
case TINYINT:
if (sfScale == 0) {
return new TinyIntToFixedConverter(vector, idx, context);
} else {
return new TinyIntToScaledFixedConverter(vector, idx, context, sfScale);
}
case SMALLINT:
if (sfScale == 0) {
return new SmallIntToFixedConverter(vector, idx, context);
} else {
return new SmallIntToScaledFixedConverter(vector, idx, context, sfScale);
}
case INT:
if (sfScale == 0) {
return new IntToFixedConverter(vector, idx, context);
} else {
return new IntToScaledFixedConverter(vector, idx, context, sfScale);
}
case BIGINT:
if (sfScale == 0) {
return new BigIntToFixedConverter(vector, idx, context);
} else {
return new BigIntToScaledFixedConverter(vector, idx, context, sfScale);
}
}
break;

case REAL:
return new DoubleToRealConverter(vector, idx, context);

case TIME:
switch (type) {
case INT:
return new IntToTimeConverter(vector, idx, context);
case BIGINT:
return new BigIntToTimeConverter(vector, idx, context);
default:
throw new SnowflakeSQLLoggedException(
session,
ErrorCode.INTERNAL_ERROR.getMessageCode(),
SqlState.INTERNAL_ERROR,
"Unexpected Arrow Field for ",
st.name());
}

case TIMESTAMP_LTZ:
if (vector.getField().getChildren().isEmpty()) {
// case when the scale of the timestamp is equal or smaller than millisecs since epoch
return new BigIntToTimestampLTZConverter(vector, idx, context);
} else if (vector.getField().getChildren().size() == 2) {
// case when the scale of the timestamp is larger than millisecs since epoch, e.g.,
// nanosecs
return new TwoFieldStructToTimestampLTZConverter(vector, idx, context);
} else {
throw new SnowflakeSQLLoggedException(
session,
ErrorCode.INTERNAL_ERROR.getMessageCode(),
SqlState.INTERNAL_ERROR,
"Unexpected Arrow Field for ",
st.name());
}

case TIMESTAMP_NTZ:
if (vector.getField().getChildren().isEmpty()) {
// case when the scale of the timestamp is equal or smaller than 7
return new BigIntToTimestampNTZConverter(vector, idx, context);
} else if (vector.getField().getChildren().size() == 2) {
// when the timestamp is represent in two-field struct
return new TwoFieldStructToTimestampNTZConverter(vector, idx, context);
} else {
throw new SnowflakeSQLLoggedException(
session,
ErrorCode.INTERNAL_ERROR.getMessageCode(),
SqlState.INTERNAL_ERROR,
"Unexpected Arrow Field for ",
st.name());
}

case TIMESTAMP_TZ:
if (vector.getField().getChildren().size() == 2) {
// case when the scale of the timestamp is equal or smaller than millisecs since epoch
return new TwoFieldStructToTimestampTZConverter(vector, idx, context);
} else if (vector.getField().getChildren().size() == 3) {
// case when the scale of the timestamp is larger than millisecs since epoch, e.g.,
// nanosecs
return new ThreeFieldStructToTimestampTZConverter(vector, idx, context);
} else {
throw new SnowflakeSQLLoggedException(
session,
ErrorCode.INTERNAL_ERROR.getMessageCode(),
SqlState.INTERNAL_ERROR,
"Unexpected SnowflakeType ",
st.name());
}

default:
throw new SnowflakeSQLLoggedException(
session,
ErrorCode.INTERNAL_ERROR.getMessageCode(),
SqlState.INTERNAL_ERROR,
"Unexpected Arrow Field for ",
st.name());
}
}
throw new SnowflakeSQLLoggedException(
session,
ErrorCode.INTERNAL_ERROR.getMessageCode(),
SqlState.INTERNAL_ERROR,
"Unexpected Arrow Field for ",
type.toString());
}
}
Loading

0 comments on commit 7539767

Please sign in to comment.