#THIS IS THE CODE I AM RUNNING
# Set the destination table
for i in range(1,13):
table_ref = client.dataset("newdataset").table("chicago_months_increment")
job_config.destination = table_ref
job_config.allow_large_results = True
query_job = client.query('SELECT * FROM `bigquery-public-
data.chicago_taxi_trips.taxi_trips` WHERE (Select EXTRACT(MONTH from
trip_start_timestamp) )=i;',
location='US', # Location must match dataset
job_config=job_config)
rows = list(query_job) # Waits for the query to finish
query_job.result()
# Export table to GCS
destination_uri = "gs://monthly-data/month-"+i+"-*.csv"
dataset_ref = client.dataset("newdataset", project="chicago-project-247714")
table_ref = dataset_ref.table("chicago_months_increment")
extract_job = client.extract_table(
table_ref,
destination_uri,
location='US')
extract_job.result() # Waits for job to complete
client.delete_table(table_ref) #Deletes table in BQ
#ERROR I AM GETTING
---------------------------------------------------------------------------
BadRequest Traceback (most recent call last)
<ipython-input-5-e176648eba58> in <module>()
9 location='US', # Location must match dataset
10 job_config=job_config)
---> 11 rows = list(query_job) # Waits for the query to finish
12
13
/home/amiteshwar/.local/lib/python2.7/site-
packages/google/cloud/bigquery/job.pyc in iter(self)
2988
第2989章
-> 2990 返回 iter(self.result())
2991
第2992章
/home/amiteshwar/.local/lib/python2.7/site-
packages/google/cloud/bigquery/job.pyc 结果(self、timeout、page_size、
重试)
2875 如果作业没有在给定的超时时间内完成。
第2876章
-> 2877 super(QueryJob, self).result(timeout=timeout)
2878 # 返回一个迭代器而不是返回作业。
2879 如果不是 self._query_results:
/home/amiteshwar/.local/lib/python2.7/site-
packages/google/cloud/bigquery/job.pyc 结果(自我、超时、重试)
第731章
732 # TODO: 修改 PollingFuture 以便它可以将重试参数传递给
完毕()。
--> 733 return super(_AsyncJob, self).result(timeout=timeout)
734
735 def 取消(自我):
/home/amiteshwar/.local/lib/python2.7/site-
packages/google/api_core/future/polling.pyc in result(self, timeout)
125 # pylint: disable=raising-bad-type
126 # Pylint doesn't recognize that this is valid in this case.
--> 127 raise self._exception
128
129 return self._result
BadRequest: 400 Unrecognized name: i at [1:125]