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

Mssql destination: enable DAT tests, use nvarchar and datetime2 by default #12305

Merged
merged 18 commits into from
May 7, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
26a9a93
Mssql destination: enable DAT tests for mssql destination, use nvarch…
sashaNeshcheret Apr 25, 2022
c024123
Mssql destination: update array handling in test
sashaNeshcheret Apr 28, 2022
3621ec8
Mssql destination: update array and JSON handling in test
sashaNeshcheret Apr 28, 2022
4472750
Mssql destination: remove unused method
sashaNeshcheret Apr 28, 2022
b517b19
Mssql destination: revert data for base normalization tests
sashaNeshcheret May 5, 2022
5f668f1
Merge branch 'master' into omneshcheret/dat-mssql
grubberr May 5, 2022
67503fe
temp fix REF -> ref
grubberr May 5, 2022
06fac71
Revert "Mssql destination: revert data for base normalization tests"
sashaNeshcheret May 5, 2022
fafe0d5
Merge remote-tracking branch 'origin/omneshcheret/dat-mssql' into omn…
sashaNeshcheret May 5, 2022
86d05a4
Mssql destination: revert data for base normalization tests
sashaNeshcheret May 5, 2022
b67626a
Merge branch 'master' into omneshcheret/dat-mssql
grubberr May 5, 2022
45da54d
bugfix bigquery tests, dataset_location added
grubberr May 6, 2022
9cac9ed
basic-normalization.md updated
grubberr May 6, 2022
64ee6eb
Merge remote-tracking branch 'origin/master' into omneshcheret/dat-mssql
sashaNeshcheret May 6, 2022
0921109
Mssql destination: change parent class for mssql test
sashaNeshcheret May 6, 2022
97832b6
Merge remote-tracking branch 'origin/omneshcheret/dat-mssql' into omn…
sashaNeshcheret May 6, 2022
bca6d64
Merge branch 'master' into omneshcheret/dat-mssql
grubberr May 7, 2022
155e8a2
Revert "temp fix REF -> ref"
grubberr May 7, 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
2 changes: 1 addition & 1 deletion airbyte-integrations/bases/base-normalization/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ WORKDIR /airbyte
ENV AIRBYTE_ENTRYPOINT "/airbyte/entrypoint.sh"
ENTRYPOINT ["/airbyte/entrypoint.sh"]

LABEL io.airbyte.version=0.1.77
LABEL io.airbyte.version=0.1.78
LABEL io.airbyte.name=airbyte/normalization
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
{%- endmacro -%}

{%- macro sqlserver__type_json() -%}
VARCHAR(max)
NVARCHAR(max)
{%- endmacro -%}

{% macro clickhouse__type_json() %}
Expand All @@ -52,7 +52,7 @@
{%- endmacro -%}

{% macro sqlserver__type_string() %}
VARCHAR(max)
NVARCHAR(max)
{%- endmacro -%}

