Binary to string mappings - #4179
Draft
sm745052 wants to merge 7 commits into
Draft
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #4179 +/- ##
============================================
+ Coverage 55.90% 61.90% +6.00%
+ Complexity 7475 3452 -4023
============================================
Files 1134 580 -554
Lines 70135 34860 -35275
Branches 8014 3878 -4136
============================================
- Hits 39207 21581 -17626
+ Misses 28381 12167 -16214
+ Partials 2547 1112 -1435
🚀 New features to boost your workflow:
|
…ctations for hex encoding
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR fixes data corruption issues when mapping source database binary and bit types to Spanner
STRINGcolumns, and ensures they successfully round-trip during reverse migrations.The Problem
Previously, when forward migrating binary/blob/bit data into a Spanner
STRINGcolumn, the pipeline was calling.toString()on the underlying JavaByteBuffer. This destroyed the actual binary data by inserting literal Java memory references (e.g.,"java.nio.HeapByteBuffer[pos=0 lim=5 cap=5]") into Spanner. Consequently, reverse migrations back to the source database were completely broken, and the related integration tests were commented out or ignored.The Fix
1. Forward Migrations (
AvroToValueMapper.java)ByteBufferandbyte[]types before they are cast to strings.2. Reverse Migrations (DML Generators)
MySQLDMLGeneratorto detect when a Spanner string is being mapped back to abloborbinarycolumn. It now wraps the generated value in theUNHEX()function (e.g.,UNHEX('7835383030')) to natively restore the raw bytes.PostgreSQLDMLGeneratorto map hex-encoded Spanner strings back tobyteaby wrapping the output in thedecode(..., 'hex')function.BITandVARBITarrays correctly map to strings and migrate back to their native representations without issue.3. Integration Tests
MySQLDataTypesIT,PostgreSQLDataTypesIT, andSpannerToMySqlDataTypesIT.