Skip to content

Commit

Permalink
SNOW-1170182: Simplify condition returning decimal in ARROW
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-dprzybysz committed Mar 18, 2024
1 parent f279079 commit 9851856
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import java.sql.Timestamp;
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.SnowflakeUtil;
Expand Down Expand Up @@ -39,6 +38,8 @@ abstract class AbstractArrowVectorConverter implements ArrowVectorConverter {

protected TimeZone sessionTimeZone;

private boolean shouldTreatDecimalAsInt;

/** Field names of the struct vectors used by timestamp */
public static final String FIELD_NAME_EPOCH = "epoch"; // seconds since epoch

Expand All @@ -54,6 +55,11 @@ abstract class AbstractArrowVectorConverter implements ArrowVectorConverter {
this.valueVector = valueVector;
this.columnIndex = vectorIndex + 1;
this.context = context;
this.shouldTreatDecimalAsInt =
context == null
|| context.getSession() == null
|| context.getSession().isJdbcArrowTreatDecimalAsInt()
|| context.getSession().isJdbcTreatDecimalAsInt();
}

@Override
Expand Down Expand Up @@ -147,13 +153,8 @@ public BigDecimal toBigDecimal(int index) throws SFException {
ErrorCode.INVALID_VALUE_CONVERT, logicalTypeStr, SnowflakeUtil.BIG_DECIMAL_STR, "");
}

public boolean shouldTreatDecimalAsInt(SFBaseSession session) {
if (session != null) {
if (!session.isJdbcArrowTreatDecimalAsInt() && !session.isJdbcTreatDecimalAsInt()) {
return false;
}
}
return true;
boolean shouldTreatDecimalAsInt() {
return shouldTreatDecimalAsInt;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public BigDecimal toBigDecimal(int index) {
public Object toObject(int index) throws SFException {
if (bigIntVector.isNull(index)) {
return null;
} else if (!shouldTreatDecimalAsInt(context.getSession())) {
} else if (!shouldTreatDecimalAsInt()) {
return BigDecimal.valueOf(getLong(index), sfScale);
}
return getLong(index);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public BigDecimal toBigDecimal(int index) throws SFException {
public Object toObject(int index) throws SFException {
if (isNull(index)) {
return null;
} else if (!shouldTreatDecimalAsInt(context.getSession())) {
} else if (!shouldTreatDecimalAsInt()) {
return BigDecimal.valueOf((long) getInt(index), sfScale);
}
return (long) getInt(index);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public double toDouble(int index) throws SFException {
public Object toObject(int index) throws SFException {
if (isNull(index)) {
return null;
} else if (!shouldTreatDecimalAsInt(context.getSession())) {
} else if (!shouldTreatDecimalAsInt()) {
return BigDecimal.valueOf((long) getShort(index), sfScale);
}
return (long) getShort(index);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public BigDecimal toBigDecimal(int index) throws SFException {
public Object toObject(int index) throws SFException {
if (isNull(index)) {
return null;
} else if (!shouldTreatDecimalAsInt(context.getSession())) {
} else if (!shouldTreatDecimalAsInt()) {
return BigDecimal.valueOf((long) getByte(index), sfScale);
}
return (long) toByte(index);
Expand Down

0 comments on commit 9851856

Please sign in to comment.