Skip to content

Commit 8a81f2d

Browse files
committed
fix: ob-mysql as target datetime bug
1 parent 162c291 commit 8a81f2d

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

connectors/oceanbase-mysql-connector/src/main/java/io/tapdata/oceanbase/connector/OceanbaseConnector.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,18 @@ public void registerCapabilities(ConnectorFunctions connectorFunctions, TapCodec
132132
return "null";
133133
});
134134
//TapTimeValue, TapDateTimeValue and TapDateValue's value is DateTime, need convert into Date object.
135-
codecRegistry.registerFromTapValue(TapTimeValue.class, tapTimeValue -> tapTimeValue.getValue().toTime());
136-
codecRegistry.registerFromTapValue(TapDateTimeValue.class, tapDateTimeValue -> tapDateTimeValue.getValue().toTimestamp());
137-
codecRegistry.registerFromTapValue(TapDateValue.class, tapDateValue -> tapDateValue.getValue().toSqlDate());
135+
codecRegistry.registerFromTapValue(TapDateTimeValue.class, tapDateTimeValue -> {
136+
if (EmptyKit.isNotNull(tapDateTimeValue.getValue().getTimeZone())) {
137+
tapDateTimeValue.getValue().setTimeZone(TimeZone.getTimeZone("UTC"));
138+
} else {
139+
tapDateTimeValue.getValue().setTimeZone(timeZone);
140+
}
141+
return tapDateTimeValue.getValue().isContainsIllegal() ? tapDateTimeValue.getValue().getIllegalDate() : formatTapDateTime(tapDateTimeValue.getValue(), "yyyy-MM-dd HH:mm:ss.SSSSSS");
142+
});
143+
//date类型通过jdbc读取时,会自动转换为当前时区的时间,所以设置为当前时区
144+
codecRegistry.registerFromTapValue(TapDateValue.class, tapDateValue -> tapDateValue.getValue().isContainsIllegal() ? tapDateValue.getValue().getIllegalDate() : tapDateValue.getValue().toInstant());
145+
codecRegistry.registerFromTapValue(TapTimeValue.class, tapTimeValue -> tapTimeValue.getValue().toTimeStr());
146+
codecRegistry.registerFromTapValue(TapYearValue.class, TapValue::getOriginValue);
138147
connectorFunctions.supportExecuteCommandFunction((a, b, c) -> SqlExecuteCommandFunction.executeCommand(a, b, () -> mysqlJdbcContext.getConnection(), this::isAlive, c));
139148
connectorFunctions.supportRunRawCommandFunction(this::runRawCommand);
140149
//ddl

0 commit comments

Comments
 (0)