Skip to content
This repository was archived by the owner on May 16, 2026. It is now read-only.

Add type compiler. - #32

Merged
mxmzdlv merged 6 commits into
googleapis:masterfrom
jmcarp:type-compiler
Dec 21, 2018
Merged

mxmzdlv merged 6 commits into
googleapis:masterfrom
jmcarp:type-compiler

Conversation

@jmcarp

@jmcarp jmcarp commented Dec 18, 2018 •

Copy link
Copy Markdown
Contributor

Map generic datatypes to bigquery datatypes.

With this patch, I was able to create tables with common types via pybigquery.

@tswast

tswast commented Dec 18, 2018

Copy link
Copy Markdown
Contributor

Neat!

I know we have a dictionary from BigQuery types to SQLAlchemy types. Would it make sense to invert that dictionary and use it for these methods? I hate to have the same mapping defined in two places, but I guess this is the only place so far where we need to go from SQLAlchemy types to BigQuery types.

@jmcarp

jmcarp commented Dec 19, 2018

Copy link
Copy Markdown
Contributor Author

Definitely don't want to duplicate logic, but it looks like the mapping in _type_map isn't the same as the one I'm adding here. The _type_map maps INTEGER to sqlalchemy.types.Integer, but we need to return INT64 in the integer visitor in the sql compiler visitor. If I understand correctly, the existing _type_map maps from bigquery types to sqlalchemy types, but the compiler visitors need to map from sqlalchemy types to bigquery sql types, which are different. So maybe we do need two separate (but pretty similar) mappings. What do you think?

@tswast

tswast commented Dec 20, 2018

Copy link
Copy Markdown
Contributor

Yeah, you're right. That's an unfortunate fact of the fact that BigQuery still uses the legacy SQL data type names in the table API methods but we use the standard SQL data types for SQL in the DB-API connector.

Map generic datatypes to bigquery datatypes.
@jmcarp

jmcarp commented Dec 20, 2018

Copy link
Copy Markdown
Contributor Author

Amended to add a few more common types.

@mxmzdlv

mxmzdlv commented Dec 20, 2018 •

Copy link
Copy Markdown
Contributor

Thanks @jmcarp! I've added a simple test, but it looks like sqlalchemy doesn't allow creating tables without primary keys?

E sqlalchemy.exc.ArgumentError: Mapper Mapper|Table|test_pybigquery.test_table_create could not assemble any primary key columns for mapped table 'test_pybigquery.test_table_create'

@jmcarp

jmcarp commented Dec 21, 2018

Copy link
Copy Markdown
Contributor Author

I was testing with sqlalchemy core, which apparently does support tables without primary keys. For sqlalchemy declarative, tables without primary keys aren't supported, but I added a ddl compiler that skips foreign and primary keys on table creation.

@mxmzdlv

mxmzdlv commented Dec 21, 2018

Copy link
Copy Markdown
Contributor

Thanks!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants