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-1170182: Simplify condition returning decimal in ARROW #1672

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading