Skip to content

fix(mysql): handle X-prefix in binary transforms; add binary-to-uuid and binary-to-bytea (#1758) - #1761

Merged
dimitri merged 2 commits into
mainfrom
fix/mysql-binary-hex-prefix
Jul 15, 2026
Merged

dimitri merged 2 commits into
mainfrom
fix/mysql-binary-hex-prefix

Conversation

@dimitri

@dimitri dimitri commented Jul 15, 2026

Copy link
Copy Markdown
Owner

Problem

MySQL BINARY/VARBINARY column values arrive in the v4 pipeline as "X{lowercase hex}" (capital X, no backslash) — produced by convert-mysql-value. Several transform functions were written expecting "\\x{hex}" (backslash-x, PostgreSQL bytea format) and silently mis-handle the X prefix.

Changes

Fix 1 — byte-vector-to-hexstring (clojure/src/pgloader/cast.clj)

Previously only stripped the \\x prefix; now also strips a bare capital-X prefix so uuid columns receive plain lowercase hex without a leading x.

Fix 2 — New binary-to-uuid transform

Converts a MySQL BINARY(16) column (arriving as "X{32 hex chars}") to the canonical hyphenated PostgreSQL uuid form xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.

Fix 3 — New binary-to-bytea transform

Converts a MySQL BINARY/VARBINARY column (arriving as "X{hex}") to the PostgreSQL bytea hex literal "\\x{hex}".

Fix 4 — hex-to-bytea (clojure/src/pgloader/cast.clj)

Added bare X prefix handling to match the other transforms.

Fix 5 — v3 parity (src/utils/transforms.lisp)

Added binary-to-uuid and binary-to-bytea to the CL transforms. v3 receives actual byte vectors (not X-hex strings), so the implementations differ from v4 but produce identical output.

Tests

  • Unit tests: 4 new deftest forms in clojure/test/pgloader/cast_test.clj covering all four fixed/new functions (22 tests, 83 assertions — all pass)
  • E2E: new binary_types table added to the mytest MySQL seed; cast rules added to mytest.load; query 17 verifies the uuid and bytea round-trip

Closes #1758

dimitri added 2 commits July 15, 2026 19:51
…and binary-to-bytea (#1758)

MySQL BINARY/VARBINARY columns arrive in the v4 pipeline as "X{hex}" (capital X,
no backslash). Several transforms checked only for the "\\x" (bytea-style) prefix
and silently left the X in place.

- byte-vector-to-hexstring: also strip bare "X" prefix so uuid columns work
- binary-to-uuid: new transform for BINARY(16) → uuid with canonical hyphen layout
- binary-to-bytea: new transform for BINARY/VARBINARY → bytea "\\x{hex}" format
- hex-to-bytea: also strip bare "X" prefix for robustness
- v3 parity: add binary-to-uuid and binary-to-bytea to transforms.lisp
- tests: unit tests for all four functions; e2e mytest binary_types table
… expected files

binary_types sorts before bit_defaults (binary < bit_d).
17-binary-types.out header needs trailing spaces to match psql output width.
@dimitri
dimitri merged commit 5ce3726 into main Jul 15, 2026
38 checks passed
@dimitri
dimitri deleted the fix/mysql-binary-hex-prefix branch July 15, 2026 18:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

byte-vector-to-hexstring don't strip leading "x"

1 participant