Skip to content

Commit

Permalink
bug: adding getProjectId() when datasetInfo projectId is null (#21)
Browse files Browse the repository at this point in the history
* bug: adding getProjectId() when datasetInfo projectId is null

* bug: adding getProjectId() when datasetInfo projectId is null

* update based on comment
  • Loading branch information
stephaniewang526 committed Dec 11, 2019
1 parent 1b0b21b commit 841d075
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Expand Up @@ -202,7 +202,12 @@ public Page<FieldValueList> getNextPage() {
@Override
public Dataset create(DatasetInfo datasetInfo, DatasetOption... options) {
final com.google.api.services.bigquery.model.Dataset datasetPb =
datasetInfo.setProjectId(getOptions().getProjectId()).toPb();
datasetInfo
.setProjectId(
Strings.isNullOrEmpty(datasetInfo.getDatasetId().getProject())
? getOptions().getProjectId()
: datasetInfo.getDatasetId().getProject())
.toPb();
final Map<BigQueryRpc.Option, ?> optionsMap = optionMap(options);
try {
return Dataset.fromPb(
Expand Down
Expand Up @@ -478,7 +478,9 @@ public void testCreateDataset() {
EasyMock.expect(bigqueryRpcMock.create(datasetInfo.toPb(), EMPTY_RPC_OPTIONS))
.andReturn(datasetInfo.toPb());
EasyMock.replay(bigqueryRpcMock);
bigquery = options.getService();
BigQueryOptions bigQueryOptions =
createBigQueryOptionsForProject(OTHER_PROJECT, rpcFactoryMock);
bigquery = bigQueryOptions.getService();
Dataset dataset = bigquery.create(datasetInfo);
assertEquals(new Dataset(bigquery, new DatasetInfo.BuilderImpl(datasetInfo)), dataset);
}
Expand Down

0 comments on commit 841d075

Please sign in to comment.