Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Streaming data to BQ using Storage Write API not possible #8063

Open
andriussev opened this issue Jan 30, 2025 · 0 comments
Open

Streaming data to BQ using Storage Write API not possible #8063

andriussev opened this issue Jan 30, 2025 · 0 comments

Comments

@andriussev
Copy link

Environment details

  • OS: Windows/Mac
  • PHP version: 8.2/8.3
  • Package name and version: google/cloud-bigquery-storage v2.1.3

Steps to reproduce

It seems to be impossible write data because of descriptor_fix.php (though it might be solving other issues).

I couldn't find any other way to use AppendRows other than using Proto-stuffs functionality.

The provided sample does not relieve the pain of explaining how data is sent.

There are mentions of fixes and AppendsRows, mainly by @bshaffer , but I could not find any information on how to move forward without using Proto-stuffs.

Code example

// prerequisites
$bigQueryWriteClient = new BigQueryWriteClient();
$parent = 'pathhere';

// setup the structure
$row = new Struct();
$row->setFields([
	'impressions' => (new Value())->setNumberValue(213),
]);
$protoRows = new ProtoRows();
$protoRows->setSerializedRows([$row->serializeToString()]);
// add the data
$protoData = new ProtoData([
	'rows' => $protoRows,
]);
// set the schema, which requires the descriptor
$protoData->setWriterSchema(new ProtoSchema([
	'proto_descriptor' => new \Google\Protobuf\DescriptorProto(),
]));

// create the append rows request
$appendRowsRequest = new AppendRowsRequest([
	'write_stream' => $parent . '/streams/_default',
	'proto_rows' => $protoData
]);

// do the writing
$stream = $bigQueryWriteClient->appendRows();
$stream->write($appendRowsRequest);

// finalize
foreach ($stream->closeWriteAndReadAll() as $element) {
	printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant