php - Bigquery PHP 使用插入选择作业填充表

标签 php insert google-bigquery google-api-php-client

我正在尝试通过 PHP 中的插入选择作业填充先前创建的表。 Google 文档中有一小段内容如下:

“运行异步查询,传入现有表的名称,并设置 writeDisposition=WRITE_APPEND。”

现在我使用接下来的句子从 bigquery 获取行:

      // query request service
      $query = new Google_Service_Bigquery_QueryRequest();
      //armar query
      $selectQuery = "select source_year, year, month, day from publicdata:samples.natality LIMIT 100";
      if($whereQuery!=null && strlen($whereQuery)>0)$selectQuery = $selectQuery . " WHERE " . $whereQuery;
      //print_r(var_dump($selectQuery));
      $query->setQuery($selectQuery);
      $response = $service->jobs->query($project_id, $query);
      $jsonStr = "";
      if($response)if($response->getRows())$jsonStr = $response->getRows();
      print_r($jsonStr);

但我需要从查询结果填充另一个表。 谢谢您的建议。 再见


谢谢 Pentium10,但我收到错误消息“调用未定义的方法 Google_Service_Bigquery_QueryRequest::setDestinationTable()”,因为我没有使用作业来执行查询。

我使用接下来的句子来获取查询结果,但它不起作用:

  //query request service
  $query = new Google_Service_Bigquery_QueryRequest();

  //destination table
  $destinationTable = new Google_Service_Bigquery_TableReference();
  $destinationTable->setDatasetId($dataset);
  $destinationTable->setProjectId($project_id);
  $destinationTable->setTableId('ventastest');

  $query->setDestinationTable($destinationTable);
  $query->setWriteDisposition('WRITE_APPEND');

  //build query
  $selectQuery = "SELECT " . $fieldsQuery . " FROM " . $dataset . "." . $tableQuery;
  if($whereQuery!=null && strlen($whereQuery)>0)$selectQuery = $selectQuery . " WHERE " . $whereQuery;

  $query->setQuery($selectQuery);
  $response = $service->jobs->query($project_id, $query);
  $jsonStr = "";
  if($response)if($response->getRows())$jsonStr = $response->getRows();
  print_r($jsonStr);

即使我附加到服务->作业,我也会收到错误消息:

  $destinationTable = new Google_Service_Bigquery_TableReference();
  $destinationTable->setDatasetId($dataset);
  $destinationTable->setProjectId($project_id);
  $destinationTable->setTableId('ventastest');

  $service->jobs->setDestinationTable($destinationTable);
  $service->jobs->setWriteDisposition('WRITE_APPEND');

谢谢,再见!

最佳答案

$destinationTable = new Google_Service_Bigquery_TableReference();
$destinationTable->setDatasetId(DATASET_ID);
$destinationTable->setProjectId(PROJECT_ID);
$destinationTable->setTableId('name_of_the_table');

$queryConfig->setDestinationTable($destinationTable);
$queryConfig->setWriteDisposition('WRITE_APPEND');

关于php - Bigquery PHP 使用插入选择作业填充表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25985559/

相关文章:

MySQL并发插入,为什么会发生以及处理它的最佳方法是什么?

google-analytics - "EACH"关键字是 't returning correct result in "GROUP EACH BY"

sql - 大查询 : Select a column with any value not in group by clause

postfix-mta - PHP 邮件后缀

php - 在包含路径 phpstorm 中找不到 PHPUnit

php - 如何在php中获取链接的值id

php程序下载权限

c# - 将行添加到数据库中,获取 ID 并填充第二个表

php - 如何在不替换 PHP 中的任何内容的情况下插入文本

firebase - iOS : Issues with switching from Google Analytics to Firebase Analytics