Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/59.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用Python实现BigQuery_Python_Mysql_Google Bigquery - Fatal编程技术网

用Python实现BigQuery

用Python实现BigQuery,python,mysql,google-bigquery,Python,Mysql,Google Bigquery,是否仍然可以使用Python脚本在google BigQuery上重复运行查询 我想用Google BigQuery平台查询一个数据集一周的数据,我想在一年内完成。查询数据集52次有点太繁琐了。相反,我更喜欢编写Python脚本(正如我所知道的Python) 我希望有人能给我指出正确的方向。BigQuery提供了几种语言的客户端库——请参阅——尤其是Python,其中的文档位于(您需要通过超链接了解文档) 给出了一个Java或Python命令行程序的示例,该程序使用Google BigQuery

是否仍然可以使用Python脚本在google BigQuery上重复运行查询

我想用Google BigQuery平台查询一个数据集一周的数据,我想在一年内完成。查询数据集52次有点太繁琐了。相反,我更喜欢编写Python脚本(正如我所知道的Python)


我希望有人能给我指出正确的方向。

BigQuery提供了几种语言的客户端库——请参阅——尤其是Python,其中的文档位于(您需要通过超链接了解文档)

给出了一个Java或Python命令行程序的示例,该程序使用Google BigQuery API在一个可用的示例数据集上运行查询并显示结果。导入并设置一些常量之后,Python脚本可以归结为

  storage = Storage('bigquery_credentials.dat')
  credentials = storage.get()

  if credentials is None or credentials.invalid:
      # Run oauth2 flow with default arguments.
      credentials = tools.run_flow(FLOW, storage, tools.argparser.parse_args([]))

  http = httplib2.Http()
  http = credentials.authorize(http)

  bigquery_service = build('bigquery', 'v2', http=http)

  try:
    query_request = bigquery_service.jobs()
    query_data = {'query':'SELECT TOP( title, 10) as title, COUNT(*) as revision_count FROM [publicdata:samples.wikipedia] WHERE wp_namespace = 0;'}

    query_response = query_request.query(projectId=PROJECT_NUMBER,
                                         body=query_data).execute()
    print 'Query Results:'
    for row in query_response['rows']:
      result_row = []
      for field in row['f']:
        result_row.append(field['v'])
      print ('\t').join(result_row)

  except HttpError as err:
    print 'Error:', pprint.pprint(err.content)

  except AccessTokenRefreshError:
    print ("Credentials have been revoked or expired, please re-run"
           "the application to re-authorize")
如您所见,只有30行,主要与获取和检查授权以及处理错误有关。除去这些考虑因素,“核心”部分实际上只是其中的一半:

    bigquery_service = build('bigquery', 'v2', http=http)
    query_request = bigquery_service.jobs()
    query_data = {'query':'SELECT TOP( title, 10) as title, COUNT(*) as revision_count FROM [publicdata:samples.wikipedia] WHERE wp_namespace = 0;'}

    query_response = query_request.query(projectId=PROJECT_NUMBER,
                                         body=query_data).execute()
    print 'Query Results:'
    for row in query_response['rows']:
      result_row = []
      for field in row['f']:
        result_row.append(field['v'])
      print ('\t').join(result_row)

您可以使用google data flow for python,如果它是一次性的,可以从您的终端或同等设备上运行它。或者,您可以在appenginecron中使用一个shell脚本,该脚本循环代码52次以获取数据。谷歌数据流调度

表明这是可能的。。。它还提到了BigQuery主页上的Python。。。不确定您的困惑/问题是什么?应用程序引擎上托管的cron作业+python代码?不过,你的问题必须更具体一些