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

🐛 Postgres Source: fixed truncated precision if the value of the milliseconds or seconds is 0 #13549

Merged
merged 18 commits into from
Jun 14, 2022
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
a53fb77
Postgres Source: fixed truncated precision if the value of the millis…
VitaliiMaltsev Jun 7, 2022
469c32b
Merge branch 'master' into vmaltsev/13489-postgres-tryncated-precision
VitaliiMaltsev Jun 7, 2022
c9598c8
check CI with 1.15.3 testcontainer
VitaliiMaltsev Jun 7, 2022
2c04a0a
check CI with 1.15.3 testcontainer
VitaliiMaltsev Jun 7, 2022
78efaf9
returned latest version of testcontainer
VitaliiMaltsev Jun 7, 2022
b22cd5a
Merge branch 'master' into vmaltsev/13489-postgres-tryncated-precision
VitaliiMaltsev Jun 7, 2022
0c468e0
fixed checkstyle
VitaliiMaltsev Jun 7, 2022
4239ba1
Merge remote-tracking branch 'origin/vmaltsev/13489-postgres-tryncate…
VitaliiMaltsev Jun 7, 2022
31f2057
Merge branch 'master' of https://github.com/airbytehq/airbyte
VitaliiMaltsev Jun 7, 2022
0c3c5c2
Merge branch 'master' into vmaltsev/13489-postgres-tryncated-precision
VitaliiMaltsev Jun 7, 2022
682c8ed
fixed checkstyle
VitaliiMaltsev Jun 7, 2022
3386418
returned latest testcontainer version
VitaliiMaltsev Jun 7, 2022
117d7f3
updated CHANGELOG
VitaliiMaltsev Jun 7, 2022
353cdb1
Merge branch 'master' into vmaltsev/13489-postgres-tryncated-precision
VitaliiMaltsev Jun 9, 2022
b884a11
Merge branch 'master' into vmaltsev/13489-postgres-tryncated-precision
VitaliiMaltsev Jun 14, 2022
e2fb697
Merge branch 'master' into vmaltsev/13489-postgres-tryncated-precision
VitaliiMaltsev Jun 14, 2022
3ae112e
bump version
VitaliiMaltsev Jun 14, 2022
b4efc76
auto-bump connector version
octavia-squidington-iii Jun 14, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ public class DataTypeUtils {

public static final String DATE_FORMAT_WITH_MILLISECONDS_PATTERN = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";

public static final DateTimeFormatter TIME_FORMATTER = DateTimeFormatter.ofPattern("HH:mm:ss.SSSSSS");
public static final DateTimeFormatter TIMESTAMP_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSSSS");
public static final DateTimeFormatter TIMETZ_FORMATTER = DateTimeFormatter.ofPattern("HH:mm:ss.SSSSSSXXX");
public static final DateTimeFormatter TIMESTAMPTZ_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSSSSXXX");

// wrap SimpleDateFormat in a function because SimpleDateFormat is not threadsafe as a static final.
public static DateFormat getDateFormat() {
return new SimpleDateFormat(DATE_FORMAT_PATTERN); // Quoted "Z" to indicate UTC, no timezone offset;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

package io.airbyte.db.jdbc;

import static io.airbyte.db.DataTypeUtils.TIMESTAMPTZ_FORMATTER;
import static io.airbyte.db.DataTypeUtils.TIMETZ_FORMATTER;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
Expand Down Expand Up @@ -256,13 +259,13 @@ protected <DateTime> DateTime getDateTimeObject(ResultSet resultSet, int index,

protected void putTimeWithTimezone(ObjectNode node, String columnName, ResultSet resultSet, int index) throws SQLException {
OffsetTime timetz = getDateTimeObject(resultSet, index, OffsetTime.class);
node.put(columnName, timetz.toString());
node.put(columnName, timetz.format(TIMETZ_FORMATTER));
}

protected void putTimestampWithTimezone(ObjectNode node, String columnName, ResultSet resultSet, int index) throws SQLException {
OffsetDateTime timestamptz = getDateTimeObject(resultSet, index, OffsetDateTime.class);
LocalDate localDate = timestamptz.toLocalDate();
node.put(columnName, resolveEra(localDate, timestamptz.toString()));
node.put(columnName, resolveEra(localDate, timestamptz.format(TIMESTAMPTZ_FORMATTER)));
}

protected String resolveEra(LocalDate date, String value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

package io.airbyte.integrations.source.postgres;

import static io.airbyte.db.DataTypeUtils.TIMESTAMP_FORMATTER;
import static io.airbyte.db.DataTypeUtils.TIME_FORMATTER;
import static io.airbyte.db.jdbc.JdbcConstants.INTERNAL_COLUMN_NAME;
import static io.airbyte.db.jdbc.JdbcConstants.INTERNAL_COLUMN_TYPE;
import static io.airbyte.db.jdbc.JdbcConstants.INTERNAL_COLUMN_TYPE_NAME;
Expand Down Expand Up @@ -135,14 +137,14 @@ protected void putDate(ObjectNode node, String columnName, ResultSet resultSet,
@Override
protected void putTime(ObjectNode node, String columnName, ResultSet resultSet, int index) throws SQLException {
LocalTime time = getDateTimeObject(resultSet, index, LocalTime.class);
node.put(columnName, time.toString());
node.put(columnName, time.format(TIME_FORMATTER));
}

@Override
protected void putTimestamp(ObjectNode node, String columnName, ResultSet resultSet, int index) throws SQLException {
LocalDateTime timestamp = getDateTimeObject(resultSet, index, LocalDateTime.class);
LocalDate date = timestamp.toLocalDate();
node.put(columnName, resolveEra(date, timestamp.toString()));
node.put(columnName, resolveEra(date, timestamp.format(TIMESTAMP_FORMATTER)));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -449,8 +449,9 @@ protected void initTests() {
.fullSourceDataType(fullSourceType)
.airbyteType(JsonSchemaType.STRING_TIME_WITHOUT_TIMEZONE)
// time column will ignore time zone
.addInsertValues("null", "'13:00:01'", "'13:00:02+8'", "'13:00:03-8'", "'13:00:04Z'", "'13:00:05Z+8'", "'13:00:06Z-8'")
.addExpectedValues(null, "13:00:01", "13:00:02", "13:00:03", "13:00:04", "13:00:05", "13:00:06")
.addInsertValues("null", "'13:00:01'", "'13:00:02+8'", "'13:00:03-8'", "'13:00:04Z'", "'13:00:05.01234Z+8'", "'13:00:00Z-8'")
.addExpectedValues(null, "13:00:01.000000", "13:00:02.000000", "13:00:03.000000", "13:00:04.000000", "13:00:05.012340",
"13:00:00.000000")
.build());
}

Expand All @@ -461,10 +462,11 @@ protected void initTests() {
.sourceType("timetz")
.fullSourceDataType(fullSourceType)
.airbyteType(JsonSchemaType.STRING_TIME_WITH_TIMEZONE)
.addInsertValues("null", "'13:00:01'", "'13:00:02+8'", "'13:00:03-8'", "'13:00:04Z'", "'13:00:05Z+8'", "'13:00:06Z-8'")
.addInsertValues("null", "'13:00:01'", "'13:00:00+8'", "'13:00:03-8'", "'13:00:04Z'", "'13:00:05.012345Z+8'", "'13:00:06.00000Z-8'")
// A time value without time zone will use the time zone set on the database, which is Z-7,
// so 13:00:01 is returned as 13:00:01-07.
.addExpectedValues(null, "13:00:01-07:00", "13:00:02+08:00", "13:00:03-08:00", "13:00:04Z", "13:00:05-08:00", "13:00:06+08:00")
.addExpectedValues(null, "13:00:01.000000-07:00", "13:00:00.000000+08:00", "13:00:03.000000-08:00", "13:00:04.000000Z",
"13:00:05.012345-08:00", "13:00:06.000000+08:00")
.build());
}

Expand All @@ -475,8 +477,8 @@ protected void initTests() {
.sourceType("timestamp")
.fullSourceDataType(fullSourceType)
.airbyteType(JsonSchemaType.STRING_TIMESTAMP_WITHOUT_TIMEZONE)
.addInsertValues("TIMESTAMP '2004-10-19 10:23:54'", "TIMESTAMP '2004-10-19 10:23:54.123456'", "null")
.addExpectedValues("2004-10-19T10:23:54", "2004-10-19T10:23:54.123456", null)
.addInsertValues("TIMESTAMP '2004-10-19 10:23:00'", "TIMESTAMP '2004-10-19 10:23:54.123456'", "null")
.addExpectedValues("2004-10-19T10:23:00.000000", "2004-10-19T10:23:54.123456", null)
.build());
}

Expand All @@ -487,9 +489,9 @@ protected void initTests() {
.sourceType("timestamptz")
.fullSourceDataType(fullSourceType)
.airbyteType(JsonSchemaType.STRING_TIMESTAMP_WITH_TIMEZONE)
.addInsertValues("TIMESTAMP '2004-10-19 10:23:54-08'", "TIMESTAMP '2004-10-19 10:23:54.123456-08'", "null")
.addInsertValues("TIMESTAMP '2004-10-19 10:23:00-08'", "TIMESTAMP '2004-10-19 10:23:54.123456-08'", "null")
// 2004-10-19T10:23:54Z-8 = 2004-10-19T17:23:54Z
.addExpectedValues("2004-10-19T17:23:54Z", "2004-10-19T17:23:54.123456Z", null)
.addExpectedValues("2004-10-19T17:23:00.000000Z", "2004-10-19T17:23:54.123456Z", null)
.build());
}

Expand Down
1 change: 1 addition & 0 deletions docs/integrations/sources/postgres.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ According to Postgres [documentation](https://www.postgresql.org/docs/14/datatyp

| Version | Date | Pull Request | Subject |
|:--------|:-----------|:-------------------------------------------------------|:----------------------------------------------------------------------------------------------------------------|
| 0.4.22 | 2022-06-07 | [13549](https://github.com/airbytehq/airbyte/pull/13549) | Fixed truncated precision if the value of microseconds or seconds is 0 |
| 0.4.21 | 2022-06-06 | [13435](https://github.com/airbytehq/airbyte/pull/13435) | Adjust JDBC fetch size based on max memory and max row size |
| 0.4.20 | 2022-06-02 | [13367](https://github.com/airbytehq/airbyte/pull/13367) | Added convertion hstore to json format |
| 0.4.19 | 2022-05-25 | [13166](https://github.com/airbytehq/airbyte/pull/13166) | Added timezone awareness and handle BC dates |
Expand Down