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 base64 to encode mssql binary field #33755

Merged
merged 11 commits into from
Jan 4, 2024
Merged

Conversation

xiaohansong
Copy link
Contributor

@xiaohansong xiaohansong commented Dec 22, 2023

What

#19337

Since airbyte transport everything in Json, binary was converted into String using default char set - thus for many cases they are not converted into a human readable string and cause confusion. Currently we did not specify how airbyte is going to handle binary in our official doc; so I propose we encode that in base64.

Slack discussion: https://airbytehq-team.slack.com/archives/C03C4AVJWG4/p1700173565688209

Result:
before:


2023-12-22 00:03:54 INFO i.a.w.g.BufferedReplicationWorker(writeToDestination):424 - writeToDestination: done. (forDest.isDone:true, isDestRunning:true)
2023-12-22 00:03:54 destination > INFO i.a.i.d.e.l.FirstNLogger(log):27 [2023-12-22T00:03:50.862Z] NewTable #0001: {"id":"2","bin":"\u0003\u0001Ȋ��\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000"}
2023-12-22 00:03:54 destination > INFO i.a.i.d.e.l.FirstNLogger(log):27 [2023-12-22T00:03:50.862Z] NewTable #0002: {"id":"12","bin":" 3\u0001Ȋ��\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000"}

===
after:


2023-12-22 19:34:29 destination > INFO i.a.i.d.e.l.FirstNLogger(log):27 [2023-12-22T19:34:24.674Z] NewTable #0001: {"id":"2","bin":"AwHIit3vAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=="}
2023-12-22 19:34:29 destination > INFO i.a.i.d.e.l.FirstNLogger(log):27 [2023-12-22T19:34:24.674Z] NewTable #0002: {"id":"12","bin":"IDMByIrd7wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=="}

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.

@xiaohansong xiaohansong requested a review from a team as a code owner December 22, 2023 19:39
Copy link

vercel bot commented Dec 22, 2023

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

1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
airbyte-docs ⬜️ Ignored (Inspect) Visit Preview Jan 4, 2024 0:02am

@octavia-squidington-iii octavia-squidington-iii added the area/connectors Connector related issues label Dec 22, 2023
Copy link
Contributor

github-actions bot commented Dec 22, 2023

Warning

🚨 Connector code freeze is in effect until 2024-01-02. This PR is changing connector code. Please contact the current OC engineers if you want to merge this change to master.

Copy link
Contributor

github-actions bot commented Dec 22, 2023

Before Merging a Connector Pull Request

Wow! What a great pull request you have here! 🎉

To merge this PR, ensure the following has been done/considered for each connector added or updated:

  • PR name follows PR naming conventions
  • Breaking changes are considered. If a Breaking Change is being introduced, ensure an Airbyte engineer has created a Breaking Change Plan.
  • Connector version has been incremented in the Dockerfile and metadata.yaml according to our Semantic Versioning for Connectors guidelines
  • You've updated the connector's metadata.yaml file any other relevant changes, including a breakingChanges entry for major version bumps. See metadata.yaml docs
  • Secrets in the connector's spec are annotated with airbyte_secret
  • All documentation files are up to date. (README.md, bootstrap.md, docs.md, etc...)
  • Changelog updated in docs/integrations/<source or destination>/<name>.md with an entry for the new version. See changelog example
  • Migration guide updated in docs/integrations/<source or destination>/<name>-migrations.md with an entry for the new version, if the version is a breaking change. See migration guide example
  • If set, you've ensured the icon is present in the platform-internal repo. (Docs)

If the checklist is complete, but the CI check is failing,

  1. Check for hidden checklists in your PR description

  2. Toggle the github label checklist-action-run on/off to re-run the checklist CI.

Copy link
Contributor

@rodireich rodireich left a comment

Choose a reason for hiding this comment

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

This looks good.
But how is it helping with the mentioned issue of 6GB updates failing?

@@ -128,7 +129,7 @@ protected void putBinary(final ObjectNode node,
final int index)
throws SQLException {
final byte[] bytes = resultSet.getBytes(index);
final String value = new String(bytes, Charset.defaultCharset());
final String value = Base64.encodeBase64String(bytes);
Copy link
Contributor

Choose a reason for hiding this comment

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

this I think is in line with what we do in other java connectors 👍

Copy link
Contributor

Choose a reason for hiding this comment

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

You can add a test also for binary type

Copy link
Contributor

Choose a reason for hiding this comment

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

Does that mean that a binary field in the source database is encoded as a AirbyteType String? Is that something that was discussed, or just how it was implemented for simplicity reasons?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the current behavior for binary column is undefined in our public doc (and see slack discussion with destination team here https://airbytehq-team.slack.com/archives/C03C4AVJWG4/p1700173565688209), it sounds like base64 is the direction we are heading to; so yes mostly for simplicity reason.

@xiaohansong
Copy link
Contributor Author

@rodireich Apologize! I linked the wrong ticket. This is the one. Updated #19337

@xiaohansong
Copy link
Contributor Author

I'll have to update version after code freeze to avoid any confliction!

@octavia-squidington-iii octavia-squidington-iii added the area/documentation Improvements or additions to documentation label Jan 2, 2024
@xiaohansong xiaohansong changed the title Use base64 to encode mssql binary field ✨Use base64 to encode mssql binary field Jan 2, 2024
@xiaohansong xiaohansong requested a review from rodireich January 2, 2024 19:00
Copy link
Contributor

@rodireich rodireich left a comment

Choose a reason for hiding this comment

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

Change looks good.
I just wanted to understand for myself if mssql is different from mysql and postgres where I think we're doing specific type conversions.

@xiaohansong xiaohansong merged commit 609bcb2 into master Jan 4, 2024
23 checks passed
@xiaohansong xiaohansong deleted the xiaohan/binaryencode branch January 4, 2024 00:32
jatinyadav-cc pushed a commit to ollionorg/datapipes-airbyte that referenced this pull request Feb 26, 2024
jatinyadav-cc pushed a commit to ollionorg/datapipes-airbyte that referenced this pull request Feb 26, 2024
@sukolenvo
Copy link

I fully support this change (this solves other issue that we had: #30856). But from my POV this is a breaking change? My view of the situation:
For sample byte array [0x68, 0x65, 0x6c, 0x6c, 0x6f]
Previously message json was:

{
  "my-byte-array": "hello"
}

In destination connector we were using json.get("my-byte-array").getBytes() to get original byte array.

Now json is

{
  "my-byte-array": "aGVsbG8="
}

same destination connector would save array [0x61, 0x46, 0x56, 0x73, 0x62, 0x47, 0x38, 0x3d, 0x0a].

So necessary steps for upgrade are:

  1. stop source connector;
  2. let destination drain queue;
  3. deploy new destination connector that decodes using Base64.decode() instead of String.getBytes();
  4. update source connector to new version.

Which is non-trivial upgrade process typically expected for patch. Am I missing something?

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/mssql
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants