Google云产品
  • Introduction
  • google cloud
    • Cloud Functions
    • Pub / Sub
      • 资料
    • Cloud Storage
      • gsutil 挂载工具
    • Cloud Dataflow
      • 入门
      • 创建和运行模板
      • Apache Beam
        • 介绍
        • Apache Beam SDK 的流水线基础知识
    • BigQuery
      • 入门
      • 运行和管理作业
      • 数据集操作
      • 处理表架构(表字段的修改)
      • 处理表
      • 使用分区表
      • 资料
      • php代码
    • 常用
  • Cloudinary
Powered by GitBook
On this page
  • php sdk
  • 分页的查询方式
  • 全表
  • 根据query分页

Was this helpful?

  1. google cloud
  2. BigQuery

php代码

Previous资料Next常用

Last updated 5 years ago

Was this helpful?

php sdk

分页的查询方式

全表

<?php

require 'vendor/autoload.php';

use Google\Cloud\BigQuery\BigQueryClient;

$bigQuery = new BigQueryClient(['keyFilePath' => './keybig.json']);

$maxResults = 1000;
$startIndex = 0;

$options = [
    'maxResults' => $maxResults,
    'startIndex' => $startIndex
];
$dataset = $bigQuery->dataset('austin_311');
$table = $dataset->table('311_request');
$numRows = 0;
foreach ($table->rows($options) as $row) {
     print('---');
    foreach ($row as $column => $value) {
        printf('%s: %s' . PHP_EOL, $column, $value);
    }
    $numRows++;
} 

根据query分页

<?php

require 'vendor/autoload.php';

use Google\Cloud\BigQuery\BigQueryClient;

$bigQuery = new BigQueryClient(['keyFilePath' => './keybig.json']);
$maxResults = 1000;
$startIndex = 0;

$queryJobConfig = $bigQuery->query(
   "SELECT * FROM `bigquery-public-data.austin_311.311_request` LIMIT 120000"
);
$queryResults = $bigQuery->runQuery($queryJobConfig);

/* foreach ($queryResults as $row) {
    print_r($row);
    file_put_contents("/tmp/test/bigquery", $row['unique_key'].PHP_EOL,FILE_APPEND);
} 
die; */
$options = [
    'maxResults' => $maxResults,
    'startIndex' => $startIndex
];
$numRows = 0;
foreach ($queryResults->rows($options) as $row) {
    file_put_contents("/tmp/test/bigquery", $row['unique_key'].PHP_EOL,FILE_APPEND);
    $numRows++;
    echo '---'.$numRows.PHP_EOL;
}

google-cloud-php-bigquery