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: Handle Arrays data types #16990

Merged
merged 26 commits into from
Nov 28, 2022

Conversation

VitaliiMaltsev
Copy link
Contributor

@VitaliiMaltsev VitaliiMaltsev commented Sep 21, 2022

What

At the moment, when emitting data of the array type, a json schema is formed that looks like an array without items, and the data is transferred simply as a string. this can lead to incorrect data transfer and also some types of arrays are not implemented at all

{
  "type": "array"
}

Data type handling should be able to handle all data types that Postgres supports

How

Updated mapping of all types of arrays for json schema, implemented conversion for СDС and STANDARD replication
Example

BIT[]  ==> 
{
  "type": "array",
  "items": {
    "type": "boolean"
  }
}

VARCHAR[] ==>
{
  "type": "array",
  "items": {
    "type": "string"
  }
}

Recommended reading order

  1. JsonSchemaType.java
  2. PostgresSourceOperations.java
  3. PostgresConverter.java

🚨 User Impact 🚨

There should not be any user impact

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/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
Copy link
Contributor

NOTE ⚠️ Changes in this PR affect the following connectors. Make sure to run corresponding integration tests:

  • source-alloydb
  • source-postgres-strict-encrypt
  • source-alloydb-strict-encrypt

@github-actions
Copy link
Contributor

github-actions bot commented Oct 3, 2022

NOTE ⚠️ Changes in this PR affect the following connectors. Make sure to run corresponding integration tests:

  • source-alloydb-strict-encrypt
  • source-alloydb
  • source-postgres-strict-encrypt

@VitaliiMaltsev VitaliiMaltsev temporarily deployed to more-secrets October 3, 2022 07:36 Inactive
@github-actions
Copy link
Contributor

github-actions bot commented Oct 7, 2022

NOTE ⚠️ Changes in this PR affect the following connectors. Make sure to run corresponding integration tests:

  • source-cockroachdb
  • source-oracle
  • source-redshift
  • source-mssql-strict-encrypt
  • source-alloydb
  • source-clickhouse
  • source-oracle-strict-encrypt
  • source-clickhouse-strict-encrypt
  • source-mongodb-v2
  • source-postgres-strict-encrypt
  • source-postgres
  • source-elasticsearch
  • source-mysql-strict-encrypt
  • source-alloydb-strict-encrypt
  • source-cockroachdb-strict-encrypt
  • source-kafka
  • source-e2e-test
  • source-db2
  • source-tidb
  • source-bigquery
  • source-snowflake
  • source-mysql
  • source-db2-strict-encrypt
  • source-sftp
  • source-mongodb-strict-encrypt
  • source-e2e-test-cloud
  • source-jdbc
  • source-scaffold-java-jdbc
  • source-mssql

@VitaliiMaltsev VitaliiMaltsev temporarily deployed to more-secrets October 7, 2022 06:03 Inactive
@github-actions
Copy link
Contributor

NOTE ⚠️ Changes in this PR affect the following connectors. Make sure to run corresponding integration tests:

  • source-e2e-test
  • source-tidb
  • source-scaffold-java-jdbc
  • source-bigquery
  • source-clickhouse-strict-encrypt
  • source-elasticsearch
  • source-clickhouse
  • source-postgres-strict-encrypt
  • source-db2-strict-encrypt
  • source-mysql
  • source-postgres
  • source-mysql-strict-encrypt
  • source-snowflake
  • source-alloydb
  • source-oracle
  • source-mssql-strict-encrypt
  • source-jdbc
  • source-mongodb-v2
  • source-kafka
  • source-alloydb-strict-encrypt
  • source-mssql
  • source-redshift
  • source-cockroachdb-strict-encrypt
  • source-cockroachdb
  • source-db2
  • source-e2e-test-cloud
  • source-oracle-strict-encrypt
  • source-sftp
  • source-mongodb-strict-encrypt

@VitaliiMaltsev VitaliiMaltsev temporarily deployed to more-secrets October 10, 2022 11:25 Inactive
@github-actions
Copy link
Contributor

NOTE ⚠️ Changes in this PR affect the following connectors. Make sure to run corresponding integration tests:

  • source-db2
  • source-clickhouse-strict-encrypt
  • source-postgres
  • source-scaffold-java-jdbc
  • source-bigquery
  • source-mssql-strict-encrypt
  • source-cockroachdb
  • source-elasticsearch
  • source-mysql
  • source-e2e-test-cloud
  • source-snowflake
  • source-mongodb-strict-encrypt
  • source-kafka
  • source-postgres-strict-encrypt
  • source-tidb
  • source-clickhouse
  • source-sftp
  • source-redshift
  • source-oracle
  • source-db2-strict-encrypt
  • source-mongodb-v2
  • source-mysql-strict-encrypt
  • source-mssql
  • source-oracle-strict-encrypt
  • source-cockroachdb-strict-encrypt
  • source-alloydb-strict-encrypt
  • source-alloydb
  • source-jdbc
  • source-e2e-test

