Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f7a52cb

Browse filesBrowse files
committed
BQ: Pass selected_fields as a string to tabledata.list. (#4143)
BigQuery was only returning the first column when passing in a list instead of a comma-separated string.
1 parent 9876ad6 commit f7a52cb
Copy full SHA for f7a52cb

File tree

Expand file treeCollapse file tree

2 files changed

+22
-3
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+22
-3
lines changed
Open diff view settings
Collapse file

‎bigquery/google/cloud/bigquery/client.py‎

Copy file name to clipboardExpand all lines: bigquery/google/cloud/bigquery/client.py
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -924,7 +924,8 @@ def list_rows(self, table, selected_fields=None, max_results=None,
924924

925925
params = {}
926926
if selected_fields is not None:
927-
params['selectedFields'] = [f.name for f in selected_fields]
927+
params['selectedFields'] = ','.join(
928+
[f.name for f in selected_fields])
928929
if start_index is not None:
929930
params['startIndex'] = start_index
930931

Collapse file

‎bigquery/tests/system.py‎

Copy file name to clipboardExpand all lines: bigquery/tests/system.py
+20-2Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,8 +312,9 @@ def test_update_table_schema(self):
312312
self.assertEqual(found.mode, expected.mode)
313313

314314
@staticmethod
315-
def _fetch_single_page(table):
316-
iterator = Config.CLIENT.list_rows(table)
315+
def _fetch_single_page(table, selected_fields=None):
316+
iterator = Config.CLIENT.list_rows(
317+
table, selected_fields=selected_fields)
317318
page = six.next(iterator.pages)
318319
return list(page)
319320

@@ -1236,6 +1237,23 @@ def test_dump_table_w_public_data(self):
12361237
table = Config.CLIENT.get_table(table_ref)
12371238
self._fetch_single_page(table)
12381239

1240+
def test_dump_table_w_public_data_selected_fields(self):
1241+
PUBLIC = 'bigquery-public-data'
1242+
DATASET_ID = 'samples'
1243+
TABLE_NAME = 'natality'
1244+
selected_fields = [
1245+
bigquery.SchemaField('year', 'INTEGER', mode='NULLABLE'),
1246+
bigquery.SchemaField('month', 'INTEGER', mode='NULLABLE'),
1247+
bigquery.SchemaField('day', 'INTEGER', mode='NULLABLE'),
1248+
]
1249+
table_ref = DatasetReference(PUBLIC, DATASET_ID).table(TABLE_NAME)
1250+
1251+
rows = self._fetch_single_page(
1252+
table_ref, selected_fields=selected_fields)
1253+
1254+
self.assertGreater(len(rows), 0)
1255+
self.assertEqual(len(rows[0]), 3)
1256+
12391257
def test_large_query_w_public_data(self):
12401258
PUBLIC = 'bigquery-public-data'
12411259
DATASET_ID = 'samples'

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.