title: BigQuery table truncation before streaming not working
body: <p>We are using BigQuery Python API to run some analyzes. To do so, we created the following adapter:</p>
  
  <pre><code>def stream_data(self, table, data, schema, how=None):
      r = self.connector.tables().list(projectId=self._project_id,
                                       datasetId='lbanor').execute()
      table_exists = [row['tableReference']['tableId'] for row in
                      r['tables'] if
                      row['tableReference']['tableId'] == table]
      if table_exists:
          if how == 'WRITE_TRUNCATE':
              self.connector.tables().delete(projectId=self._project_id,
                                             datasetId='lbanor',
                                             tableId=table).execute()
              body = {
                  'tableReference': {
                      'tableId': table,
                      'projectId': self._project_id,
                      'datasetId': 'lbanor'
                  },
                  'schema': schema
              }
              self.connector.tables().insert(projectId=(
                                             self._project_id),
                                             datasetId='lbanor',
                                             body=body).execute()
      else:
          body = {
              'tableReference': {
                  'tableId': table,
                  'projectId': self._project_id,
                  'datasetId': 'lbanor'
              },
              'schema': schema
          }
          self.connector.tables().insert(projectId=(
                                         self._project_id),
                                         datasetId='lbanor',
                                         body=body).execute()
  
      body = {
          'rows': [
              {
                  'json': data,
                  'insertId': str(uuid.uuid4())
              }
          ]
      }
      self.connector.tabledata().insertAll(projectId=(
                                           self._project_id),
                                           datasetId='lbanor',
                                           tableId=table,
                                                 body=body).execute(num_retries=5)
  </code></pre>
  
  <p>where <code>connector</code> is just the build object.</p>
  
  <p>Its main purpose is to stream data to the given table. And in case the table already exists and "how" input is passed as "WRITE_TRUNCATE", then the table is first deleted and created again.
  After that, proceed doing the data stream.</p>
  
  <p>Everything worked fine when the table is not deleted over and over again.</p>
  
  <p>For instance, this is the result when we run the script without simulating the write truncation option (a <code>for</code> loop keeps calling <code>stream_data</code> with <code>how=None</code>):</p>
  
  <pre><code>[
    {
      "date": "2016-04-25",
      "unix_date": "1461606664981207",
      "init_cv_date": "2016-03-12",
      "end_cv_date": "2016-03-25",
      "days_trained": "56",
      "days_validated": "14",
      "navigated_score": "1",
      "carted_score": "3",
      "purchased_score": "10",
      "description": "First trial of top seller alg. No filter nor any condition is applied. Skus not present in train count as rank=0.5",
      "metric": "rank",
      "result": "0.31729249914663893"
    },
    {
      "date": "2016-04-25",
      "unix_date": "1461606599745107",
      "init_cv_date": "2016-03-06",
      "end_cv_date": "2016-03-25",
      "days_trained": "80",
      "days_validated": "20",
      "navigated_score": "1",
      "carted_score": "3",
      "purchased_score": "10",
      "description": "First trial of top seller alg. No filter nor any condition is applied. Skus not present in train count as rank=0.5",
      "metric": "rank",
      "result": "0.32677143128667446"
    },
    {
      "date": "2016-04-25",
      "unix_date": "1461606688950415",
      "init_cv_date": "2016-03-14",
      "end_cv_date": "2016-03-25",
      "days_trained": "48",
      "days_validated": "12",
      "navigated_score": "1",
      "carted_score": "3",
      "purchased_score": "10",
      "description": "First trial of top seller alg. No filter nor any condition is applied. Skus not present in train count as rank=0.5",
      "metric": "rank",
      "result": "0.3129267723358932"
    },
    {
      "date": "2016-04-25",
      "unix_date": "1461606707195122",
      "init_cv_date": "2016-03-16",
      "end_cv_date": "2016-03-25",
      "days_trained": "40",
      "days_validated": "10",
      "navigated_score": "1",
      "carted_score": "3",
      "purchased_score": "10",
      "description": "First trial of top seller alg. No filter nor any condition is applied. Skus not present in train count as rank=0.5",
      "metric": "rank",
      "result": "0.310620987663015"
    },
    {
      "date": "2016-04-25",
      "unix_date": "1461606622432947",
      "init_cv_date": "2016-03-08",
      "end_cv_date": "2016-03-25",
      "days_trained": "72",
      "days_validated": "18",
      "navigated_score": "1",
      "carted_score": "3",
      "purchased_score": "10",
      "description": "First trial of top seller alg. No filter nor any condition is applied. Skus not present in train count as rank=0.5",
      "metric": "rank",
      "result": "0.32395802949369296"
    }
  ]
  </code></pre>
  
  <p>But when we use the same adapter with the input how="WRITE_TRUNCATE", its behavior changed and became unpredictable.</p>
  
  <p>Sometimes it works and data is saved to the table. But sometimes, even though no error is raised, no data is saved to the table.</p>
  
  <p>When trying to query the table, no data is returned. It just returns "Query returned zero results".</p>
  
  <p>Something went wrong when deleting the table, creating it again and streaming the data. Are we making some mistake?</p>
  
  <p>If you need more info please let me know. Thanks in advance!</p>