Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion bigquery/google/cloud/bigquery/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,8 @@ def list_rows(self, table, selected_fields=None, max_results=None,

params = {}
if selected_fields is not None:
params['selectedFields'] = [f.name for f in selected_fields]
params['selectedFields'] = ','.join(
[f.name for f in selected_fields])
if start_index is not None:
params['startIndex'] = start_index

Expand Down
22 changes: 20 additions & 2 deletions bigquery/tests/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,9 @@ def test_update_table_schema(self):
self.assertEqual(found.mode, expected.mode)

@staticmethod
def _fetch_single_page(table):
iterator = Config.CLIENT.list_rows(table)
def _fetch_single_page(table, selected_fields=None):
iterator = Config.CLIENT.list_rows(
table, selected_fields=selected_fields)
page = six.next(iterator.pages)
return list(page)

Expand Down Expand Up @@ -1236,6 +1237,23 @@ def test_dump_table_w_public_data(self):
table = Config.CLIENT.get_table(table_ref)
self._fetch_single_page(table)

def test_dump_table_w_public_data_selected_fields(self):
PUBLIC = 'bigquery-public-data'
DATASET_ID = 'samples'
TABLE_NAME = 'natality'
selected_fields = [
bigquery.SchemaField('year', 'INTEGER', mode='NULLABLE'),
bigquery.SchemaField('month', 'INTEGER', mode='NULLABLE'),
bigquery.SchemaField('day', 'INTEGER', mode='NULLABLE'),
]
table_ref = DatasetReference(PUBLIC, DATASET_ID).table(TABLE_NAME)

rows = self._fetch_single_page(
table_ref, selected_fields=selected_fields)

self.assertGreater(len(rows), 0)
self.assertEqual(len(rows[0]), 3)

def test_large_query_w_public_data(self):
PUBLIC = 'bigquery-public-data'
DATASET_ID = 'samples'
Expand Down