Skip to content

Commit

Permalink
Merge pull request #5 from fivetran/deserializer-fix-precesion
Browse files Browse the repository at this point in the history
fix(AbstractRowsEventDataDeserializer): correct fsp accuracy for datetime/timestamp v2
  • Loading branch information
glarwood authored Apr 1, 2020
2 parents 3f1bc55 + e26e2d7 commit 10d7c8c
Showing 1 changed file with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
import java.io.IOException;
import java.io.Serializable;
import java.math.BigDecimal;
import java.sql.Time;
import java.util.BitSet;
import java.util.Calendar;
import java.util.Date;
import java.util.Map;
import java.util.TimeZone;

Expand Down Expand Up @@ -266,7 +266,7 @@ protected Serializable deserializeTime(ByteArrayInputStream inputStream) throws
if (deserializeDateAndTimeAsLong) {
return castTimestamp(timestamp, 0);
}
return timestamp != null ? new java.sql.Time(timestamp) : null;
return timestamp != null ? new java.sql.Timestamp(timestamp) : null;
}

protected Serializable deserializeTimeV2(int meta, ByteArrayInputStream inputStream) throws IOException {
Expand Down Expand Up @@ -294,7 +294,7 @@ protected Serializable deserializeTimeV2(int meta, ByteArrayInputStream inputStr
if (deserializeDateAndTimeAsLong) {
return castTimestamp(timestamp, fsp);
}
return timestamp != null ? new java.sql.Time(timestamp) : null;
return timestamp != null ? convertLongTimestamptWithFSP(timestamp, fsp) : null;
}

protected Serializable deserializeTimestamp(ByteArrayInputStream inputStream) throws IOException {
Expand All @@ -312,7 +312,7 @@ protected Serializable deserializeTimestampV2(int meta, ByteArrayInputStream inp
if (deserializeDateAndTimeAsLong) {
return castTimestamp(timestamp, fsp);
}
return new java.sql.Timestamp(timestamp);
return convertLongTimestamptWithFSP(timestamp, fsp);
}

protected Serializable deserializeDatetime(ByteArrayInputStream inputStream) throws IOException {
Expand All @@ -321,7 +321,7 @@ protected Serializable deserializeDatetime(ByteArrayInputStream inputStream) thr
if (deserializeDateAndTimeAsLong) {
return castTimestamp(timestamp, 0);
}
return timestamp != null ? new java.util.Date(timestamp) : null;
return timestamp != null ? new java.sql.Timestamp(timestamp) : null;
}

protected Serializable deserializeDatetimeV2(int meta, ByteArrayInputStream inputStream) throws IOException {
Expand Down Expand Up @@ -354,7 +354,14 @@ protected Serializable deserializeDatetimeV2(int meta, ByteArrayInputStream inpu
if (deserializeDateAndTimeAsLong) {
return castTimestamp(timestamp, fsp);
}
return timestamp != null ? new java.util.Date(timestamp) : null;

return timestamp != null ? convertLongTimestamptWithFSP(timestamp, fsp) : null;
}

private java.sql.Timestamp convertLongTimestamptWithFSP(Long timestamp, int fsp) {
java.sql.Timestamp ts = new java.sql.Timestamp(timestamp);
ts.setNanos(fsp * 1000);
return ts;
}

protected Serializable deserializeYear(ByteArrayInputStream inputStream) throws IOException {
Expand Down

0 comments on commit 10d7c8c

Please sign in to comment.