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 Redshift: fixed array contents verification for SUPER #13069

Merged
merged 4 commits into from
Jun 3, 2022
Merged
Show file tree
Hide file tree
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
11 changes: 10 additions & 1 deletion airbyte-commons/src/main/java/io/airbyte/commons/json/Jsons.java
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,15 @@ public static Map<String, Object> flatten(final JsonNode node) {
mergeMaps(output, field, flatten(value));
}
return output;
} else if (node.isArray()) {
final Map<String, Object> output = new HashMap<>();
final int arrayLen = node.size();
for (int i = 0; i < arrayLen; i++) {
final String field = String.format("[%d]", i);
final JsonNode value = node.get(i);
mergeMaps(output, field, flatten(value));
}
return output;
Comment on lines +235 to +243
Copy link
Member

Choose a reason for hiding this comment

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

thanks @adam-bloom but can you add a unit test for this? I'll request the team to review it becsause the change can impact more than just Redshift.

} else {
final Object value;
if (node.isBoolean()) {
Expand All @@ -245,7 +254,7 @@ public static Map<String, Object> flatten(final JsonNode node) {
} else if (node.isValueNode() && !node.isNull()) {
value = node.asText();
} else {
// Fallback handling for e.g. arrays
// Fallback handling
value = node.toString();
}
return singletonMap(null, value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@
import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.junit.jupiter.api.Test;

class JsonsTest {
Expand Down Expand Up @@ -251,6 +254,29 @@ void testGetEstimatedByteSize() {
final JsonNode json = Jsons.deserialize("{\"string_key\":\"abc\",\"array_key\":[\"item1\", \"item2\"]}");
assertEquals(Jsons.toBytes(json).length, Jsons.getEstimatedByteSize(json));
}

@Test
void testFlatten__noArrays() {
final JsonNode json = Jsons.deserialize("{ \"abc\": { \"def\": \"ghi\" }, \"jkl\": true, \"pqr\": 1 }");
Map<String, Object> expected = Stream.of(new Object[][] {
{ "abc.def", "ghi" },
{ "jkl", true },
{ "pqr", 1 },
}).collect(Collectors.toMap(data -> (String) data[0], data -> data[1]));
assertEquals(Jsons.flatten(json), expected);
}

@Test
void testFlatten__withArrays() {
final JsonNode json = Jsons.deserialize("{ \"abc\": [{ \"def\": \"ghi\" }, { \"fed\": \"ihg\" }], \"jkl\": true, \"pqr\": 1 }");
Map<String, Object> expected = Stream.of(new Object[][] {
{ "abc.[0].def", "ghi" },
{ "abc.[1].fed", "ihg" },
{ "jkl", true },
{ "pqr", 1 },
}).collect(Collectors.toMap(data -> (String) data[0], data -> data[1]));
assertEquals(Jsons.flatten(json), expected);
}

private static class ToClass {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@
- name: Redshift
destinationDefinitionId: f7a7d195-377f-cf5b-70a5-be6b819019dc
dockerRepository: airbyte/destination-redshift
dockerImageTag: 0.3.37
dockerImageTag: 0.3.38
documentationUrl: https://docs.airbyte.io/integrations/destinations/redshift
icon: redshift.svg
resourceRequirements:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3629,7 +3629,7 @@
supported_destination_sync_modes:
- "overwrite"
- "append"
- dockerImage: "airbyte/destination-redshift:0.3.37"
- dockerImage: "airbyte/destination-redshift:0.3.38"
spec:
documentationUrl: "https://docs.airbyte.io/integrations/destinations/redshift"
connectionSpecification:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ ENV APPLICATION destination-redshift

COPY --from=build /airbyte /airbyte

LABEL io.airbyte.version=0.3.37
LABEL io.airbyte.version=0.3.38
LABEL io.airbyte.name=airbyte/destination-redshift
1 change: 1 addition & 0 deletions docs/integrations/destinations/redshift.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ Each stream will be output into its own raw table in Redshift. Each table will c

| Version | Date | Pull Request | Subject |
|:--------|:-----------|:-----------------------------------------------------------|:----------------------------------------------------------------------------------------------------------------------------------------------------|
| 0.3.38 | 2022-05-25 | [13069](https://github.com/airbytehq/airbyte/pull/13069) | Fixed array contents verification for SUPER type |
| 0.3.37 | 2022-05-23 | [13090](https://github.com/airbytehq/airbyte/pull/13090) | Removed redshiftDataTmpTableMode. Some refactoring. |
| 0.3.36 | 2022-05-23 | [12820](https://github.com/airbytehq/airbyte/pull/12820) | Improved 'check' operation performance |
| 0.3.35 | 2022-05-18 | [12940](https://github.com/airbytehq/airbyte/pull/12940) | Fixed maximum record size for SUPER type |
Expand Down