Skip to content

Commit

Permalink
fix: Set policy tags to empty instead of null
Browse files Browse the repository at this point in the history
When BigQuery returns policy tag object without names, policy tags will have names field set to
null (instead of the policy tags object itself set to null) to be consistent with the REST api.
  • Loading branch information
Tamer Abdulradi committed Jul 14, 2020
1 parent a6d9491 commit 3312baf
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
Expand Up @@ -60,10 +60,11 @@ com.google.api.services.bigquery.model.TableFieldSchema.PolicyTags toPb() {

static PolicyTags fromPb(
com.google.api.services.bigquery.model.TableFieldSchema.PolicyTags tagPb) {
// Treat a PolicyTag message without a Names subfield as invalid.
Builder builder = newBuilder();
// Treat a PolicyTag message without a Names subfield as empty.
if (tagPb.getNames() != null) {
return newBuilder().setNames(tagPb.getNames()).build();
builder = builder.setNames(tagPb.getNames());
}
return null;
return builder.build();
}
}
Expand Up @@ -51,7 +51,7 @@ public void testBuilder() {
public void testWithoutNames() {
com.google.api.services.bigquery.model.TableFieldSchema.PolicyTags PARTIALTAG =
new com.google.api.services.bigquery.model.TableFieldSchema.PolicyTags();
assertNull(PolicyTags.fromPb(PARTIALTAG));
assertNull(PolicyTags.fromPb(PARTIALTAG).getNames());
}

@Test
Expand Down

0 comments on commit 3312baf

Please sign in to comment.