Skip to content

Commit

Permalink
adj decimal
Browse files Browse the repository at this point in the history
  • Loading branch information
feloxx committed Jan 17, 2024
1 parent 0b0d42b commit fa9e74f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.facebook.presto.common.type.CharType;
import com.facebook.presto.common.type.DateType;
import com.facebook.presto.common.type.DecimalType;
import com.facebook.presto.common.type.Decimals;
import com.facebook.presto.common.type.DoubleType;
import com.facebook.presto.common.type.IntegerType;
import com.facebook.presto.common.type.MapType;
Expand All @@ -48,7 +49,6 @@
import io.airlift.slice.Slice;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.time.Instant;
import java.time.ZoneId;
import java.util.ArrayList;
Expand Down Expand Up @@ -213,7 +213,7 @@ private Object getLiteralValue(Type type, Object prestoNativeValue) {
}

if (type instanceof TimeType) {
return Timestamp.fromEpochMillis((Long) prestoNativeValue);
return (int) ((long) prestoNativeValue / 1_000);
}

if (type instanceof TimestampType) {
Expand Down Expand Up @@ -248,7 +248,10 @@ private Object getLiteralValue(Type type, Object prestoNativeValue) {
BigDecimal.valueOf((long) prestoNativeValue)
.movePointLeft(decimalType.getScale());
} else {
bigDecimal = new BigDecimal((BigInteger) prestoNativeValue, decimalType.getScale());
bigDecimal =
new BigDecimal(
Decimals.decodeUnscaledValue((Slice) prestoNativeValue),
decimalType.getScale());
}
return Decimal.fromBigDecimal(
bigDecimal, decimalType.getPrecision(), decimalType.getScale());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,9 @@ public void testDecimalPredicate() throws Exception {
assertThat(sql("SELECT c2 FROM paimon.default.test_decimal where c2 = 123.456"))
.isEqualTo("[[123.456]]");

assertThat(sql("SELECT c1 FROM paimon.default.test_decimal where c1 = 10000000000"))
.isEqualTo("[[10000000000]]");

// Test gt and gte.
assertThat(sql("SELECT c2 FROM paimon.default.test_decimal where c2 > 123"))
.isEqualTo("[[123.456]]");
Expand All @@ -443,6 +446,9 @@ public void testDecimalPredicate() throws Exception {
assertThat(sql("SELECT c2 FROM paimon.default.test_decimal where c2 >= 123.456"))
.isEqualTo("[[123.456]]");

assertThat(sql("SELECT c1 FROM paimon.default.test_decimal where c1 >= 10000000000"))
.isEqualTo("[[10000000000]]");

// Test lt and lte.
assertThat(sql("SELECT c2 FROM paimon.default.test_decimal where c2 < 124"))
.isEqualTo("[[123.456]]");
Expand All @@ -456,6 +462,9 @@ public void testDecimalPredicate() throws Exception {
assertThat(sql("SELECT c2 FROM paimon.default.test_decimal where c2 <= 123.457"))
.isEqualTo("[[123.456]]");

assertThat(sql("SELECT c1 FROM paimon.default.test_decimal where c1 <= 10000000000"))
.isEqualTo("[[10000000000]]");

// Test gt and lt.
assertThat(sql("SELECT c2 FROM paimon.default.test_decimal where c2 > 123 and c2 < 666"))
.isEqualTo("[[123.456]]");
Expand All @@ -471,6 +480,11 @@ public void testDecimalPredicate() throws Exception {
// Test gte and lt.
assertThat(sql("SELECT c2 FROM paimon.default.test_decimal where c2 >= 123 and c2 < 666"))
.isEqualTo("[[123.456]]");

assertThat(
sql(
"SELECT c1 FROM paimon.default.test_decimal where c1 >= 10000000000 and c1 < 10000000001"))
.isEqualTo("[[10000000000]]");
}

private String sql(String sql) throws Exception {
Expand Down

0 comments on commit fa9e74f

Please sign in to comment.