Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2f5ffb9

Browse files
authored
BigQuery: Moves all Table property conversion logic into properties (googleapis#5125)
* moves Table python/API type conversions into properties * handles empty schema * updates per comments and adds Table.to_api_repr() * updates docstrings to google style * removes properties with the same name as API field from _PROPERTY_TO_API_FIELD * _build_resource() is only for update * fixes variable name and comment * fixes type handling for non-string properties * adds partition_expiration to _PROPERTY_TO_API_FIELD
1 parent bd50917 commit 2f5ffb9

File tree

4 files changed

+388
-481
lines changed

4 files changed

+388
-481
lines changed

bigquery/google/cloud/bigquery/client.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -272,12 +272,8 @@ def create_table(self, table):
272272
"""
273273
path = '/projects/%s/datasets/%s/tables' % (
274274
table.project, table.dataset_id)
275-
resource = table._build_resource(Table.all_fields)
276-
doomed = [field for field in resource if resource[field] is None]
277-
for field in doomed:
278-
del resource[field]
279275
api_response = self._connection.api_request(
280-
method='POST', path=path, data=resource)
276+
method='POST', path=path, data=table.to_api_repr())
281277
return Table.from_api_repr(api_response)
282278

283279
def _call_api(self, retry, **kwargs):
@@ -1111,7 +1107,7 @@ def insert_rows(self, table, rows, selected_fields=None, **kwargs):
11111107
elif isinstance(table, TableReference):
11121108
raise ValueError('need selected_fields with TableReference')
11131109
elif isinstance(table, Table):
1114-
if len(table._schema) == 0:
1110+
if len(table.schema) == 0:
11151111
raise ValueError(_TABLE_HAS_NO_SCHEMA)
11161112
schema = table.schema
11171113
else:
@@ -1305,7 +1301,7 @@ def list_rows(self, table, selected_fields=None, max_results=None,
13051301
elif isinstance(table, TableReference):
13061302
raise ValueError('need selected_fields with TableReference')
13071303
elif isinstance(table, Table):
1308-
if len(table._schema) == 0:
1304+
if len(table.schema) == 0:
13091305
raise ValueError(_TABLE_HAS_NO_SCHEMA)
13101306
schema = table.schema
13111307
else:

0 commit comments

Comments
 (0)