Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: timestamp incompatibility with OceanBase 4.x #2146

Closed
wants to merge 2 commits into from
Closed
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
2 changes: 1 addition & 1 deletion docs/content/connectors/oceanbase-cdc(ZH).md
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ public class OceanBaseSourceExample {
.port(2881)
.logProxyHost("127.0.0.1")
.logProxyPort(2983)
.serverTimeZone(serverTimezone)
.serverTimeZone(serverTimeZone)
.deserializer(deserializer)
.build();

Expand Down
2 changes: 1 addition & 1 deletion docs/content/connectors/oceanbase-cdc.md
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ public class OceanBaseSourceExample {
.port(2881)
.logProxyHost("127.0.0.1")
.logProxyPort(2983)
.serverTimeZone(serverTimezone)
.serverTimeZone(serverTimeZone)
.deserializer(deserializer)
.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
import java.sql.Date;
import java.sql.Time;
import java.sql.Timestamp;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Arrays;
import java.util.Map;
Expand Down Expand Up @@ -484,7 +486,10 @@ private static OceanBaseDeserializationRuntimeConverter convertToTimestamp() {
@Override
public Object convertSnapshotEvent(Object object) {
if (object instanceof Timestamp) {
return TimestampData.fromLocalDateTime(((Timestamp) object).toLocalDateTime());
return TimestampData.fromTimestamp((Timestamp) object);
}
if (object instanceof LocalDateTime) {
return TimestampData.fromLocalDateTime((LocalDateTime) object);
}
throw new IllegalArgumentException(
"Unable to convert to TimestampData from unexpected value '"
Expand All @@ -495,7 +500,11 @@ public Object convertSnapshotEvent(Object object) {

@Override
public Object convertChangeEvent(String string) {
return TimestampData.fromLocalDateTime(Timestamp.valueOf(string).toLocalDateTime());
try {
return TimestampData.fromTimestamp(Timestamp.valueOf(string));
} catch (IllegalArgumentException e) {
return TimestampData.fromInstant(Instant.parse(string));
}
}
};
}
Expand All @@ -515,6 +524,10 @@ public Object convertSnapshotEvent(Object object) {
.atZone(serverTimeZone)
.toInstant());
}
if (object instanceof LocalDateTime) {
return TimestampData.fromInstant(
((LocalDateTime) object).atZone(serverTimeZone).toInstant());
}
throw new IllegalArgumentException(
"Unable to convert to TimestampData from unexpected value '"
+ object
Expand All @@ -524,11 +537,15 @@ public Object convertSnapshotEvent(Object object) {

@Override
public Object convertChangeEvent(String string) {
return TimestampData.fromInstant(
Timestamp.valueOf(string)
.toLocalDateTime()
.atZone(serverTimeZone)
.toInstant());
try {
return TimestampData.fromInstant(
Timestamp.valueOf(string)
.toLocalDateTime()
.atZone(serverTimeZone)
.toInstant());
} catch (IllegalArgumentException e) {
return TimestampData.fromInstant(Instant.parse(string));
}
}
};
}
Expand Down
Loading