Skip to content

Conversation

@vinceatbluelabs
Copy link
Contributor

This is a follow-on PR to #53 to implement the desired expanded project and dataset parsing behavior discussed during its review.

Tests have been updated and pass.

# If neither dataset nor project are the default
sample_table_1 = Table('natality', schema='bigquery-public-data.samples')
# If just dataset is not the default
sample_table_2 = Table('natality', schema='bigquery-public-data')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed in #53, I believe it's more in the spirit of SQLAlchemy and common SQL database notions of 'schema name' to specify the location, rather than encouraging people to specify it in the name (in BigQuery-speak, the project and dataset).

As per previous discussion, the code will continue to accept dataset and project specified in the table name to avoid breaking existing users, and there are regression tests added for that usage.

elif len(table_name_split) == 3:
project, dataset, table_name = table_name_split
else:
raise ValueError("Did not understand table_name: {}".format(full_table_name))
Copy link
Contributor Author

@vinceatbluelabs vinceatbluelabs Aug 12, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used .format() instead of f-strings since I assume you want to support older Python versions. The underlying BigQuery libraries seemed to use ValueError for SQL parsing issues, so I assumed this was a good exception type.

table_ref = TableReference.from_string("{}.{}.{}".format(
project_id, dataset_id, table_id
))
return table_ref
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I broke out this function so it could be easily unit tested with the various valid combinations of specifying project/dataset/table in the schema and table arguments. I test drove this, and every line was added due to a corresponding test case.

with pytest.raises(ValueError):
dialect._table_reference(provided_schema_name,
provided_table_name,
client_project)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Above are the test cases! Let me know if you think of any other scenarios we need to cover.

@vinceatbluelabs
Copy link
Contributor Author

Hi @tswast! Let me know what you think.

@tswast
Copy link
Collaborator

tswast commented Aug 27, 2020

Thanks for the contribution! It'll probably be another week or two before I have time to review this. Thanks for your patience.

@tswast tswast self-requested a review September 16, 2020 16:24
Copy link
Collaborator

@tswast tswast left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wonderful! Thanks so much for your contribution.

@tswast tswast merged commit 72fbe2b into googleapis:master Nov 18, 2020
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.

2 participants