Skip to content
Open
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 @@ -51,9 +51,9 @@
import org.apache.paimon.table.source.TableRead;
import org.apache.paimon.types.BigIntType;
import org.apache.paimon.types.DataField;
import org.apache.paimon.types.LocalZonedTimestampType;
import org.apache.paimon.types.MapType;
import org.apache.paimon.types.RowType;
import org.apache.paimon.types.TimestampType;
import org.apache.paimon.utils.IteratorRecordReader;
import org.apache.paimon.utils.ProjectedRow;
import org.apache.paimon.utils.SerializationUtils;
Expand All @@ -64,9 +64,6 @@
import javax.annotation.Nullable;

import java.io.IOException;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
Expand Down Expand Up @@ -96,7 +93,7 @@ public class SnapshotsTable implements ReadonlyTable {
new DataField(3, "commit_identifier", new BigIntType(false)),
new DataField(
4, "commit_kind", SerializationUtils.newStringType(false)),
new DataField(5, "commit_time", new TimestampType(false, 3)),
new DataField(5, "commit_time", new LocalZonedTimestampType(false, 3)),
new DataField(
6,
"base_manifest_list",
Expand Down Expand Up @@ -359,10 +356,7 @@ private InternalRow toRow(Snapshot snapshot) {
BinaryString.fromString(snapshot.commitUser()),
snapshot.commitIdentifier(),
BinaryString.fromString(snapshot.commitKind().toString()),
Timestamp.fromLocalDateTime(
LocalDateTime.ofInstant(
Instant.ofEpochMilli(snapshot.timeMillis()),
ZoneId.systemDefault())),
Timestamp.fromEpochMillis(snapshot.timeMillis()),
BinaryString.fromString(snapshot.baseManifestList()),
BinaryString.fromString(snapshot.deltaManifestList()),
BinaryString.fromString(snapshot.changelogManifestList()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@
import org.apache.paimon.tag.Tag;
import org.apache.paimon.types.BigIntType;
import org.apache.paimon.types.DataField;
import org.apache.paimon.types.LocalZonedTimestampType;
import org.apache.paimon.types.RowType;
import org.apache.paimon.types.TimestampType;
import org.apache.paimon.utils.DateTimeUtils;
import org.apache.paimon.utils.IteratorRecordReader;
import org.apache.paimon.utils.Pair;
import org.apache.paimon.utils.ProjectedRow;
Expand Down Expand Up @@ -87,7 +87,7 @@ public class TagsTable implements ReadonlyTable {
new DataField(0, TAG_NAME, SerializationUtils.newStringType(false)),
new DataField(1, "snapshot_id", new BigIntType(false)),
new DataField(2, "schema_id", new BigIntType(false)),
new DataField(3, "commit_time", new TimestampType(false, 3)),
new DataField(3, "commit_time", new LocalZonedTimestampType(false, 3)),
new DataField(4, "record_count", new BigIntType(true)),
new DataField(5, "create_time", new TimestampType(true, 3)),
new DataField(
Expand Down Expand Up @@ -296,7 +296,7 @@ private InternalRow toRow(Map.Entry<String, Tag> snapshot) {
BinaryString.fromString(snapshot.getKey()),
tag.id(),
tag.schemaId(),
Timestamp.fromLocalDateTime(DateTimeUtils.toLocalDateTime(tag.timeMillis())),
Timestamp.fromEpochMillis(tag.timeMillis()),
tag.totalRecordCount(),
Optional.ofNullable(tag.getTagCreateTime())
.map(Timestamp::fromLocalDateTime)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,14 @@
import org.apache.paimon.table.TableTestBase;
import org.apache.paimon.table.sink.TableCommitImpl;
import org.apache.paimon.table.source.ReadBuilder;
import org.apache.paimon.types.DataField;
import org.apache.paimon.types.DataTypes;
import org.apache.paimon.utils.SnapshotManager;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.time.Duration;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
Expand Down Expand Up @@ -106,6 +104,12 @@ public void before() throws Exception {

@Test
public void testReadSnapshotsFromLatest() throws Exception {
assertThat(snapshotsTable.rowType().getField(5))
.isEqualTo(
new DataField(
5,
"commit_time",
DataTypes.TIMESTAMP_WITH_LOCAL_TIME_ZONE(3).notNull()));
List<InternalRow> expectedRow = getExpectedResult(new long[] {1, 2});
List<InternalRow> result = read(snapshotsTable);
assertThat(result).containsExactlyInAnyOrderElementsOf(expectedRow);
Expand Down Expand Up @@ -278,10 +282,7 @@ private List<InternalRow> getExpectedResult(long[] snapshotIds) {
BinaryString.fromString(snapshot.commitUser()),
snapshot.commitIdentifier(),
BinaryString.fromString(snapshot.commitKind().toString()),
Timestamp.fromLocalDateTime(
LocalDateTime.ofInstant(
Instant.ofEpochMilli(snapshot.timeMillis()),
ZoneId.systemDefault())),
Timestamp.fromEpochMillis(snapshot.timeMillis()),
BinaryString.fromString(snapshot.baseManifestList()),
BinaryString.fromString(snapshot.deltaManifestList()),
BinaryString.fromString(snapshot.changelogManifestList()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
import org.apache.paimon.table.sink.TableCommitImpl;
import org.apache.paimon.table.source.ReadBuilder;
import org.apache.paimon.tag.Tag;
import org.apache.paimon.types.DataField;
import org.apache.paimon.types.DataTypes;
import org.apache.paimon.utils.DateTimeUtils;
import org.apache.paimon.utils.Pair;
import org.apache.paimon.utils.TagManager;

Expand Down Expand Up @@ -95,6 +95,12 @@ void before() throws Exception {

@Test
void testTagsTable() throws Exception {
assertThat(tagsTable.rowType().getField(3))
.isEqualTo(
new DataField(
3,
"commit_time",
DataTypes.TIMESTAMP_WITH_LOCAL_TIME_ZONE(3).notNull()));
List<InternalRow> expectRow = getExpectedResult();
List<InternalRow> result = read(tagsTable);
assertThat(result).containsExactlyElementsOf(expectRow);
Expand Down Expand Up @@ -208,8 +214,7 @@ private List<InternalRow> getExpectedResult() {
BinaryString.fromString(tagName),
tag.id(),
tag.schemaId(),
Timestamp.fromLocalDateTime(
DateTimeUtils.toLocalDateTime(tag.timeMillis())),
Timestamp.fromEpochMillis(tag.timeMillis()),
tag.totalRecordCount(),
tag.getTagCreateTime() == null
? null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,27 @@ class PaimonSystemTableTest extends PaimonSparkTestBase {
sql("CALL paimon.sys.expire_snapshots(table => 'test.T', retain_max => 1, retain_min => 1)")
checkAnswer(sql("SELECT snapshot_id FROM `T$snapshots` WHERE snapshot_id < 2"), Nil)
}

test("system table: snapshot and tag commit times use the snapshot instant") {
assume(gteqSpark3_4)
sql("CREATE TABLE T (a INT)")
sql("INSERT INTO T VALUES (1)")
sql("CALL paimon.sys.create_tag(table => 'test.T', tag => 'first', snapshot => 1)")
val millis = loadTable("T").snapshotManager().snapshot(1).timeMillis()

withTimeZone("Asia/Shanghai") {
withSparkSQLConf(
"spark.sql.session.timeZone" -> "UTC",
"spark.paimon.legacy-timestamp-mapping.enabled" -> "false") {
checkAnswer(
sql(s"""
|SELECT unix_millis(s.commit_time), unix_millis(t.commit_time)
|FROM `T$$snapshots` s JOIN `T$$tags` t ON s.snapshot_id = t.snapshot_id
|WHERE t.tag_name = 'first' AND s.commit_time < timestamp_millis(${millis + 1})
|""".stripMargin),
Seq(Row(millis, millis))
)
}
}
}
}
Loading