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

🐛 Source Postgres: write hstore as json #13367

Merged
merged 5 commits into from
Jun 6, 2022

Conversation

yurii-bidiuk
Copy link
Contributor

What

Fixed #11953

How

Converted hstore key-value to JSON format

Recommended reading order

  1. PostgresSourceOperations.java
  2. PostgresSourceDatatypeTest.java

🚨 User Impact 🚨

Values of hstore type will be represented as JSON string instead of key-value map

Pre-merge Checklist

Expand the relevant checklist and delete the others.

New Connector

Community member or Airbyter

  • Community member? Grant edit access to maintainers (instructions)
  • Secrets in the connector's spec are annotated with airbyte_secret
  • Unit & integration tests added and passing. Community members, please provide proof of success locally e.g: screenshot or copy-paste unit, integration, and acceptance test output. To run acceptance tests for a Python connector, follow instructions in the README. For java connectors run ./gradlew :airbyte-integrations:connectors:<name>:integrationTest.
  • Code reviews completed
  • Documentation updated
    • Connector's README.md
    • Connector's bootstrap.md. See description and examples
    • docs/SUMMARY.md
    • docs/integrations/<source or destination>/<name>.md including changelog. See changelog example
    • docs/integrations/README.md
    • airbyte-integrations/builds.md
  • PR name follows PR naming conventions

Airbyter

If this is a community PR, the Airbyte engineer reviewing this PR is responsible for the below items.

  • Create a non-forked branch based on this PR and test the below items on it
  • Build is successful
  • If new credentials are required for use in CI, add them to GSM. Instructions.
  • /test connector=connectors/<name> command is passing
  • New Connector version released on Dockerhub by running the /publish command described here
  • After the connector is published, connector added to connector index as described here
  • Seed specs have been re-generated by building the platform and committing the changes to the seed spec files, as described here
Updating a connector

Community member or Airbyter

  • Grant edit access to maintainers (instructions)
  • Secrets in the connector's spec are annotated with airbyte_secret
  • Unit & integration tests added and passing. Community members, please provide proof of success locally e.g: screenshot or copy-paste unit, integration, and acceptance test output. To run acceptance tests for a Python connector, follow instructions in the README. For java connectors run ./gradlew :airbyte-integrations:connectors:<name>:integrationTest.
  • Code reviews completed
  • Documentation updated
    • Connector's README.md
    • Connector's bootstrap.md. See description and examples
    • Changelog updated in docs/integrations/<source or destination>/<name>.md including changelog. See changelog example
  • PR name follows PR naming conventions

Airbyter

If this is a community PR, the Airbyte engineer reviewing this PR is responsible for the below items.

  • Create a non-forked branch based on this PR and test the below items on it
  • Build is successful
  • If new credentials are required for use in CI, add them to GSM. Instructions.
  • /test connector=connectors/<name> command is passing
  • New Connector version released on Dockerhub and connector version bumped by running the /publish command described here
Connector Generator
  • Issue acceptance criteria met
  • PR name follows PR naming conventions
  • If adding a new generator, add it to the list of scaffold modules being tested
  • The generator test modules (all connectors with -scaffold in their name) have been updated with the latest scaffold by running ./gradlew :airbyte-integrations:connector-templates:generator:testScaffoldTemplates then checking in your changes
  • Documentation which references the generator is updated as needed

Tests

Unit

Put your unit tests output here.

Integration

Put your integration tests output here.

Acceptance

Put your acceptance tests output here.

@github-actions github-actions bot added the area/connectors Connector related issues label Jun 1, 2022
@yurii-bidiuk yurii-bidiuk force-pushed the bidiuk/11953-src-postgres-hstore-support branch from 4c60f62 to 51cf252 Compare June 1, 2022 07:14
@yurii-bidiuk
Copy link
Contributor Author

yurii-bidiuk commented Jun 1, 2022

/test connector=connectors/source-postgres

🕑 connectors/source-postgres https://github.com/airbytehq/airbyte/actions/runs/2419890300
✅ connectors/source-postgres https://github.com/airbytehq/airbyte/actions/runs/2419890300
No Python unittests run

Build Passed

Test summary info:

All Passed

