Skip to content

fix: normalize postgres UUIDs to strings - #3806

Open
emagda97 wants to merge 2 commits into
googleapis:mainfrom
emagda97:main
Open

fix: normalize postgres UUIDs to strings#3806
emagda97 wants to merge 2 commits into
googleapis:mainfrom
emagda97:main

Conversation

@emagda97

@emagda97 emagda97 commented Aug 11, 2026

Copy link
Copy Markdown
Collaborator

Description

Fixes a bug where PostgreSQL UUID columns were being serialized as numerical arrays (e.g., [1, 158, 103, ...]) in JSON output instead of standard hyphenated strings.

Root Cause
The generic results.Values() method in the pgx driver returns UUIDs as [16]byte fixed arrays. Go's standard encoding/json package serializes fixed arrays of bytes as numerical arrays rather than strings.

Solution
Introduced a centralized NormalizeValue helper function in internal/sources/util.go that intercepts values based on their PostgreSQL Object Identifier (OID). If it detects a UUID OID (2950) and a [16]byte type, it converts it into a standard UUID string via the github.com/google/uuid package.

Impact
Consistent string serialization for UUIDs across all Postgres-compatible drivers (postgres, alloydb-postgres, cloud-sql-postgres, yugabytedb). Added unit tests to internal/sources/util_test.go to guarantee reliability.

PR Checklist

  • Make sure you reviewed CONTRIBUTING.md
  • Make sure to open an issue as a bug/issue before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)
  • Make sure to add ! if this involve a breaking change

🛠️ Fixes #3795

@google-cla

google-cla Bot commented Aug 11, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a NormalizeValue utility function to convert PostgreSQL UUID values (OID 2950) from [16]byte to their string representation, applying it across AlloyDB, Cloud SQL Postgres, Postgres, and YugabyteDB sources. It also adds corresponding unit tests. The review feedback suggests extending this normalization to support PostgreSQL UUID arrays (OID 2951) and provides the necessary code and test cases to implement this improvement.

Comment thread internal/sources/util.go
Comment thread internal/sources/util_test.go
@emagda97
emagda97 force-pushed the main branch 5 times, most recently from db72f9f to 8aad0bf Compare August 11, 2026 20:49
@emagda97
emagda97 requested a review from Yuan325 August 11, 2026 21:27
@emagda97
emagda97 marked this pull request as ready for review August 11, 2026 21:34
@emagda97
emagda97 requested review from a team as code owners August 11, 2026 21:34
@emagda97 emagda97 changed the title Normalize postgres UUIDs to strings fix: normalize postgres UUIDs to strings Aug 11, 2026
@emagda97
emagda97 marked this pull request as draft August 11, 2026 22:02
@emagda97
emagda97 marked this pull request as ready for review August 12, 2026 21:12
@emagda97
emagda97 force-pushed the main branch 3 times, most recently from f941889 to bc3e155 Compare August 14, 2026 19:53
@emagda97

Copy link
Copy Markdown
Collaborator Author

also included some Zizmor workflow fixes under .github because the presubmit tests were failing.

TAG=agy

CONV=4ebccd78-3deb-4d92-b29e-6b1a36f2308a
TAG=agy

CONV=08322a1d-4754-4ca9-ae73-4e91bf2b280c
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.

UUIDv7 serialized to Array of numbers.

2 participants