Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Zouxxyy committed Jan 3, 2024
1 parent f659d36 commit 2a64067
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
import org.apache.paimon.data.Timestamp;
import org.apache.paimon.io.DataInputView;
import org.apache.paimon.io.DataOutputView;
import org.apache.paimon.utils.DateTimeUtils;

import java.io.IOException;
import java.time.LocalDateTime;

/**
* Serializer for {@link Timestamp}.
Expand Down Expand Up @@ -76,12 +76,12 @@ public Timestamp deserialize(DataInputView source) throws IOException {

@Override
public String serializeToString(Timestamp record) {
return record.toLocalDateTime().toString();
return DateTimeUtils.formatTimestamp(record, precision);
}

@Override
public Timestamp deserializeFromString(String s) {
return Timestamp.fromLocalDateTime(LocalDateTime.parse(s));
return DateTimeUtils.parseTimestampData(s, precision);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.apache.paimon.data.serializer;

import org.apache.paimon.data.Timestamp;
import org.apache.paimon.utils.DateTimeUtils;
import org.apache.paimon.utils.Pair;

import java.util.Arrays;
Expand Down Expand Up @@ -47,42 +48,83 @@ protected Timestamp[] getTestData() {
};
}

@Override
protected List<Pair<Timestamp, String>> getSerializableToStringTestData() {
return Arrays.asList(
Pair.of(Timestamp.fromEpochMillis(1), "1970-01-01T00:00:00.001"),
Pair.of(Timestamp.fromEpochMillis(2), "1970-01-01T00:00:00.002"),
Pair.of(Timestamp.fromEpochMillis(3), "1970-01-01T00:00:00.003"),
Pair.of(Timestamp.fromEpochMillis(4, 1), "1970-01-01T00:00:00.004000001"));
}

protected abstract int getPrecision();

static final class TimestampSerializer0Test extends TimestampSerializerTest {
@Override
protected int getPrecision() {
return 0;
}

@Override
protected List<Pair<Timestamp, String>> getSerializableToStringTestData() {
return Arrays.asList(
Pair.of(
DateTimeUtils.parseTimestampData("2019-01-01 00:00:00", getPrecision()),
"2019-01-01 00:00:00"),
Pair.of(
DateTimeUtils.parseTimestampData("2019-01-01 00:00:01", getPrecision()),
"2019-01-01 00:00:01"));
}
}

static final class TimestampSerializer3Test extends TimestampSerializerTest {
@Override
protected int getPrecision() {
return 3;
}

@Override
protected List<Pair<Timestamp, String>> getSerializableToStringTestData() {
return Arrays.asList(
Pair.of(
DateTimeUtils.parseTimestampData(
"2019-01-01 00:00:00.000", getPrecision()),
"2019-01-01 00:00:00.000"),
Pair.of(
DateTimeUtils.parseTimestampData(
"2019-01-01 00:00:00.001", getPrecision()),
"2019-01-01 00:00:00.001"));
}
}

static final class TimestampSerializer6Test extends TimestampSerializerTest {
@Override
protected int getPrecision() {
return 6;
}

@Override
protected List<Pair<Timestamp, String>> getSerializableToStringTestData() {
return Arrays.asList(
Pair.of(
DateTimeUtils.parseTimestampData(
"2019-01-01 00:00:00.000000", getPrecision()),
"2019-01-01 00:00:00.000000"),
Pair.of(
DateTimeUtils.parseTimestampData(
"2019-01-01 00:00:00.000001", getPrecision()),
"2019-01-01 00:00:00.000001"));
}
}

static final class TimestampSerializer8Test extends TimestampSerializerTest {
@Override
protected int getPrecision() {
return 8;
}

@Override
protected List<Pair<Timestamp, String>> getSerializableToStringTestData() {
return Arrays.asList(
Pair.of(
DateTimeUtils.parseTimestampData(
"2019-01-01 00:00:00.00000000", getPrecision()),
"2019-01-01 00:00:00.00000000"),
Pair.of(
DateTimeUtils.parseTimestampData(
"2019-01-01 00:00:00.00000001", getPrecision()),
"2019-01-01 00:00:00.00000001"));
}
}
}

0 comments on commit 2a64067

Please sign in to comment.