Add varbinary-to-inet transform for MySQL VARBINARY IP addresses (#1757) - #1760
Merged
Merged
Conversation
MySQL stores IPv4 as 4-byte and IPv6 as 16-byte VARBINARY columns.
Without a transform, pgloader v4 emits the raw hex string (e.g.
"X7fffffff") which PostgreSQL rejects when the target column is inet.
v4 (Clojure):
- Add varbinary-to-inet to transforms.clj; accepts the "X"+hex string
that convert-mysql-value produces for binary columns, strips the prefix,
parses the bytes, and delegates to java.net.InetAddress/getByAddress
which handles both 4-byte (IPv4) and 16-byte (IPv6) inputs natively.
- Add unit tests covering nil, empty ("X"), IPv4, and IPv6 cases.
v3 (Common Lisp):
- Add varbinary-to-inet to transforms.lisp; accepts a byte vector
directly from qmynd (4 bytes → dotted decimal, 16 bytes → colon
notation, 0 bytes / nil → nil).
mytest end-to-end coverage:
- New ip_addresses table in mytest.sql with IPv4, IPv6, and NULL rows.
- Cast rule in mytest.load: column ip_addresses.ip_raw to inet using
varbinary-to-inet.
- Verification query in sql/16-varbinary-to-inet.sql.
Two string literals in transforms.clj contained raw \x00 bytes that caused git to classify the file as binary. Replace with the Clojure unicode escape \u0000 — semantically identical, ASCII-safe.
…emod; update expected The varbinary-to-inet transform function was implemented in transforms.clj (commit 8b2ac12) but was never registered in cast.clj's registry map. apply-cast() looks up transform keywords in the registry; without the entry it silently passed the raw X-hex string through to PostgreSQL, causing: ERROR: invalid input syntax for type inet: "X7f000001" Fixes: - cast.clj: add varbinary-to-inet function + :varbinary-to-inet registry entry - cast_test.clj: unit tests for the function, apply-cast, and resolve-specs - mytest.load: add 'drop typemod' to the column cast rule (VARBINARY(16) typemod would otherwise become inet(16) which PostgreSQL rejects) - build.clj: exclude META-INF/LICENSE directory entry from uber JAR (fixes build failure when azure-identity JARs include it as a directory) - expected/: regenerated 01-tables, 03-indexes, 12-pkeys for new ip_addresses table; add 16-varbinary-to-inet.out with all 5 rows including IPv4 and IPv6
The v3 regression variant (--variant v3) checks *.v3.out files
separately from the v4 *.out files. These three were not updated when
the ip_addresses table was added in the main varbinary-to-inet commit.
- 01-tables.v3.out: add ip_addresses, 33→34 rows
- 03-indexes.v3.out: add one idx_{oid}_PRIMARY, 39→40 rows
- 12-pkeys.v3.out: pk_constraints 27→28, total_indexes 39→40
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.
Closes #1757.
Problem
MySQL stores IPv4 addresses as
VARBINARY(4)and IPv6 asVARBINARY(16)raw binary. Without a transform pgloader v4 emits the hex-escaped form (e.g.X7fffffff) which PostgreSQL rejects when the target column type isinet.Solution
Add a
varbinary-to-inettransform function to both v3 and v4.v4 (Clojure —
clojure/src/pgloader/transforms.clj)Accepts the
"X" + lowercase-hexstring thatconvert-mysql-valuealready produces forbyte[]columns, strips the prefix, parses the bytes into abyte[], and callsjava.net.InetAddress/getByAddress— which handles both 4-byte (IPv4) and 16-byte (IPv6) natively. Returnsnilfor null or empty input.v3 (Common Lisp —
src/utils/transforms.lisp)Accepts the byte vector that qmynd returns directly. Maps 4 bytes → dotted-decimal string, 16 bytes → colon-notation, 0 bytes / nil → nil.
Usage
Test coverage
transforms_test.clj— nil, empty ("X"), IPv4 cases, IPv6 case.ip_addressestable with IPv4, IPv6, and NULL rows; cast rule inmytest.load; verification query insql/16-varbinary-to-inet.sql.