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

Use parse base64Binary to parse binary related data #32610

Merged
merged 26 commits into from
Nov 30, 2023
Merged

Conversation

xiaohansong
Copy link
Contributor

@xiaohansong xiaohansong commented Nov 16, 2023

Fix for
https://github.com/airbytehq/oncall/issues/3079
#31311

Rational is

we treat all binary in JDBC as String in discover according to this line:

case BLOB, BINARY, VARBINARY, LONGVARBINARY -> JsonSchemaType.STRING_BASE_64;

And we are reading it assuming the value is hex: https://github.com/airbytehq/airbyte/blob/da32fc86bf6450b4d02d4cc9e5f761b80529255a[…]airbyte/cdk/db/jdbc/AbstractJdbcCompatibleSourceOperations.java

Tested on mysql connector locally. However this will take effect on all JDBC source connectors too.

Logs output. Please confirm we are going to output base64 encoded string for binary typed columns.

2023-11-16 17:26:26 destination > INFO i.a.i.d.e.l.FirstNLogger(log):27 [2023-11-16T17:25:31.806Z] Users #0001: {"id":"n61enu/ftEkAAAAAAAAAAA==","name":"Alice Smith","email":"alice.smith@example.com","_ab_cdc_updated_at":"2023-11-16T17:25:31.806783963Z","_ab_cdc_log_file":"binlog.000002","_ab_cdc_log_pos":991,"_ab_cdc_deleted_at":null,"_ab_cdc_cursor":170015553100000001}

What

Describe what the change is solving
It helps to add screenshots if it affects the frontend.

How

Describe the solution

Recommended reading order

  1. x.java
  2. y.python

🚨 User Impact 🚨

Are there any breaking changes? What is the end result perceived by the user?

For connector PRs, use this section to explain which type of semantic versioning bump occurs as a result of the changes. Refer to our Semantic Versioning for Connectors guidelines for more information. Breaking changes to connectors must be documented by an Airbyte engineer (PR author, or reviewer for community PRs) by using the Breaking Change Release Playbook.

If there are breaking changes, please merge this PR with the 🚨🚨 emoji so changelog authors can further highlight this if needed.

Pre-merge Actions

Expand the relevant checklist and delete the others.

New Connector

Community member or Airbyter

  • Community member? Grant edit access to maintainers (instructions)
  • 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.
  • Connector version is set to 0.0.1
    • Dockerfile has version 0.0.1
  • Documentation updated
    • Connector's README.md
    • Connector's bootstrap.md. See description and examples
    • docs/integrations/<source or destination>/<name>.md including changelog with an entry for the initial version. See changelog example
    • docs/integrations/README.md

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.
Updating a connector

Community member or Airbyter

  • Grant edit access to maintainers (instructions)
  • Unit & integration tests added

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.
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:generateScaffolds then checking in your changes
  • Documentation which references the generator is updated as needed
Updating the Python CDK

Airbyter

Before merging:

  • Pull Request description explains what problem it is solving
  • Code change is unit tested
  • Build and my-py check pass
  • Smoke test the change on at least one affected connector
    • On Github: Run this workflow, passing --use-local-cdk --name=source-<connector> as options
    • Locally: airbyte-ci connectors --use-local-cdk --name=source-<connector> test
  • PR is reviewed and approved

After merging:

  • Publish the CDK
    • The CDK does not follow proper semantic versioning. Choose minor if this the change has significant user impact or is a breaking change. Choose patch otherwise.
    • Write a thoughtful changelog message so we know what was updated.
  • Merge the platform PR that was auto-created for updating the Connector Builder's CDK version
    • This step is optional if the change does not affect the connector builder or declarative connectors.

Copy link

vercel bot commented Nov 16, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
airbyte-docs ❌ Failed (Inspect) Nov 30, 2023 6:55pm

