【发布时间】:2020-11-12 07:11:45
【问题描述】:
我正在尝试将 5 个 SQL 文件加载到 bigquery 中的 5 个不同的表中,以可视化 Data Studio 中的数据。我已将这些文件上传到 CoLab 的存储部分并授权该项目。
datasets = [r"/file1.sql",r"/file2.sql",,r"/file3.sql",r"/file4.sql",,r"/file5.sql"]
f = open(datasets[1], "r")
data=f.read()
data = data.replace('\n','')
import pandas as pd
df = pd.io.gbq.read_gbq('''data''', project_id='newproject1', dialect='standard')
df.head()
df.to_gbq('dataset1.testtable1','newproject1',chunksize=None,reauth=False,if_exists='append')
df.to_gbq('dataset1.testtable2','newproject1',chunksize=None,reauth=False,if_exists='append')
df.to_gbq('dataset1.testtable3','newproject1',chunksize=None,reauth=False,if_exists='append')
df.to_gbq('dataset1.testtable4','newproject1',chunksize=None,reauth=False,if_exists='append')
df.to_gbq('dataset1.testtable5','newproject1',chunksize=None,reauth=False,if_exists='append')
)
运行查询时出现以下错误。
The following traceback may be corrupted or invalid
The error message is: ('EOF in multi-line string', (1, 0))
---------------------------------------------------------------------------
BadRequest Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/pandas_gbq/gbq.py in _download_results(self, query_job, max_results, progress_bar_type)
549
--> 550 query_job.result()
551 # Get the table schema, so that we can list rows.
我还想知道如何更改 python 代码以将数据加载到 5 个受尊重的表中。
【问题讨论】:
-
目前,不支持将 sql 文件 加载到 BigQuery。 Here 你可以找到所有支持的格式。此外,作为替代方案,您可以将这些文件上传到 Cloud SQL 并使用 BigQuery 控制台中的联合查询来查询它们,例如 documentation 中所述。这会满足您的需求吗?
标签: python pandas google-bigquery google-colaboratory