Skip to content

feat: Add SQL Server CDC support to Datastream-to-BigQuery template#3450

Open
mahendrarathore1742 wants to merge 1 commit intoGoogleCloudPlatform:mainfrom
mahendrarathore1742:feat/sqlserver-cdc-support
Open

feat: Add SQL Server CDC support to Datastream-to-BigQuery template#3450
mahendrarathore1742 wants to merge 1 commit intoGoogleCloudPlatform:mainfrom
mahendrarathore1742:feat/sqlserver-cdc-support

Conversation

@mahendrarathore1742
Copy link

Closes #3410

Add SQL Server as a supported source database for the Datastream to BigQuery Flex template, enabling CDC replication from SQL Server to BigQuery.

Changes:

  • DataStreamClient: Add SQL Server schema discovery, primary key extraction, and type conversion (20+ SQL Server types to BigQuery)
  • FormatDatastreamRecordToJson: Handle SQL Server CDC metadata (_metadata_schema, _metadata_lsn, _metadata_tx_id) for Avro format
  • FormatDatastreamJsonToJson: Handle SQL Server CDC metadata for JSON format. Also fix pre-existing bug where _metadata_lsn was reading from 'database' instead of 'lsn'
  • DatastreamRow: Add SQL Server sort fields for CDC event ordering
  • BigQueryDefaultSchemas: Add _metadata_lsn to default schema
  • DataStreamToBigQuery: Update template requirements and parameter docs to include SQL Server
  • DataStreamClientTest: Add unit tests for SQL Server type conversion

Tested:

  • Maven compile: SUCCESS (datastream-common + datastream-to-bigquery)
  • Checkstyle: 0 violations
  • Unit tests: 11 run, 0 failures

Closes GoogleCloudPlatform#3410

Add SQL Server as a supported source database for the Datastream to
BigQuery Flex template, enabling CDC replication from SQL Server to
BigQuery.

Changes:
- DataStreamClient: Add SQL Server schema discovery, primary key
  extraction, and type conversion (20+ SQL Server types to BigQuery)
- FormatDatastreamRecordToJson: Handle SQL Server CDC metadata
  (_metadata_schema, _metadata_lsn, _metadata_tx_id) for Avro format
- FormatDatastreamJsonToJson: Handle SQL Server CDC metadata for JSON
  format. Also fix pre-existing bug where _metadata_lsn was reading
  from 'database' instead of 'lsn'
- DatastreamRow: Add SQL Server sort fields for CDC event ordering
- BigQueryDefaultSchemas: Add _metadata_lsn to default schema
- DataStreamToBigQuery: Update template requirements and parameter
  docs to include SQL Server
- DataStreamClientTest: Add unit tests for SQL Server type conversion

Tested:
- Maven compile: SUCCESS (datastream-common + datastream-to-bigquery)
- Checkstyle: 0 violations
- Unit tests: 11 run, 0 failures
@google-cla
Copy link

google-cla bot commented Mar 6, 2026

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
Copy link

Summary of Changes

Hello, 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 significantly expands the capabilities of the Datastream-to-BigQuery Flex template by introducing full support for SQL Server as a source for Change Data Capture (CDC) replication. The changes enable seamless data streaming from SQL Server instances to BigQuery, encompassing schema mapping, metadata processing, and proper data type conversions. This enhancement allows users to leverage the template for a broader range of enterprise data sources, facilitating real-time analytics and data warehousing solutions.

Highlights

  • SQL Server CDC Support: Added comprehensive support for SQL Server as a source database for Datastream-to-BigQuery CDC replication, including schema discovery, primary key extraction, and type conversion for over 20 SQL Server data types to BigQuery.
  • CDC Metadata Handling: Implemented handling for SQL Server CDC metadata (_metadata_schema, _metadata_lsn, _metadata_tx_id) in both Avro and JSON record formatting, ensuring proper data ingestion and processing.
  • Metadata LSN Bug Fix: Corrected a pre-existing bug in JSON record formatting where _metadata_lsn was incorrectly reading from the 'database' field instead of the 'lsn' field for certain source types.
  • Data Ordering and Schema Updates: Integrated SQL Server specific sort fields for CDC event ordering and updated the default BigQuery schema to include the _metadata_lsn field.
  • Documentation and Testing: Updated template requirements and parameter documentation to reflect SQL Server support, and added dedicated unit tests for SQL Server type conversion to ensure correctness.
Changelog
  • v2/common/src/main/java/com/google/cloud/teleport/v2/cdc/mappers/BigQueryDefaultSchemas.java
    • Added _metadata_lsn field for SQL Server specific metadata.
  • v2/datastream-common/src/main/java/com/google/cloud/teleport/v2/datastream/transforms/FormatDatastreamJsonToJson.java
    • Added handling for SQL Server specific CDC metadata (_metadata_schema, _metadata_lsn, _metadata_tx_id).
    • Fixed a bug where _metadata_lsn was incorrectly read from 'database' instead of 'lsn'.
  • v2/datastream-common/src/main/java/com/google/cloud/teleport/v2/datastream/transforms/FormatDatastreamRecordToJson.java
    • Added handling for SQL Server specific CDC metadata (_metadata_schema, _metadata_lsn, _metadata_tx_id).
  • v2/datastream-common/src/main/java/com/google/cloud/teleport/v2/datastream/utils/DataStreamClient.java
    • Imported SQL Server model classes.
    • Integrated SQL Server into schema discovery and primary key extraction logic.
    • Implemented methods for discovering SQL Server table schemas and primary keys.
    • Added a comprehensive type conversion utility for mapping SQL Server data types to BigQuery Standard SQL types.
  • v2/datastream-common/src/main/java/com/google/cloud/teleport/v2/datastream/values/DatastreamRow.java
    • Included SQL Server as a source type for determining CDC event sort fields.
  • v2/datastream-common/src/test/java/com/google/cloud/teleport/v2/datastream/utils/DataStreamClientTest.java
    • Imported SqlServerColumn and StandardSQLTypeName.
    • Added extensive unit tests for SQL Server to BigQuery column type conversion, covering various data types.
  • v2/datastream-to-bigquery/README_Cloud_Datastream_to_BigQuery.md
    • Updated documentation for the 'datastreamSourceType' parameter to include 'sqlserver' as a valid value.
  • v2/datastream-to-bigquery/src/main/java/com/google/cloud/teleport/v2/templates/DataStreamToBigQuery.java
    • Updated template requirements to explicitly list SQL Server as a supported source database.
    • Modified the 'datastreamSourceType' parameter's help text to include 'sqlserver'.
Activity
  • No human activity (comments, reviews) was detected on this pull request.
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request]: Support for SQL Server in Datastream-to-Bigquery Dataflow Flex template

1 participant