@VitaliiMaltsev VitaliiMaltsev temporarily deployed to more-secrets October 10, 2022 11:28 Inactive
@github-actions
Copy link
Contributor

NOTE ⚠️ Changes in this PR affect the following connectors. Make sure to run corresponding integration tests:

  • source-elasticsearch
  • source-kafka
  • source-postgres-strict-encrypt
  • source-alloydb
  • source-mysql-strict-encrypt
  • source-clickhouse-strict-encrypt
  • source-db2
  • source-mongodb-strict-encrypt
  • source-db2-strict-encrypt
  • source-clickhouse
  • source-mssql
  • source-mysql
  • source-bigquery
  • source-sftp
  • source-jdbc
  • source-mssql-strict-encrypt
  • source-postgres
  • source-e2e-test
  • source-oracle-strict-encrypt
  • source-e2e-test-cloud
  • source-cockroachdb-strict-encrypt
  • source-scaffold-java-jdbc
  • source-tidb
  • source-mongodb-v2
  • source-oracle
  • source-snowflake
  • source-redshift
  • source-alloydb-strict-encrypt
  • source-cockroachdb

@VitaliiMaltsev VitaliiMaltsev temporarily deployed to more-secrets October 10, 2022 11:46 Inactive
@github-actions
Copy link
Contributor

NOTE ⚠️ Changes in this PR affect the following connectors. Make sure to run corresponding integration tests:

  • source-redshift
  • source-postgres-strict-encrypt
  • source-sftp
  • source-db2
  • source-mssql
  • source-clickhouse
  • source-snowflake
  • source-alloydb-strict-encrypt
  • source-db2-strict-encrypt
  • source-e2e-test
  • source-cockroachdb
  • source-mongodb-v2
  • source-cockroachdb-strict-encrypt
  • source-oracle-strict-encrypt
  • source-mysql-strict-encrypt
  • source-tidb
  • source-postgres
  • source-scaffold-java-jdbc
  • source-oracle
  • source-clickhouse-strict-encrypt
  • source-jdbc
  • source-mssql-strict-encrypt
  • source-e2e-test-cloud
  • source-mongodb-strict-encrypt
  • source-alloydb
  • source-bigquery
  • source-kafka
  • source-mysql
  • source-elasticsearch

…rray-types' into vmaltsev/15157-postgres-handle-array-types
Copy link
Contributor

@subodh1810 subodh1810 left a comment

Choose a reason for hiding this comment

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

We are almost there! @edgao can you clarify how the new items attribute in the json schema will be used downstream?

return Arrays.stream(values).map(value -> value == null ? null : convertToTimestamp(value)).collect(Collectors.toList());
case "_TIMESTAMPTZ":
return Arrays.stream(values).map(value -> value == null ? null : convertToTimestampWithTimezone(value)).collect(Collectors.toList());
case "_TIMETZ":
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's add this logic to method convertToTimeWithTimezone in class DateTimeConverter and add a condition like

if (time instanceof final java.sql.Time timetz) then do what you are doing

@@ -23,6 +23,7 @@ public class JsonSchemaType {
public static final String CONTENT_ENCODING = "contentEncoding";
public static final String BASE_64 = "base64";
public static final String AIRBYTE_TYPE = "airbyte_type";
public static final String ITEMS = "items";
Copy link
Contributor

Choose a reason for hiding this comment

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

I meant will this be used in downstream in normalization?

@edgao ^

node.set(columnName, arrayNode);
}

private void putTimestampTzArray(ObjectNode node, String columnName, ResultSet resultSet, int colIndex) throws SQLException {
Copy link
Contributor

Choose a reason for hiding this comment

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

this got left out

@github-actions
Copy link
Contributor

github-actions bot commented Nov 8, 2022

Affected Connector Report

NOTE ⚠️ Changes in this PR affect the following connectors. Make sure to do the following as needed:

  • Run integration tests
  • Bump connector or module version
  • Add changelog
  • Publish the new version

❌ Sources (30)

Connector Version Changelog Publish
source-alloydb 1.0.17
source-alloydb-strict-encrypt 1.0.17
(not in seed)
source-bigquery 0.2.3
source-clickhouse 0.1.14
source-clickhouse-strict-encrypt 0.1.14
(not in seed)
source-cockroachdb 0.1.18
source-cockroachdb-strict-encrypt 0.1.18
(not in seed)
source-db2 0.1.16
source-db2-strict-encrypt 0.1.16
(not in seed)
source-dynamodb 0.1.0
(changelog missing)
source-e2e-test 2.1.3
source-e2e-test-cloud 2.1.1
(doc not found)

(not in seed)
source-elasticsearch 0.1.0
source-jdbc 0.3.5
(doc not found)

(not in seed)
source-kafka 0.2.2
source-mongodb-strict-encrypt 0.1.19
(doc not found)

(not in seed)
source-mongodb-v2 0.1.19
source-mssql 0.4.25
source-mssql-strict-encrypt 0.4.25
(not in seed)
source-mysql 1.0.13
source-mysql-strict-encrypt 1.0.13
(not in seed)
source-oracle 0.3.21
source-oracle-strict-encrypt 0.3.21
(not in seed)
source-postgres 1.0.27
source-postgres-strict-encrypt 1.0.27
(not in seed)
source-redshift 0.3.15
source-scaffold-java-jdbc 0.1.0
(doc not found)

(not in seed)
source-sftp 0.1.2
source-snowflake 0.1.26
source-tidb 0.2.1
  • See "Actionable Items" below for how to resolve warnings and errors.

✅ Destinations (0)

Connector Version Changelog Publish
  • See "Actionable Items" below for how to resolve warnings and errors.

✅ Other Modules (0)

Actionable Items

(click to expand)

Category Status Actionable Item
Version
mismatch
The version of the connector is different from its normal variant. Please bump the version of the connector.

doc not found
The connector does not seem to have a documentation file. This can be normal (e.g. basic connector like source-jdbc is not published or documented). Please double-check to make sure that it is not a bug.
Changelog
doc not found
The connector does not seem to have a documentation file. This can be normal (e.g. basic connector like source-jdbc is not published or documented). Please double-check to make sure that it is not a bug.

changelog missing
There is no chnagelog for the current version of the connector. If you are the author of the current version, please add a changelog.
Publish
not in seed
The connector is not in the seed file (e.g. source_definitions.yaml), so its publication status cannot be checked. This can be normal (e.g. some connectors are cloud-specific, and only listed in the cloud seed file). Please double-check to make sure that it is not a bug.

diff seed version
The connector exists in the seed file, but the latest version is not listed there. This usually means that the latest version is not published. Please use the /publish command to publish the latest version.

@VitaliiMaltsev VitaliiMaltsev temporarily deployed to more-secrets November 8, 2022 09:05 Inactive
Copy link
Contributor

@edgao edgao left a comment

Choose a reason for hiding this comment

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

lgtm, probably worth waiting for @subodh1810's approval before merging

Copy link
Contributor

@subodh1810 subodh1810 left a comment

Choose a reason for hiding this comment

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

Sadly we cant get this out until code freeze is lifted

@VitaliiMaltsev VitaliiMaltsev temporarily deployed to more-secrets November 22, 2022 19:22 Inactive
@VitaliiMaltsev VitaliiMaltsev temporarily deployed to more-secrets November 22, 2022 19:22 Inactive
@VitaliiMaltsev VitaliiMaltsev temporarily deployed to more-secrets November 28, 2022 14:40 Inactive
@VitaliiMaltsev VitaliiMaltsev temporarily deployed to more-secrets November 28, 2022 14:41 Inactive
@octavia-squidington-iv octavia-squidington-iv added the area/documentation Improvements or additions to documentation label Nov 28, 2022
@timroes timroes removed the request for review from a team November 28, 2022 14:49
@VitaliiMaltsev VitaliiMaltsev temporarily deployed to more-secrets November 28, 2022 14:51 Inactive
@VitaliiMaltsev VitaliiMaltsev temporarily deployed to more-secrets November 28, 2022 14:51 Inactive
@VitaliiMaltsev
Copy link
Contributor Author

VitaliiMaltsev commented Nov 28, 2022

/publish connector=connectors/source-postgres-strict-encrypt

🕑 Publishing the following connectors:
connectors/source-postgres-strict-encrypt
https://github.com/airbytehq/airbyte/actions/runs/3565982549


Connector Did it publish? Were definitions generated?
connectors/source-postgres-strict-encrypt

if you have connectors that successfully published but failed definition generation, follow step 4 here ▶️

@VitaliiMaltsev
Copy link
Contributor Author

VitaliiMaltsev commented Nov 28, 2022

/publish connector=connectors/source-postgres

🕑 Publishing the following connectors:
connectors/source-postgres
https://github.com/airbytehq/airbyte/actions/runs/3565985304


Connector Did it publish? Were definitions generated?
connectors/source-postgres

if you have connectors that successfully published but failed definition generation, follow step 4 here ▶️

@octavia-squidington-iii octavia-squidington-iii temporarily deployed to more-secrets November 28, 2022 15:53 Inactive
@octavia-squidington-iii octavia-squidington-iii temporarily deployed to more-secrets November 28, 2022 15:53 Inactive
@VitaliiMaltsev VitaliiMaltsev merged commit d04a01a into master Nov 28, 2022
@VitaliiMaltsev VitaliiMaltsev deleted the vmaltsev/15157-postgres-handle-array-types branch November 28, 2022 15:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Postgres source: verify handling of arrays data types
6 participants