{%- macro clickhouse__type_string() -%}
Expand Down Expand Up @@ -154,7 +154,7 @@
{%- macro sqlserver__type_timestamp_with_timezone() -%}
{#-- in TSQL timestamp is really datetime or datetime2 --#}
{#-- https://docs.microsoft.com/en-us/sql/t-sql/functions/date-and-time-data-types-and-functions-transact-sql?view=sql-server-ver15#DateandTimeDataTypes --#}
datetime
datetime2
{%- endmacro -%}

{% macro clickhouse__type_timestamp_with_timezone() %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,4 @@
{"type": "RECORD", "record": {"stream": "1_prefix_startwith_number", "emitted_at": 1602637990800, "data": { "id": 2, "date": "2020-09-01", "text": "hi 4"}}}

{"type":"RECORD","record":{"stream":"multiple_column_names_conflicts","data":{"id":1,"User Id":"chris","user_id":42,"User id":300,"user id": 102,"UserId":101},"emitted_at":1623959926}}
{"type":"RECORD","record":{"stream":"special_characters","data":{"id":1,"character_1":"some random special characters: ࠈൡሗ","user_id":42,"character_2":"some random special characters: žõ⥁🌞"},"emitted_at":1623959932}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I'm not mistaken, this test will effect normalization of all destinations. Are you sure that we are safe to do it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you are right. @grubberr will check if it works for all destinations and will make changes in scope of the PR if not.

Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import static org.junit.jupiter.api.Assertions.assertTrue;

import com.fasterxml.jackson.databind.JsonNode;
import io.airbyte.commons.json.Jsons;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
Expand Down Expand Up @@ -91,6 +92,8 @@ protected boolean compareJsonNodes(final JsonNode expectedValue, final JsonNode
return compareDateValues(expectedValue.asText(), actualValue.asText());
} else if (expectedValue.isArray() && actualValue.isArray()) {
return compareArrays(expectedValue, actualValue);
} else if (expectedValue.isArray() && isQuotedArray(actualValue)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a specific case of your destination. It should be handled inside your destination implementation.
I already fixed few destinations with the similar problem. You need to parse text values on the destination and provide actual value as true array here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, will do it.

return compareArrays(expectedValue, Jsons.deserialize(actualValue.asText()));
} else if (expectedValue.isObject() && actualValue.isObject()) {
compareObjects(expectedValue, actualValue);
return true;
Expand All @@ -99,6 +102,10 @@ protected boolean compareJsonNodes(final JsonNode expectedValue, final JsonNode
}
}

protected boolean isQuotedArray(JsonNode actualValue) {
return actualValue.isTextual() && actualValue.asText().matches("^\\[.*\\]$");
}

protected boolean compareString(final JsonNode expectedValue, final JsonNode actualValue) {
return expectedValue.asText().equals(actualValue.asText());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import io.airbyte.integrations.base.JavaBaseConstants;
import io.airbyte.integrations.destination.ExtendedNameTransformer;
import io.airbyte.integrations.standardtest.destination.DestinationAcceptanceTest;
import io.airbyte.integrations.standardtest.destination.comparator.TestDataComparator;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -167,6 +168,26 @@ protected void setup(final TestDestinationEnv testEnv) throws SQLException {
@Override
protected void tearDown(final TestDestinationEnv testEnv) {}

@Override
protected TestDataComparator getTestDataComparator() {
return new MSSQLTestDataComparator();
}

@Override
protected boolean supportBasicDataTypeTest() {
return true;
}

@Override
protected boolean supportArrayDataTypeTest() {
return true;
}

@Override
protected boolean supportObjectDataTypeTest() {
return true;
}

@AfterAll
static void cleanUp() {
db.stop();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package io.airbyte.integrations.destination.mssql;

import io.airbyte.integrations.destination.ExtendedNameTransformer;
import io.airbyte.integrations.standardtest.destination.comparator.AdvancedTestDataComparator;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;

public class MSSQLTestDataComparator extends AdvancedTestDataComparator {

public static final String ACTUAL_MSSQL_AIRBYTE_DATETIME_FORMAT = "yyyy-MM-dd HH:mm:ss.S";
private final ExtendedNameTransformer namingResolver = new ExtendedNameTransformer();


@Override
protected boolean compareDateTimeValues(String airbyteMessageValue, String destinationValue) {
if(!isDateTimeValue(destinationValue)){
destinationValue = LocalDateTime.parse(destinationValue, DateTimeFormatter.ofPattern(ACTUAL_MSSQL_AIRBYTE_DATETIME_FORMAT)).toString();
}
return super.compareDateTimeValues(airbyteMessageValue, destinationValue);
}

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

@Override
protected List<String> resolveIdentifier(final String identifier) {
final List<String> result = new ArrayList<>();
final String resolved = namingResolver.getIdentifier(identifier);
result.add(identifier);
result.add(resolved);
if (!resolved.startsWith("\"")) {
result.add(resolved.toLowerCase());
result.add(resolved.toUpperCase());
}
return result;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
public class NormalizationRunnerFactory {

public static final String BASE_NORMALIZATION_IMAGE_NAME = "airbyte/normalization";
public static final String NORMALIZATION_VERSION = "0.1.77";
public static final String NORMALIZATION_VERSION = "0.1.78";

static final Map<String, ImmutablePair<String, DefaultNormalizationRunner.DestinationType>> NORMALIZATION_MAPPING =
ImmutableMap.<String, ImmutablePair<String, DefaultNormalizationRunner.DestinationType>>builder()
Expand Down