-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BigQuery: Use TableListItem for table listing. #4427
Conversation
The table list response only includes a subset of all table properties. This commit adds a new type to document explicitly which properties are included, but also make it clear that this object should not be used in place of a full Table object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few design questions:
- How many of these
@property
-s are copy-pasta? - I don't think the class name really conveys what it is (a read-only version of
Table
). - Is there a reason you might be opposed to just subclassing
Table
or just an arbitrary decision to make a new class? - Are you opposed to adding a
read_only
attribute / member toTable
?
@@ -38,6 +38,7 @@ | |||
from google.cloud.bigquery.dataset import Dataset | |||
from google.cloud.bigquery.dataset import DatasetReference | |||
from google.cloud.bigquery.table import Table, _TABLE_HAS_NO_SCHEMA | |||
from google.cloud.bigquery.table import TableListItem |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Basically all of them. I made a slight change to
It being read-only is more of a side-effect than the primary purpose of the class.
The primary purpose of A sub-class would allow this object to be used in any place a table is allowed, such as update or create requests, which is not something I want people to be doing (because not all properties are present).
I hadn't really considered it, because it wouldn't solve the problem of |
@tswast I'm just trying to avoid code duplication, because the copy-pasta will drift over time. If you did a subclass, you could over-ride and raise an The same applies to methods like I think having a different class is probably the right move as far as "principle of least astonishment" is concerned. (Or rather, if you returned a |
There's so little code in these properties, I'm not super concerned about drift. |
But I am concerned. Care to sell me a bit on your position? |
Most of these properties have implementations like:
These properties directly reflect properties on the resource, with minimal modification. The
I agree this could be shared with the You're right that |
@tswast Though these are simple "schema->data->Python" mappings, some APIs (BQ included) have changed the underlying schema and caught us off guard. With that in mind, "so little code" doesn't inspire much confidence? Also, I don't want to get lost in this discussion that I think |
Discussed in chat. Since |
@@ -713,6 +713,137 @@ def _build_resource(self, filter_fields): | |||
return resource | |||
|
|||
|
|||
class TableListItem(object): | |||
"""Read-only table resource object with a subset of table properties. |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
# it. So a missing or None can only come from the server, whose | ||
# default is True. | ||
return view.get('useLegacySql', True) | ||
view_use_legacy_sql = property(_view_use_legacy_sql_getter) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
For performance reasons, the BigQuery API only includes some of the table | ||
properties when listing tables. Notably, | ||
:attr:`google.cloud.bigquery.table.Table.schema` and | ||
:attr:`google.cloud.bigquery.table.Table.num_rows` are missing. |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
||
For a full list of the properties that the BigQuery API returns, see the | ||
`REST documentation for tables.list | ||
<https://cloud.google.com/bigquery/docs/reference/rest/v2/tables/list>`. |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
@tswast OK Do you feel this is merge-able? |
Yeah. Just ran the full nox suite locally to double-check. |
Cool LGTM |
The table list response only includes a subset of all table properties.
This commit adds a new type to document explicitly which properties are
included, but also make it clear that this object should not be used in
place of a full Table object.
Towards #4373 (needs a similar change for dataset listing before closing that issue)