Comment on lines 79 to 85
if (resultSet.getString(colIndex) == null) {
json.putNull(columnName);
} else if (columnTypeName.equalsIgnoreCase("hstore")) {
putHstoreAsJson(json, columnName, resultSet, colIndex);
} else if (columnTypeName.equalsIgnoreCase("bool") || columnTypeName.equalsIgnoreCase("boolean")) {
putBoolean(json, columnName, resultSet, colIndex);
} else if (columnTypeName.equalsIgnoreCase("bytea")) {
Copy link
Contributor

Choose a reason for hiding this comment

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

@yurii-bidiuk refactor this to switch, please. See as example https://github.com/airbytehq/airbyte/pull/13166/files

__
sema-logo  Summary: 🛠️ This code needs a fix  |  Tags: Inefficient

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -169,6 +173,12 @@ private void putMoney(final ObjectNode node, final String columnName, final Resu
node.put(columnName, DataTypeUtils.returnNullIfInvalid(() -> Double.valueOf(moneyValue), Double::isFinite));
}

private void putHstoreAsJson(final ObjectNode node, final String columnName, final ResultSet resultSet, final int index)
throws SQLException {
HashMap<String, String> data = (HashMap<String, String>) resultSet.getObject(index);
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we sure we won't have ClassCastException here?

__
sema-logo  Summary: ❓ I have a question

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

Copy link
Contributor

@alexandertsukanov alexandertsukanov left a comment

Choose a reason for hiding this comment

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

Left comments, please take a look.

@yurii-bidiuk yurii-bidiuk force-pushed the bidiuk/11953-src-postgres-hstore-support branch 2 times, most recently from 6e5f433 to e24565f Compare June 1, 2022 08:02
Copy link
Contributor

@alexandertsukanov alexandertsukanov left a comment

Choose a reason for hiding this comment

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

__
sema-logo  Summary: 👌 This code looks good

@yurii-bidiuk yurii-bidiuk requested a review from edgao June 1, 2022 12:29
@github-actions github-actions bot added the area/documentation Improvements or additions to documentation label Jun 2, 2022
@yurii-bidiuk yurii-bidiuk force-pushed the bidiuk/11953-src-postgres-hstore-support branch from ecb87b6 to 9b6e2b3 Compare June 2, 2022 07:35
@yurii-bidiuk yurii-bidiuk temporarily deployed to more-secrets June 2, 2022 07:37 Inactive
@alexandr-shegeda alexandr-shegeda marked this pull request as ready for review June 2, 2022 09:52
@yurii-bidiuk yurii-bidiuk force-pushed the bidiuk/11953-src-postgres-hstore-support branch from 9b6e2b3 to 2ea9d94 Compare June 2, 2022 14:33
@yurii-bidiuk yurii-bidiuk temporarily deployed to more-secrets June 2, 2022 14:36 Inactive
@yurii-bidiuk
Copy link
Contributor Author

yurii-bidiuk commented Jun 2, 2022

/publish connector=connectors/source-postgres

🕑 connectors/source-postgres https://github.com/airbytehq/airbyte/actions/runs/2428987691
❌ Failed to publish connectors/source-postgres
❌ Couldn't auto-bump version for connectors/source-postgres

@yurii-bidiuk
Copy link
Contributor Author

@grishick Hi Greg. Publish for this PR is failed, looks like the same issue with timeout as we had before

private void putHstoreAsJson(final ObjectNode node, final String columnName, final ResultSet resultSet, final int index)
throws SQLException {
final var data = resultSet.getObject(index);
node.put(columnName, new Gson().toJson(data));
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick: most of our codebase uses ObjectMapper rather than Gson, e.g.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would be better to declare the object mapper as a static final constant

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

TestDataHolder.builder()
.sourceType("hstore")
.airbyteType(JsonSchemaType.STRING)
.addInsertValues("'\"paperback\" => \"243\",\"publisher\" => \"postgresqltutorial.com\","
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick: these would be a bit more readable using multiline strings:

.addInsertValues("""
"paperback" => ...
""")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@yurii-bidiuk yurii-bidiuk force-pushed the bidiuk/11953-src-postgres-hstore-support branch from 2ea9d94 to 8b23971 Compare June 3, 2022 08:48
@yurii-bidiuk yurii-bidiuk temporarily deployed to more-secrets June 3, 2022 08:50 Inactive
@yurii-bidiuk yurii-bidiuk force-pushed the bidiuk/11953-src-postgres-hstore-support branch from 8b23971 to ce9c9c0 Compare June 6, 2022 10:33
@yurii-bidiuk yurii-bidiuk temporarily deployed to more-secrets June 6, 2022 10:36 Inactive
@yurii-bidiuk yurii-bidiuk force-pushed the bidiuk/11953-src-postgres-hstore-support branch from ce9c9c0 to 918eb71 Compare June 6, 2022 11:17
@yurii-bidiuk yurii-bidiuk force-pushed the bidiuk/11953-src-postgres-hstore-support branch from 918eb71 to 75c3bdf Compare June 6, 2022 11:18
@yurii-bidiuk
Copy link
Contributor Author

yurii-bidiuk commented Jun 6, 2022

/publish connector=connectors/source-postgres

🕑 connectors/source-postgres https://github.com/airbytehq/airbyte/actions/runs/2447396807
🚀 Successfully published connectors/source-postgres
🚀 Auto-bumped version for connectors/source-postgres
✅ connectors/source-postgres https://github.com/airbytehq/airbyte/actions/runs/2447396807

@octavia-squidington-iii octavia-squidington-iii temporarily deployed to more-secrets June 6, 2022 13:01 Inactive
@yurii-bidiuk yurii-bidiuk force-pushed the bidiuk/11953-src-postgres-hstore-support branch from 3ec4441 to 1b58cd5 Compare June 6, 2022 14:42
@yurii-bidiuk yurii-bidiuk merged commit 4b266c1 into master Jun 6, 2022
@yurii-bidiuk yurii-bidiuk deleted the bidiuk/11953-src-postgres-hstore-support branch June 6, 2022 19:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/connectors Connector related issues area/documentation Improvements or additions to documentation connectors/source/postgres
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Different serialization behaviour for Postgres hstore type between normal and CDC sync
7 participants