@octavia-squidington-iii octavia-squidington-iii added the CDK Connector Development Kit label Nov 16, 2023
@@ -6,7 +6,7 @@ plugins {
airbyteJavaConnector {
cdkVersionRequired = '0.4.1'
features = ['db-sources']
useLocalCdk = false
useLocalCdk = true
Copy link
Contributor

Choose a reason for hiding this comment

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

Remember to toggle these to false and bump ckd version finally

Copy link
Contributor

@akashkulk akashkulk left a comment

Choose a reason for hiding this comment

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

Couple of comments:

  • Let's add a test to MySqlSourceOperationsTest.java
  • This actually only affects cases where binary data is set as the cursor.

The flow is :

  • From the source DB, data is read in via putBinary method, which reads it as Base 64 encoded string
  • Data is saved in the load state, again as a base 64 encoded string
  • Data is parsed while setting the cursor as a hex string, which this pR fixes. Thanks!

But to clarify setting the cursor field is a source connector only setting - this isn't changing what is sent to the destination in the case of a binary field

tolik0 and others added 2 commits November 21, 2023 10:54
Co-authored-by: Alexandre Girard <alexandre@airbyte.io>
@octavia-squidington-iii octavia-squidington-iii added area/documentation Improvements or additions to documentation connectors/source/s3 labels Nov 21, 2023
@octavia-squidington-iii octavia-squidington-iii removed area/connectors Connector related issues area/documentation Improvements or additions to documentation labels Nov 22, 2023
@xiaohansong
Copy link
Contributor Author

xiaohansong commented Nov 22, 2023

@akashkulk I'll add the test in the next PR where we point source connector to the new CDK version (otherwise it won't pass because it's still using old logic to parse out binary)

#32746

@@ -222,7 +222,7 @@ protected void setString(final PreparedStatement preparedStatement, final int pa
}

protected void setBinary(final PreparedStatement preparedStatement, final int parameterIndex, final String value) throws SQLException {
preparedStatement.setBytes(parameterIndex, DatatypeConverter.parseHexBinary(value));
preparedStatement.setBytes(parameterIndex, DatatypeConverter.parseBase64Binary(value));
Copy link
Contributor

Choose a reason for hiding this comment

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

Just FYI, this affects other connectors too, since this is shared code. We should understand which connectors this affects - this would be the classes with source operations that inheirit from this and classes that allow BINARY columns as cursors (which I don't think we have more of)

Copy link
Contributor

Choose a reason for hiding this comment

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

I should clarify, no need to publish them - more of a documentation exercise

Copy link
Contributor Author

@xiaohansong xiaohansong Nov 28, 2023

Choose a reason for hiding this comment

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

They are called from postgres and mysql, and general JdbcSourceOperations which is inherited by Teradata, Oracle, Cockroach, Db2, Snowflake, Mssql, Redshift.

Indeed we do not allow binary column as cursor, both in individual SourceOperations(Mysql, Postgres) and general JDBCSourceOperations

public static final Set<JDBCType> ALLOWED_CURSOR_TYPES =

Copy link
Contributor

@akashkulk akashkulk Nov 29, 2023

Choose a reason for hiding this comment

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

cool, good to know - then this shouldn't affect anything for now other than MySQL

@@ -63,6 +69,7 @@ public class MySqlSourceOperations extends AbstractJdbcCompatibleSourceOperation
private static final Logger LOGGER = LoggerFactory.getLogger(MySqlSourceOperations.class);
private static final Set<MysqlType> ALLOWED_CURSOR_TYPES = Set.of(TINYINT, TINYINT_UNSIGNED, SMALLINT,
SMALLINT_UNSIGNED, MEDIUMINT, MEDIUMINT_UNSIGNED, INT, INT_UNSIGNED, BIGINT, BIGINT_UNSIGNED,
TINYBLOB, BLOB, MEDIUMBLOB, LONGBLOB, BINARY, VARBINARY,
Copy link
Contributor

@akashkulk akashkulk Nov 28, 2023

Choose a reason for hiding this comment

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

As discussed yesterday, we should not allow BINARY as a cursor type, since it's hard for the user to make sure that this value is increasing (hallmark of a good cursor)

We mainly use it for the initial load (where we checkpoint by PK for the user), so I think we can exclude it here

@@ -11,7 +11,7 @@ data:
connectorSubtype: database
connectorType: source
definitionId: 435bb9a5-7887-4809-aa58-28c27df0d7ad
dockerImageTag: 3.1.8
dockerImageTag: 3.1.10
Copy link
Contributor

Choose a reason for hiding this comment

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

Why 3.1.10 instead of 3.1.9?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

3.1.9 was used by my previous PR (The one to extend debezium schema loading time)

Copy link
Contributor

@akashkulk akashkulk left a comment

Choose a reason for hiding this comment

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

Looks good in general - some very minor nits. Approving to unblock!! FYI - I bumped the CDK to 0.5.3....so you're going to have to use 0.5.4

@xiaohansong
Copy link
Contributor Author

xiaohansong commented Nov 29, 2023

/publish-java-cdk

🕑 https://github.com/airbytehq/airbyte/actions/runs/7038943992
✅ Successfully published Java CDK version=0.5.4!

@xiaohansong xiaohansong merged commit 2d26337 into master Nov 30, 2023
22 of 23 checks passed
@xiaohansong xiaohansong deleted the xiaohan/parse branch November 30, 2023 19:05
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.

None yet

4 participants