Skip to content

Comments

feat(dv): visitor pattern hashing utilities#3377

Merged
manitgupta merged 2 commits intomainfrom
dv-3-hashing-utilities
Feb 19, 2026
Merged

feat(dv): visitor pattern hashing utilities#3377
manitgupta merged 2 commits intomainfrom
dv-3-hashing-utilities

Conversation

@manitgupta
Copy link
Member

@manitgupta manitgupta commented Feb 19, 2026

TL;DR

Implemented a Visitor pattern for Spanner Value types to improve code maintainability and reduce duplication.

What changed?

Added three new classes to implement the Visitor pattern for Spanner Value types:

  1. IUnifiedVisitor - Interface defining visit methods for each Spanner data type with a static dispatch method to route values to the appropriate visitor method.

  2. UnifiedHasherVisitor - Implementation that hashes Spanner values using a provided Hasher, with careful handling of null values and type-specific encoding.

  3. UnifiedStringVisitor - Implementation that converts Spanner values to their string representation.

Added comprehensive unit tests for both visitor implementations to verify correct behavior for all Spanner data types.

How to test?

Added tests for the Visitor classes.

  1. UnifiedHasherVisitorTest - Tests the hashing logic.
  2. UnifiedStringVisitorTest - Tests the string conversion logic.
  3. IUnifiedVisitorTest - Tests the dispatch logic.

@gemini-code-assist
Copy link

Summary of Changes

Hello @manitgupta, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a robust visitor pattern for Spanner Value types, enabling flexible and extensible operations such as hashing and string conversion. This architectural improvement streamlines code by centralizing type-specific logic, reducing boilerplate, and enhancing maintainability for future data processing tasks.

Highlights

  • Visitor Pattern Implementation: Introduced a new IUnifiedVisitor interface to apply the visitor pattern for handling various Spanner Value types, decoupling operations from the data structure.
  • Hashing Utility: Added UnifiedHasherVisitor, an implementation of IUnifiedVisitor, to provide a consistent mechanism for hashing different Spanner Value types, including handling nulls and ensuring collision avoidance.
  • String Conversion Utility: Implemented UnifiedStringVisitor, another IUnifiedVisitor implementation, to convert diverse Spanner Value types into their string representations.
  • Comprehensive Testing: Included dedicated unit tests for both UnifiedHasherVisitor and UnifiedStringVisitor to ensure the correctness and reliability of the new visitor implementations across all supported Spanner data types.
Changelog
  • v2/gcs-spanner-dv/src/main/java/com/google/cloud/teleport/v2/visitor/IUnifiedVisitor.java
    • Added a new interface IUnifiedVisitor that defines methods for visiting different Spanner Value types.
    • Included a static dispatch method to route Spanner Value instances to the appropriate visitor method.
    • Provided a static formatDate utility method for consistent date formatting.
  • v2/gcs-spanner-dv/src/main/java/com/google/cloud/teleport/v2/visitor/UnifiedHasherVisitor.java
    • Added a new class UnifiedHasherVisitor that implements IUnifiedVisitor to hash Spanner values.
    • Implemented specific hashing logic for various data types (String, Int64, Float64, Bool, Bytes, Date, Numeric, Timestamp, Json) using a Hasher.
    • Introduced sentinel bytes to differentiate between null and non-null values and to prevent hash collisions.
  • v2/gcs-spanner-dv/src/main/java/com/google/cloud/teleport/v2/visitor/UnifiedStringVisitor.java
    • Added a new class UnifiedStringVisitor that implements IUnifiedVisitor to convert Spanner values to their string representations.
    • Provided methods to convert various Spanner data types into strings, including Base64 encoding for byte arrays and specific formatting for dates and timestamps.
  • v2/gcs-spanner-dv/src/test/java/com/google/cloud/teleport/v2/visitor/UnifiedHasherVisitorTest.java
    • Added unit tests for UnifiedHasherVisitor to verify the correctness of hashing for all supported Spanner value types.
    • Tests cover string length, sentinel bytes, and accurate hash generation for each data type, including nulls.
  • v2/gcs-spanner-dv/src/test/java/com/google/cloud/teleport/v2/visitor/UnifiedStringVisitorTest.java
    • Added unit tests for UnifiedStringVisitor to ensure accurate string conversion for all supported Spanner value types.
    • Tests validate the output string for various data types, including empty strings for nulls and Base64 encoding for bytes.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@codecov
Copy link

codecov bot commented Feb 19, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 56.69%. Comparing base (d116909) to head (b65badc).
⚠️ Report is 5 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #3377      +/-   ##
============================================
+ Coverage     51.04%   56.69%   +5.64%     
+ Complexity     5211     1747    -3464     
============================================
  Files           994      474     -520     
  Lines         60723    27066   -33657     
  Branches       6657     2883    -3774     
============================================
- Hits          30997    15345   -15652     
+ Misses        27546    10800   -16746     
+ Partials       2180      921    -1259     
Components Coverage Δ
spanner-templates 71.94% <ø> (+1.09%) ⬆️
spanner-import-export ∅ <ø> (∅)
spanner-live-forward-migration 79.84% <ø> (ø)
spanner-live-reverse-replication 77.37% <ø> (ø)
spanner-bulk-migration 87.99% <ø> (ø)
gcs-spanner-dv 85.75% <ø> (ø)
see 540 files with indirect coverage changes
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@manitgupta manitgupta marked this pull request as ready for review February 19, 2026 05:04
@manitgupta manitgupta requested a review from a team as a code owner February 19, 2026 05:04
Copy link
Contributor

@darshan-sj darshan-sj left a comment

Choose a reason for hiding this comment

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

LGTM

@manitgupta manitgupta merged commit 844f3fc into main Feb 19, 2026
18 checks passed
@manitgupta manitgupta deleted the dv-3-hashing-utilities branch February 19, 2026 05:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants