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

🐛Destination-postgres: fixed normalization java tests after changes in Python part #15289

Merged
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class PostgresTestDataComparator extends AdvancedTestDataComparator {

private final ExtendedNameTransformer namingResolver = new ExtendedNameTransformer();

private static final String AIRBYTE_DATETIME_PARSED_FORMAT = "yyyy-MM-dd HH:mm:ss.S";
private static final String POSTGRES_DATETIME_FORMAT = "yyyy-MM-dd'T'HH:mm:ss'Z'";
private static final String POSTGRES_DATETIME_WITH_TZ_FORMAT = "yyyy-MM-dd'T'HH:mm:ss'Z'";

Expand All @@ -34,15 +35,6 @@ protected List<String> resolveIdentifier(final String identifier) {
return result;
}

private LocalDate parseLocalDate(String dateTimeValue) {
if (dateTimeValue != null) {
var format = (dateTimeValue.matches(".+Z") ? POSTGRES_DATETIME_FORMAT : AIRBYTE_DATETIME_FORMAT);
return LocalDate.parse(dateTimeValue, DateTimeFormatter.ofPattern(format));
} else {
return null;
}
}

@Override
protected boolean compareDateTimeValues(String expectedValue, String actualValue) {
var destinationDate = parseLocalDate(actualValue);
Expand All @@ -52,7 +44,29 @@ protected boolean compareDateTimeValues(String expectedValue, String actualValue

@Override
protected ZonedDateTime parseDestinationDateWithTz(String destinationValue) {
return ZonedDateTime.of(LocalDateTime.parse(destinationValue, DateTimeFormatter.ofPattern(POSTGRES_DATETIME_WITH_TZ_FORMAT)), ZoneOffset.UTC);
return ZonedDateTime.of(LocalDateTime.parse(destinationValue,
DateTimeFormatter.ofPattern(POSTGRES_DATETIME_WITH_TZ_FORMAT)), ZoneOffset.UTC);
}

private LocalDate parseLocalDate(String dateTimeValue) {
if (dateTimeValue != null) {
return LocalDate.parse(dateTimeValue,
DateTimeFormatter.ofPattern(getFormat(dateTimeValue)));
} else {
return null;
}
}

private String getFormat(String dateTimeValue) {
if (dateTimeValue.matches(".+Z")) {
return POSTGRES_DATETIME_FORMAT;
} else if (dateTimeValue.contains("T")) {
// Postgres stores array of objects as a jsobb type, i.e. array of string for all cases
return AIRBYTE_DATETIME_FORMAT;
} else {
// Postgres stores datetime as datetime type after normalization
return AIRBYTE_DATETIME_PARSED_FORMAT;
}
}

}