Unverified Commit 13e0eb60 authored by booleandev's avatar booleandev Committed by GitHub

[Fix-1936][Client]: cdcsource convert value error (#1938)

parent cfd3ad09
...@@ -343,6 +343,15 @@ public abstract class AbstractSinkBuilder implements SinkBuilder { ...@@ -343,6 +343,15 @@ public abstract class AbstractSinkBuilder implements SinkBuilder {
.atZone(sinkTimeZone) .atZone(sinkTimeZone)
.toLocalDateTime()); .toLocalDateTime());
} else if (value instanceof Long) { } else if (value instanceof Long) {
// pgsql database timestamp is microsecond ,need transform to millisecond
// time is microsecond when time after 3000-01-01 00:00:00
// time is microsecond when time before 1000-01-01 00:00:00
if ((long) value > 32503651200000L || (long) value < -30610253143000L) {
return TimestampData.fromLocalDateTime(
Instant.ofEpochMilli((long) value / 1000)
.atZone(sinkTimeZone)
.toLocalDateTime());
}
return TimestampData.fromLocalDateTime( return TimestampData.fromLocalDateTime(
Instant.ofEpochMilli((long) value).atZone(sinkTimeZone).toLocalDateTime()); Instant.ofEpochMilli((long) value).atZone(sinkTimeZone).toLocalDateTime());
} else { } else {
...@@ -369,6 +378,12 @@ public abstract class AbstractSinkBuilder implements SinkBuilder { ...@@ -369,6 +378,12 @@ public abstract class AbstractSinkBuilder implements SinkBuilder {
} else { } else {
return value; return value;
} }
} else if (logicalType instanceof SmallIntType) {
if (value instanceof Number) {
return ((Number) value).shortValue();
} else {
return value;
}
} else if (logicalType instanceof VarBinaryType) { } else if (logicalType instanceof VarBinaryType) {
// VARBINARY AND BINARY is converted to String with encoding base64 in FlinkCDC. // VARBINARY AND BINARY is converted to String with encoding base64 in FlinkCDC.
if (value instanceof String) { if (value instanceof String) {
......
...@@ -343,6 +343,15 @@ public abstract class AbstractSinkBuilder implements SinkBuilder { ...@@ -343,6 +343,15 @@ public abstract class AbstractSinkBuilder implements SinkBuilder {
.atZone(sinkTimeZone) .atZone(sinkTimeZone)
.toLocalDateTime()); .toLocalDateTime());
} else if (value instanceof Long) { } else if (value instanceof Long) {
// pgsql database timestamp is microsecond ,need transform to millisecond
// time is microsecond when time after 3000-01-01 00:00:00
// time is microsecond when time before 1000-01-01 00:00:00
if ((long) value > 32503651200000L || (long) value < -30610253143000L) {
return TimestampData.fromLocalDateTime(
Instant.ofEpochMilli((long) value / 1000)
.atZone(sinkTimeZone)
.toLocalDateTime());
}
return TimestampData.fromLocalDateTime( return TimestampData.fromLocalDateTime(
Instant.ofEpochMilli((long) value).atZone(sinkTimeZone).toLocalDateTime()); Instant.ofEpochMilli((long) value).atZone(sinkTimeZone).toLocalDateTime());
} else { } else {
...@@ -369,6 +378,12 @@ public abstract class AbstractSinkBuilder implements SinkBuilder { ...@@ -369,6 +378,12 @@ public abstract class AbstractSinkBuilder implements SinkBuilder {
} else { } else {
return value; return value;
} }
} else if (logicalType instanceof SmallIntType) {
if (value instanceof Number) {
return ((Number) value).shortValue();
} else {
return value;
}
} else if (logicalType instanceof VarBinaryType) { } else if (logicalType instanceof VarBinaryType) {
// VARBINARY AND BINARY is converted to String with encoding base64 in FlinkCDC. // VARBINARY AND BINARY is converted to String with encoding base64 in FlinkCDC.
if (value instanceof String) { if (value instanceof String) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment