Skip to content

feat(sqlalchemy-bigquery): add JSON type support to BigQueryTypeCompiler#16124

Open
geoHeil wants to merge 1 commit intogoogleapis:mainfrom
geoHeil:feat/sqlalchemy-bigquery-json-type
Open

feat(sqlalchemy-bigquery): add JSON type support to BigQueryTypeCompiler#16124
geoHeil wants to merge 1 commit intogoogleapis:mainfrom
geoHeil:feat/sqlalchemy-bigquery-json-type

Conversation

@geoHeil
Copy link

@geoHeil geoHeil commented Mar 18, 2026

Description

BigQuery has natively supported the JSON type since 2022, but sqlalchemy-bigquery does not map it. This causes UnsupportedCompilationError when creating tables with sa.JSON() columns:

sqlalchemy.exc.UnsupportedCompilationError: Compiler <BigQueryTypeCompiler>
can't render element of type JSON

Changes

  • base.py: Add visit_JSON to BigQueryTypeCompiler, returning "JSON"
  • _types.py: Add "JSON": sqlalchemy.types.JSON to _type_map and export JSON
  • __init__.py: Export JSON from the package
  • tests/unit/test_compiler.py: Add unit test for JSON column DDL compilation

Testing

All 314 existing unit tests pass. New test verifies sa.JSON() compiles to JSON in CREATE TABLE DDL.

Context

Discovered while setting up Alembic migrations for Metaxy's BigQuery metadata store.

Fixes #16123

@geoHeil geoHeil requested review from a team as code owners March 18, 2026 14:31
@google-cla
Copy link

google-cla bot commented Mar 18, 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
Contributor

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 introduces comprehensive support for the JSON data type within the sqlalchemy-bigquery dialect. By integrating sqlalchemy.types.JSON with BigQuery's native JSON type, it resolves UnsupportedCompilationError issues and enables users to define and manage JSON columns in their BigQuery schemas through SQLAlchemy, enhancing compatibility and functionality for applications leveraging BigQuery's modern data capabilities.

Highlights

  • JSON Type Support: Added support for the sqlalchemy.types.JSON type in sqlalchemy-bigquery, allowing it to be correctly compiled to BigQuery's native JSON type.
  • Compiler Implementation: Implemented the visit_JSON method within the BigQueryTypeCompiler to handle the compilation of JSON types.
  • Type Mapping and Export: Mapped sqlalchemy.types.JSON to the BigQuery JSON type in the internal type map and exported the JSON type for public use.
  • Unit Testing: Included a new unit test to verify that sqlalchemy.JSON() columns are correctly compiled into CREATE TABLE DDL statements for BigQuery.
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.

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.

Copy link
Contributor

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

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 adds support for the JSON data type in sqlalchemy-bigquery, which is a valuable feature enhancement. The implementation is straightforward and correct, including adding the type mapping, the compiler visit method, and exporting the new type. A unit test is also included to verify the change. I have a minor suggestion for improving code maintainability by keeping type assignments sorted, consistent with other parts of the codebase.

BigQuery has natively supported the JSON type since 2022, but the
SQLAlchemy dialect was missing visit_JSON in BigQueryTypeCompiler
and the JSON entry in _type_map. This caused UnsupportedCompilationError
when creating tables with sa.JSON() columns via Alembic.

Changes:
- Add visit_JSON to BigQueryTypeCompiler returning "JSON"
- Add "JSON" to _type_map mapping to sqlalchemy.types.JSON
- Export JSON from the package __init__.py
- Add unit test for JSON column DDL compilation

Fixes: googleapis#16123
@geoHeil geoHeil force-pushed the feat/sqlalchemy-bigquery-json-type branch from 764ca52 to dc6761e Compare March 18, 2026 14:42
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.

sqlalchemy-bigquery: BigQueryTypeCompiler missing visit_JSON

1 participant