@@ -26,7 +26,7 @@ def browse_table_data(client, table_id):
2626 # table_id = "your-project.your_dataset.your_table_name"
2727
2828 # Download all rows from a table.
29- rows_iter = client .list_rows (table_id )
29+ rows_iter = client .list_rows (table_id ) # Make an API request.
3030
3131 # Iterate over rows to make the API requests to fetch row data.
3232 rows = list (rows_iter )
@@ -38,10 +38,18 @@ def browse_table_data(client, table_id):
3838 print ("Downloaded {} rows from table {}" .format (len (rows ), table_id ))
3939
4040 # Specify selected fields to limit the results to certain columns.
41- table = client .get_table (table_id )
41+ table = client .get_table (table_id ) # Make an API request.
4242 fields = table .schema [:2 ] # first two columns
4343 rows_iter = client .list_rows (table_id , selected_fields = fields , max_results = 10 )
4444 rows = list (rows_iter )
4545 print ("Selected {} columns from table {}." .format (len (rows_iter .schema ), table_id ))
4646 print ("Downloaded {} rows from table {}" .format (len (rows ), table_id ))
47+
48+ # Print row data in tabular format.
49+ rows = client .list_rows (table , max_results = 10 )
50+ format_string = "{!s:<16} " * len (rows .schema )
51+ field_names = [field .name for field in rows .schema ]
52+ print (format_string .format (* field_names )) # Prints column headers.
53+ for row in rows :
54+ print (format_string .format (* row )) # Prints row data.
4755 # [END bigquery_browse_table]
0 commit comments