Skip to content

Commit

Permalink
Add resource tags to Tables
Browse files Browse the repository at this point in the history
  • Loading branch information
PhongChuong committed Dec 8, 2023
1 parent 05651ca commit e0518c3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,12 @@ public Builder setLabels(Map<String, String> labels) {
return this;
}

@Override
public Builder setResourceTags(Map<String, String> resourceTags) {
infoBuilder.setResourceTags(resourceTags);
return this;
}

@Override
public Builder setRequirePartitionFilter(Boolean requirePartitionFilter) {
infoBuilder.setRequirePartitionFilter(requirePartitionFilter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ public Table apply(TableInfo tableInfo) {
private final TableDefinition definition;
private final EncryptionConfiguration encryptionConfiguration;
private final Annotations labels;

private final Annotations resourceTags;
private final Boolean requirePartitionFilter;
private final String defaultCollation;

Expand Down Expand Up @@ -152,6 +154,9 @@ public abstract static class Builder {
@BetaApi
public abstract Builder setLabels(Map<String, String> labels);

/** Sets the resource tags applied to this table. */
public abstract Builder setResourceTags(Map<String, String> resourceTags);

/** Creates a {@code TableInfo} object. */
public abstract TableInfo build();

Expand Down Expand Up @@ -192,6 +197,8 @@ static class BuilderImpl extends Builder {
private TableDefinition definition;
private EncryptionConfiguration encryptionConfiguration;
private Annotations labels = Annotations.ZERO;

private Annotations resourceTags = Annotations.ZERO;
private Boolean requirePartitionFilter;
private String defaultCollation;
private CloneDefinition cloneDefinition;
Expand Down Expand Up @@ -222,6 +229,7 @@ static class BuilderImpl extends Builder {
this.definition = tableInfo.definition;
this.encryptionConfiguration = tableInfo.encryptionConfiguration;
this.labels = tableInfo.labels;
this.resourceTags = tableInfo.resourceTags;
this.requirePartitionFilter = tableInfo.requirePartitionFilter;
this.defaultCollation = tableInfo.defaultCollation;
this.cloneDefinition = tableInfo.cloneDefinition;
Expand Down Expand Up @@ -256,6 +264,7 @@ static class BuilderImpl extends Builder {
new EncryptionConfiguration.Builder(tablePb.getEncryptionConfiguration()).build();
}
this.labels = Annotations.fromPb(tablePb.getLabels());
this.resourceTags = Annotations.fromPb(tablePb.getResourceTags());
this.requirePartitionFilter = tablePb.getRequirePartitionFilter();
this.defaultCollation = tablePb.getDefaultCollation();
if (tablePb.getCloneDefinition() != null) {
Expand Down Expand Up @@ -398,6 +407,12 @@ public Builder setLabels(Map<String, String> labels) {
return this;
}

@Override
public Builder setResourceTags(Map<String, String> resourceTags) {
this.resourceTags = Annotations.fromUser(resourceTags);
return this;
}

@Override
public Builder setRequirePartitionFilter(Boolean requirePartitionFilter) {
this.requirePartitionFilter = requirePartitionFilter;
Expand Down Expand Up @@ -449,6 +464,7 @@ public TableInfo build() {
this.definition = builder.definition;
this.encryptionConfiguration = builder.encryptionConfiguration;
this.labels = builder.labels;
this.resourceTags = builder.resourceTags;
this.requirePartitionFilter = builder.requirePartitionFilter;
this.defaultCollation = builder.defaultCollation;
this.cloneDefinition = builder.cloneDefinition;
Expand Down Expand Up @@ -610,6 +626,11 @@ public Map<String, String> getLabels() {
return labels.userMap();
}

/** Return a map for resource tags applied to the table. */
public Map<String, String> getResourceTags() {
return resourceTags.userMap();
}

/**
* Returns true if a partition filter (that can be used for partition elimination) is required for
* queries over this table.
Expand Down Expand Up @@ -660,6 +681,7 @@ public String toString() {
.add("definition", definition)
.add("encryptionConfiguration", encryptionConfiguration)
.add("labels", labels)
.add("resourceTags", resourceTags)
.add("requirePartitionFilter", requirePartitionFilter)
.add("defaultCollation", defaultCollation)
.add("cloneDefinition", cloneDefinition)
Expand Down Expand Up @@ -724,6 +746,7 @@ Table toPb() {
tablePb.setEncryptionConfiguration(encryptionConfiguration.toPb());
}
tablePb.setLabels(labels.toPb());
tablePb.setResourceTags(resourceTags.toPb());
tablePb.setRequirePartitionFilter(requirePartitionFilter);
if (defaultCollation != null) {
tablePb.setDefaultCollation(defaultCollation);
Expand Down

0 comments on commit e0518c3

Please sign in to comment.