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 92c71cf Fix timestamp format (#20)
92c71cf is described below
commit 92c71cf1ec3c21a2254aaefe111585c5e017cb40
Author: humengyu <[email protected]>
AuthorDate: Mon Nov 27 13:25:35 2023 +0800
Fix timestamp format (#20)
---
.../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 a99e886..98218b7 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
@@ -206,7 +206,7 @@ public abstract class PrestoPageSourceBase implements
ConnectorPageSource {
prestoType.writeLong(
output, encodeShortScaledValue(decimal,
decimalType.getScale()));
} else if (prestoType.equals(TIMESTAMP)) {
- prestoType.writeLong(output, ((Timestamp)
value).getMillisecond() * 1_000);
+ prestoType.writeLong(output, ((Timestamp)
value).toSQLTimestamp().getTime());
} else if (prestoType.equals(TIME)) {
prestoType.writeLong(output, (int) value * 1_000);
} else {
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 aa409f8..7812ca8 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
@@ -20,6 +20,7 @@ package org.apache.paimon.presto;
import org.apache.paimon.data.GenericMap;
import org.apache.paimon.data.GenericRow;
+import org.apache.paimon.data.Timestamp;
import org.apache.paimon.fs.Path;
import org.apache.paimon.fs.local.LocalFileIO;
import org.apache.paimon.schema.Schema;
@@ -35,6 +36,7 @@ import org.apache.paimon.types.IntType;
import org.apache.paimon.types.MapType;
import org.apache.paimon.types.RowKind;
import org.apache.paimon.types.RowType;
+import org.apache.paimon.types.TimestampType;
import org.apache.paimon.types.VarCharType;
import com.facebook.presto.testing.MaterializedResult;
@@ -44,6 +46,7 @@ import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import java.nio.file.Files;
+import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
@@ -147,6 +150,30 @@ public class TestPrestoITCase {
commit.commit(0, writer.prepareCommit(true, 0));
}
+ {
+ // test for timestamp
+ Path tablePath5 = new Path(warehouse, "default.db/test_timestamp");
+ RowType rowType =
+ new RowType(
+ Collections.singletonList(new DataField(0, "ts",
new TimestampType())));
+ new SchemaManager(LocalFileIO.create(), tablePath5)
+ .createTable(
+ new Schema(
+ rowType.getFields(),
+ Collections.emptyList(),
+ Collections.singletonList("ts"),
+ new HashMap<>(),
+ ""));
+ FileStoreTable table =
FileStoreTableFactory.create(LocalFileIO.create(), tablePath5);
+ InnerTableWrite writer = table.newWrite("user");
+ InnerTableCommit commit = table.newCommit("user");
+ writer.write(
+ GenericRow.of(
+ Timestamp.fromLocalDateTime(
+
LocalDateTime.parse("2023-01-01T01:01:01.123"))));
+ commit.commit(0, writer.prepareCommit(true, 0));
+ }
+
DistributedQueryRunner queryRunner = null;
try {
queryRunner =
@@ -223,6 +250,14 @@ public class TestPrestoITCase {
.isEqualTo("[[1, 1, 3, 3], [2, 3, 3, 3]]");
}
+ // Due to the inconsistency between the testing behavior and the real
production environment,
+ // we are temporarily disabling timestamp testing here.
+ @Test(enabled = false)
+ public void testTimestampFormat() throws Exception {
+ assertThat(sql("SELECT ts FROM paimon.default.test_timestamp"))
+ .isEqualTo("[[2023-01-01T01:01:01.123]]");
+ }
+
private String sql(String sql) throws Exception {
MaterializedResult result = queryRunner.execute(sql);
return result.getMaterializedRows().toString();