Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
FLOAT64,
INT64,
INTEGER,
JSON,
NUMERIC,
RECORD,
STRING,
Expand Down Expand Up @@ -75,6 +76,7 @@
"FLOAT64",
"INT64",
"INTEGER",
"JSON",
"NUMERIC",
"RECORD",
"STRING",
Expand Down
2 changes: 2 additions & 0 deletions packages/sqlalchemy-bigquery/sqlalchemy_bigquery/_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"FLOAT": sqlalchemy.types.Float,
"INT64": sqlalchemy.types.Integer,
"INTEGER": sqlalchemy.types.Integer,
"JSON": sqlalchemy.types.JSON,
"NUMERIC": sqlalchemy.types.Numeric,
"RECORD": STRUCT,
"STRING": sqlalchemy.types.String,
Expand All @@ -60,6 +61,7 @@
FLOAT = _type_map["FLOAT"]
INT64 = _type_map["INT64"]
INTEGER = _type_map["INTEGER"]
JSON = _type_map["JSON"]
NUMERIC = _type_map["NUMERIC"]
RECORD = _type_map["RECORD"]
STRING = _type_map["STRING"]
Expand Down
3 changes: 3 additions & 0 deletions packages/sqlalchemy-bigquery/sqlalchemy_bigquery/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,9 @@ def visit_NUMERIC(self, type_, **kw):

visit_DECIMAL = visit_NUMERIC

def visit_JSON(self, type_, **kw):
return "JSON"


class BigQueryDDLCompiler(DDLCompiler):
option_datatype_mapping = {
Expand Down
13 changes: 13 additions & 0 deletions packages/sqlalchemy-bigquery/tests/unit/test_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,19 @@ def table(faux_conn, metadata):
table.drop(faux_conn)


def test_compile_json_column(faux_conn, metadata):
sqlalchemy.Table(
"json_table",
metadata,
sqlalchemy.Column("id", sqlalchemy.Integer),
sqlalchemy.Column("data", sqlalchemy.JSON),
)
metadata.create_all(faux_conn.engine)
assert " ".join(faux_conn.test_data["execute"][-1][0].strip().split()) == (
"CREATE TABLE `json_table` ( `id` INT64, `data` JSON )"
)


def test_constraints_are_ignored(faux_conn, metadata):
sqlalchemy.Table(
"ref",
Expand Down
Loading