Allow setting BigQuery endpoint#32153
Conversation
|
Checks are failing. Will not request review until checks are succeeding. If you'd like to override that behavior, comment |
|
assign set of reviewers |
|
Assigning reviewers. If you would like to opt out of this review, comment R: @Abacn for label java. Available commands:
The PR bot will only process comments in the main thread (not review comments). |
86a5872 to
f6b612a
Compare
|
@Abacn @damondouglas could you please have a look? Basically, I just followed the same pattern as with |
Abacn
left a comment
There was a problem hiding this comment.
Thanks! The change looks good, just left a few minor formatting comments
CHANGES.md
Outdated
There was a problem hiding this comment.
shall we note that this is for testing purpose? Endpoint can be ambiguous (e.g. regional/zonal endpoint/ like Dataflow endpoint)
consider "BigQuery endpoint can be overridden via PipelineOptions, this enables BigQuery emulators (Java)"
There was a problem hiding this comment.
a safer guard is Strings.isNullOrEmpty
f6b612a to
dc0cbab
Compare
|
Thanks @Abacn , addressed your comments |
|
Reminder, please take a look at this pr: @Abacn @damondouglas |
|
Hello, Thank you for this new feature. May I ask you @kberezin-nshl how you intend the user to use this new possibilities ? I've tried to use test container for my pipeline, but I still get the error message I use TestContainer and TestPipeline BigQueryEmulatorContainer container = new BigQueryEmulatorContainer("ghcr.io/goccy/bigquery-emulator:0.4.3");
String projectId = container.getProjectId();
org.apache.beam.sdk.io.gcp.bigquery.BigQueryOptions pipelineOptions = PipelineOptionsFactory.create().as(org.apache.beam.sdk.io.gcp.bigquery.BigQueryOptions.class);
pipelineOptions.setBigQueryEndpoint(container.getEmulatorHttpEndpoint());
BigQueryServicesImpl bqService = new BigQueryServicesImpl();
bqService.getJobService(pipelineOptions);
Session session = buildExpectedSession();
WriteResult writeResult = p.apply(Create.of(session))
.apply(ParDo.of(new ProtobufSessionToBigQueryTableRow()))
.apply(BigQueryIO.writeTableRows()
.withTestServices(bqService)
.to(row -> {
return new TableDestination(projectId+":***.***", null);
}));Thanks in advance for your help |
|
I have the same question as @wattache. I've tried the following: Still get the following error: |
|
I've updated on the previous example:
Now I'm getting an exception related to serialization: |
|
Unfortunately, currently there is a bug causing the behavior that you're seeing. The fix for that has been merged already, so hopefully you'll be able to use this feature with the next release. In the meantime, it is possible to have the following workaround, first create this class: public class WorkaroundBQServices extends BigQueryServicesImpl {
private final String bigQueryEndpoint;
public WorkaroundBQServices(String bigQueryEndpoint) {
this.bigQueryEndpoint = bigQueryEndpoint;
}
@Override
public JobService getJobService(BigQueryOptions options) {
options.setBigQueryEndpoint(bigQueryEndpoint);
return super.getJobService(options);
}
@Override
public DatasetService getDatasetService(BigQueryOptions options) {
options.setBigQueryEndpoint(bigQueryEndpoint);
return super.getDatasetService(options);
}
@Override
public WriteStreamService getWriteStreamService(BigQueryOptions options) {
options.setBigQueryEndpoint(bigQueryEndpoint);
return super.getWriteStreamService(options);
}
@Override
public StorageClient getStorageClient(BigQueryOptions options) throws IOException {
options.setBigQueryEndpoint(bigQueryEndpoint);
return super.getStorageClient(options);
}
}then in your pipeline, set it as BigQueryIO.<...>write()
.withTestServices(new WorkaroundBQServices(options.getBigQueryEndpoint()))As I said, once new release come out, you should be able to remove this workaround. |
|
@kberezin-nshl Thanks for the update, I have a follow up issue with the use of emulator, now related to credentials: I tried setting |
|
Another question, maybe related to the previous, is what to set on |
* Allow setting BigQuery endpoint * Changes.md update
This fixes #28149
Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:
addresses #123), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, commentfixes #<ISSUE NUMBER>instead.CHANGES.mdwith noteworthy changes.See the Contributor Guide for more tips on how to make review process smoother.
To check the build health, please visit https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md
GitHub Actions Tests Status (on master branch)
See CI.md for more information about GitHub Actions CI or the workflows README to see a list of phrases to trigger workflows.