This is an automated email from the ASF dual-hosted git repository.
lzljs3620320 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-paimon-presto.git
The following commit(s) were added to refs/heads/main by this push:
new cb4feaf Fix long decimal error (#29)
cb4feaf is described below
commit cb4feafe23195a500af6e659c07c865f6d5a8ce1
Author: humengyu <[email protected]>
AuthorDate: Thu Dec 7 21:19:09 2023 +0800
Fix long decimal error (#29)
---
.../apache/paimon/presto/PrestoPageSourceBase.java | 2 +-
.../org/apache/paimon/presto/TestPrestoITCase.java | 35 ++++++++++++++++++++++
2 files changed, 36 insertions(+), 1 deletion(-)
diff --git
a/paimon-presto-common/src/main/java/org/apache/paimon/presto/PrestoPageSourceBase.java
b/paimon-presto-common/src/main/java/org/apache/paimon/presto/PrestoPageSourceBase.java
index 98218b7..8df72fb 100644
---
a/paimon-presto-common/src/main/java/org/apache/paimon/presto/PrestoPageSourceBase.java
+++
b/paimon-presto-common/src/main/java/org/apache/paimon/presto/PrestoPageSourceBase.java
@@ -245,7 +245,7 @@ public abstract class PrestoPageSourceBase implements
ConnectorPageSource {
Verify.verify(isLongDecimal(type), "The type should be long
decimal");
DecimalType decimalType = (DecimalType) type;
BigDecimal decimal = ((Decimal) value).toBigDecimal();
- type.writeObject(output, Decimals.encodeScaledValue(decimal,
decimalType.getScale()));
+ type.writeSlice(output, Decimals.encodeScaledValue(decimal,
decimalType.getScale()));
} else {
throw new PrestoException(
GENERIC_INTERNAL_ERROR,
diff --git
a/paimon-presto-common/src/test/java/org/apache/paimon/presto/TestPrestoITCase.java
b/paimon-presto-common/src/test/java/org/apache/paimon/presto/TestPrestoITCase.java
index 7812ca8..b740e6c 100644
---
a/paimon-presto-common/src/test/java/org/apache/paimon/presto/TestPrestoITCase.java
+++
b/paimon-presto-common/src/test/java/org/apache/paimon/presto/TestPrestoITCase.java
@@ -18,6 +18,7 @@
package org.apache.paimon.presto;
+import org.apache.paimon.data.Decimal;
import org.apache.paimon.data.GenericMap;
import org.apache.paimon.data.GenericRow;
import org.apache.paimon.data.Timestamp;
@@ -32,6 +33,7 @@ import org.apache.paimon.table.sink.InnerTableWrite;
import org.apache.paimon.types.BigIntType;
import org.apache.paimon.types.CharType;
import org.apache.paimon.types.DataField;
+import org.apache.paimon.types.DecimalType;
import org.apache.paimon.types.IntType;
import org.apache.paimon.types.MapType;
import org.apache.paimon.types.RowKind;
@@ -45,6 +47,7 @@ import com.facebook.presto.tests.DistributedQueryRunner;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
+import java.math.BigDecimal;
import java.nio.file.Files;
import java.time.LocalDateTime;
import java.util.Arrays;
@@ -174,6 +177,32 @@ public class TestPrestoITCase {
commit.commit(0, writer.prepareCommit(true, 0));
}
+ {
+ // test for decimal
+ Path tablePath5 = new Path(warehouse, "default.db/test_decimal");
+ RowType rowType =
+ new RowType(
+ Arrays.asList(
+ new DataField(0, "c1", new DecimalType(20,
0)),
+ new DataField(1, "c2", new DecimalType(6,
3))));
+ new SchemaManager(LocalFileIO.create(), tablePath5)
+ .createTable(
+ new Schema(
+ rowType.getFields(),
+ Collections.emptyList(),
+ Arrays.asList("c1", "c2"),
+ new HashMap<>(),
+ ""));
+ FileStoreTable table =
FileStoreTableFactory.create(LocalFileIO.create(), tablePath5);
+ InnerTableWrite writer = table.newWrite("user");
+ InnerTableCommit commit = table.newCommit("user");
+ writer.write(
+ GenericRow.of(
+ Decimal.fromBigDecimal(new
BigDecimal("10000000000"), 20, 0),
+ Decimal.fromBigDecimal(new BigDecimal("123.456"),
6, 3)));
+ commit.commit(0, writer.prepareCommit(true, 0));
+ }
+
DistributedQueryRunner queryRunner = null;
try {
queryRunner =
@@ -258,6 +287,12 @@ public class TestPrestoITCase {
.isEqualTo("[[2023-01-01T01:01:01.123]]");
}
+ @Test
+ public void testDecimal() throws Exception {
+ assertThat(sql("SELECT c1, c2 FROM paimon.default.test_decimal"))
+ .isEqualTo("[[10000000000, 123.456]]");
+ }
+
private String sql(String sql) throws Exception {
MaterializedResult result = queryRunner.execute(sql);
return result.getMaterializedRows().toString();