google/cloud-bigquery-storage

PHP Google BigQuery Storage 客户端

v2.0.0 2024-09-07 00:21 UTC

README

本组件是 Google BigQuery Storage 的 PHP 风格客户端。

Latest Stable Version Packagist

注意: 此存储库是 Google Cloud PHP 的一部分(https://github.com/googleapis/google-cloud-php)。有关支持请求、错误报告或开发贡献,请参阅该项目。

安装

首先,安装 PHP 的首选依赖管理器 Composer

现在安装此组件

$ composer require google/cloud-bigquery-storage

此组件支持通过 HTTP/1.1 的 REST 和 gRPC。为了利用 gRPC 提供的好处(例如流式方法),请参阅我们的 gRPC 安装指南

身份验证

请参阅我们的 身份验证指南 了解有关身份验证客户端的更多信息。一旦认证,您就可以开始发送请求。

示例

require 'vendor/autoload.php';

use Google\Cloud\BigQuery\Storage\V1\BigQueryReadClient;
use Google\Cloud\BigQuery\Storage\V1\DataFormat;
use Google\Cloud\BigQuery\Storage\V1\ReadSession;
use Google\Cloud\BigQuery\Storage\V1\ReadSession\TableReadOptions;

$client = new BigQueryReadClient();

$project = sprintf(
    'projects/%s',
    '[MY_PROJECT_ID]'
);
$table = sprintf(
    'projects/%s/datasets/%s/tables/%s',
    'bigquery-public-data',
    'usa_names',
    'usa_1910_current'
);
$readOptions = (new TableReadOptions())
    ->setRowRestriction('state = "WA"');
$readSession = (new ReadSession())
    ->setTable($table)
    ->setDataFormat(DataFormat::AVRO)
    ->setReadOptions($readOptions);
$session = $client->createReadSession([
    'parent' => $project,
    'readSession' => $readSession,
    'maxStreamCount' => 1
]);

$stream = $client->readRows([
    'readStream' => $session->getStreams()[0]->getName()
]);

foreach ($stream->readAll() as $response) {
    printf(
        'Discovered %s rows in response.' . PHP_EOL,
        $response->getRowCount()
    );
}

版本

此组件被认为是 GA(通常可用)。因此,它不会在次要或补丁版本中引入不兼容的更改。我们将优先处理问题和请求。

下一步

  1. 了解 官方文档