Skip to content

sqlalchemy-bigquery: BigQueryTypeCompiler missing visit_JSON #16123

Description

@geoHeil

Description

sqlalchemy-bigquery does not support sa.JSON() column type. BigQuery has natively supported the JSON type since 2022, but the SQLAlchemy dialect's BigQueryTypeCompiler has no visit_JSON method.

Error

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

This occurs when running Alembic migrations that include sa.Column("my_col", sa.JSON(), ...) against BigQuery.

Reproduction

from sqlalchemy import create_engine, MetaData, Table, Column, JSON, String

engine = create_engine("bigquery://my-project/my_dataset")
metadata = MetaData()
Table("test", metadata, Column("id", String()), Column("data", JSON()))
metadata.create_all(engine)  # UnsupportedCompilationError

Expected behavior

sa.JSON() should compile to BigQuery's native JSON type in DDL statements, since BigQuery supports it.

Context

Discovered while setting up Alembic migrations for Metaxy's BigQuery metadata store: anam-org/metaxy#1072

Environment

  • sqlalchemy-bigquery==1.16.0
  • sqlalchemy==2.0.x
  • alembic==1.15.x

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions