-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Common Jsons: add flag to apply flatten to arrays #13464
Conversation
/test connector=connectors/destination-redshift
Build PassedTest summary info:
|
*/ | ||
public static Map<String, Object> flatten(final JsonNode node) { | ||
public static Map<String, Object> flatten(final JsonNode node, final Boolean applyFlattenToArray) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public static Map<String, Object> flatten(final JsonNode node, final Boolean applyFlattenToArray) { | |
public static Map<String, Object> flatten(final JsonNode node, final boolean applyFlattenToArray) { |
* Flattens an ObjectNode, or dumps it into a {null: value} map if it's not an object. | ||
* this is used for JobTracker where is arrays aren't flatten and only converted to strings | ||
* and Redshift SUPER type now reuse the function and need to arrays be flatten in the | ||
* correct format |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* Flattens an ObjectNode, or dumps it into a {null: value} map if it's not an object. | |
* this is used for JobTracker where is arrays aren't flatten and only converted to strings | |
* and Redshift SUPER type now reuse the function and need to arrays be flatten in the | |
* correct format | |
* Flattens an ObjectNode, or dumps it into a {null: value} map if it's not an object. When | |
* applyFlattenToArray is true, each element in the array will be one entry in the returned map. | |
* This behavior is used in the Redshift SUPER type. When it is false, the whole array will be one | |
* entry. This is used in the JobTracker. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll apply format. thanks for the review @tuliren
if (node.isObject()) { | ||
final Map<String, Object> output = new HashMap<>(); | ||
for (final Iterator<Entry<String, JsonNode>> it = node.fields(); it.hasNext();) { | ||
final Entry<String, JsonNode> entry = it.next(); | ||
final String field = entry.getKey(); | ||
final JsonNode value = entry.getValue(); | ||
mergeMaps(output, field, flatten(value)); | ||
mergeMaps(output, field, flatten(value, false)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@marcosmarxm this cannot be hardcoded to false
, but needs to pass applyFlattenToArray
through - you can have an array nested inside an object.
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)); | ||
mergeMaps(output, field, flatten(value, true)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for consistency with the case above, I'd recommend changing this to flatten(value, applyFlattenToArray)
, although of course it will only be invoked when applyFlattenToArray
is true
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@marcosmarxm thanks for addressing this case - I wasn't sure if we needed to go here or not. See my comments below for a quick functional fix we need to apply.
Do we need to republish redshift 0.3.38 too? Looks like the connector version bump/changelog was backed out too. Even though this will result in a functionally equivalent connector, we should make sure the changelog remains accurate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you write some unit tests please?
What
Describe what the change is solving
It helps to add screenshots if it affects the frontend.
How
Describe the solution
Recommended reading order
x.java
y.python
🚨 User Impact 🚨
Are there any breaking changes? What is the end result perceived by the user? If yes, please merge this PR with the 🚨🚨 emoji so changelog authors can further highlight this if needed.
Pre-merge Checklist
Expand the relevant checklist and delete the others.
New Connector
Community member or Airbyter
airbyte_secret
./gradlew :airbyte-integrations:connectors:<name>:integrationTest
.README.md
bootstrap.md
. See description and examplesdocs/SUMMARY.md
docs/integrations/<source or destination>/<name>.md
including changelog. See changelog exampledocs/integrations/README.md
airbyte-integrations/builds.md
Airbyter
If this is a community PR, the Airbyte engineer reviewing this PR is responsible for the below items.
/test connector=connectors/<name>
command is passing/publish
command described hereUpdating a connector
Community member or Airbyter
airbyte_secret
./gradlew :airbyte-integrations:connectors:<name>:integrationTest
.README.md
bootstrap.md
. See description and examplesdocs/integrations/<source or destination>/<name>.md
including changelog. See changelog exampleAirbyter
If this is a community PR, the Airbyte engineer reviewing this PR is responsible for the below items.
/test connector=connectors/<name>
command is passing/publish
command described hereConnector Generator
-scaffold
in their name) have been updated with the latest scaffold by running./gradlew :airbyte-integrations:connector-templates:generator:testScaffoldTemplates
then checking in your changesTests
Unit
Put your unit tests output here.
Integration
Put your integration tests output here.
Acceptance
Put your acceptance tests output here.