높은 처리량으로 테이블 데이터를 읽기 위해 Google Cloud BigQuery Storage Read gRPC API를 호출하는 형식화된 인터페이스입니다.
BigQuery Storage Read API는 BigQuery 테이블 데이터에 대한 빠르고 높은 처리량의 접근을 제공합니다. gRPC API는 google.cloud.bigquery.storage.v1.BigQueryRead 서비스를 통해 제공되며, TLS를 통해 bigquerystorage.googleapis.com:443에서 접근하고, 주요 메서드는 CreateReadSession 및 ReadRows(서버 스트리밍)입니다.
요청은 TsgcGRPCBigQueryCreateReadSessionRequest로 작성되며, 이는 Parent(projects/<id>), ReadSession.Table(projects/<id>/datasets/<ds>/tables/<tbl>), ReadSession.DataFormat(1 = AVRO, 2 = ARROW) 및 MaxStreamCount를 설정합니다. 세션 응답은 스트림 이름을 전달하며, 이는 이후 서버 스트리밍 ReadRows 메서드로 읽습니다.
아래 예제는 서비스 계정 JWT로 인증하고, BigQuery Storage 호스트에 대해 TsgcHTTP2Client 위에 TsgcGRPCClient를 연결하고, authorization Bearer 메타데이터를 설정한 후, AVRO 데이터 형식을 사용하여 테이블에 대해 CreateReadSession을 호출합니다.
TsgcHTTP2Client *oHTTP2 = new TsgcHTTP2Client();
oHTTP2->Host = "bigquerystorage.googleapis.com";
oHTTP2->Port = 443;
oHTTP2->TLS = true;
TsgcGRPCClient *oGRPC = new TsgcGRPCClient();
oGRPC->Client = oHTTP2;
// service-account JWT authentication
oGRPC->GoogleCloudOptions->JWT->KeyFile = "service-account.json";
oGRPC->GoogleCloudOptions->JWT->API_Endpoint = "https://bigquerystorage.googleapis.com/";
oGRPC->DefaultMetadata->AddValue("authorization", "Bearer " + oGRPC->GoogleCloudOptions->JWT->Token);
// build the typed request and call the method
TsgcGRPCBigQueryCreateReadSessionRequest *oRequest = new TsgcGRPCBigQueryCreateReadSessionRequest();
oRequest->Parent = "projects/my-project-id";
oRequest->ReadSession->Table = "projects/my-project-id/datasets/my_dataset/tables/my_table";
oRequest->ReadSession->DataFormat = 1; // 1 = AVRO, 2 = ARROW
oRequest->MaxStreamCount = 1;
TsgcGRPCResponse *oResponse = oGRPC->Call("google.cloud.bigquery.storage.v1.BigQueryRead", "CreateReadSession", oRequest->ToBytes());
ShowMessage(oResponse->DataString);
delete oRequest;
| Name | 설명 |
|---|---|
| CreateReadSession | 테이블에 대한 읽기 세션을 생성하고 병렬로 읽을 수 있는 스트림을 반환합니다. |
| ReadRows | 읽기 세션에서 스트림의 행을 읽는 서버 스트리밍 메서드입니다. |
작동하는 샘플은 데모 폴더 Demos/21.GRPC/16.BigQuery에서 제공되며, 인증하고 읽기 세션을 생성하며 테이블의 행을 스트리밍하는 방법을 보여줍니다.