Uploading empty data to Bigquery using gcloud python
<p>I try to upload a few rows of data using the <a href="https://googlecloudplatform.github.io/google-cloud-python/stable/bigquery-usage.html" rel="nofollow">gcloud python library</a> and don't succeed. Here is the sample code taken from the <a href="https://googlecloudplatform.github.io/google-cloud-python/stable/bigquery-table.html" rel="nofollow">latest documentation</a> </p>

<pre><code>client = bigquery.Client()
dataset = client.dataset('test')
table = dataset.table("test_table")
rows = [("foo", "bar"), ("foo2", "bar2")]
result = table.insert_data(rows)
</code></pre>

<p>If I query the latest upload I get:</p>

<pre><code>[(None, None), (None, None)]
</code></pre>

<p>So I add empty fields. In the documentation it says the uploaded rows should be "list of tuples", but that does not seem to work. My schema has two string fields. Unicode fields do not work either and I do not get any error result back either, which makes it difficult to debug. Any hint what I do wrong? </p>

<p>Explicitly declaring the schema in your table will help solve this problem. I.e., instead of using <code>table = dataset.table('test_table')</code>, you should use the following:</p>

<p><code>left = SchemaField('left', 'STRING', 'REQUIRED')
right = SchemaField('right', 'STRING', 'REQUIRED')
table = dataset.table('test_table', schema=[left, right])
</code></p>

<p>I had opened an issue on Github regarding this. You can <a href="https://github.com/GoogleCloudPlatform/google-cloud-python/issues/2472" rel="nofollow">read more here</a> if interested.</p>

python google-bigquery gcloud-python google-cloud-python