Skip to content
Merged
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
16 changes: 8 additions & 8 deletions docs/bigquery/snippets.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,11 +447,6 @@ def test_load_table_from_file(client, to_delete):
client.create_dataset(dataset)
to_delete.append(dataset)

table_ref = dataset.table(TABLE_ID)
table = bigquery.Table(table_ref, schema=SCHEMA)
table = client.create_table(table)
to_delete.insert(0, table)

# [START load_table_from_file]
csv_file = six.BytesIO(b"""full_name,age
Phred Phlyntstone,32
Expand All @@ -462,11 +457,14 @@ def test_load_table_from_file(client, to_delete):
job_config = bigquery.LoadJobConfig()
job_config.source_format = 'CSV'
job_config.skip_leading_rows = 1
job_config.autodetect = True
job = client.load_table_from_file(
csv_file, table_ref, job_config=job_config) # API request
job.result() # Waits for table load to complete.
# [END load_table_from_file]

table = client.get_table(table_ref)
to_delete.insert(0, table)
found_rows = []

def do_something(row):
Expand All @@ -487,11 +485,13 @@ def do_something(row):
token = iterator.next_page_token
# [END table_list_rows_iterator_properties]

row_tuples = [r.values() for r in rows]
expected_rows = [
bigquery.Row(('Wylma Phlyntstone', 29), {'full_name': 0, 'age': 1}),
bigquery.Row(('Phred Phlyntstone', 32), {'full_name': 0, 'age': 1}),
]
assert len(rows) == total == 2
assert token is None
assert (u'Phred Phlyntstone', 32) in row_tuples
assert (u'Wylma Phlyntstone', 29) in row_tuples
assert rows == expected_rows


def test_load_table_from_uri(client, to_delete):
Expand Down