Skip to content

Commit

Permalink
feat: add destinationExpirationTime to CopyJobConfiguration (#2031)
Browse files Browse the repository at this point in the history
* Add destinationExpirationTime

* Added testDestExpTimeTableCopyJob IT

* Added testDestExpTimeTableCopyJob IT

* Removed testDestExpTimeTableCopyJob IT. Modified testCopyJobWithLabelsAndExpTime to add destinationExpiryTime

* Modified Builder to add destinationExpiryTime

* Modified testCopyJobWithLabelsAndExpTime. Added assertion for destinationExpiryTime

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
  • Loading branch information
prash-mi and gcf-owl-bot[bot] authored May 31, 2022
1 parent 7f09014 commit 9e0b351
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public final class CopyJobConfiguration extends JobConfiguration {
private final List<TableId> sourceTables;
private final TableId destinationTable;
private final String operationType;
private final String destinationExpirationTime;
private final JobInfo.CreateDisposition createDisposition;
private final JobInfo.WriteDisposition writeDisposition;
private final EncryptionConfiguration destinationEncryptionConfiguration;
Expand All @@ -51,6 +52,7 @@ public static final class Builder
private List<TableId> sourceTables;
private TableId destinationTable;
private String operationType;
private String destinationExpirationTime;
private JobInfo.CreateDisposition createDisposition;
private JobInfo.WriteDisposition writeDisposition;
private EncryptionConfiguration destinationEncryptionConfiguration;
Expand All @@ -66,6 +68,7 @@ private Builder(CopyJobConfiguration jobConfiguration) {
this.sourceTables = jobConfiguration.sourceTables;
this.destinationTable = jobConfiguration.destinationTable;
this.operationType = jobConfiguration.operationType;
this.destinationExpirationTime = jobConfiguration.destinationExpirationTime;
this.createDisposition = jobConfiguration.createDisposition;
this.writeDisposition = jobConfiguration.writeDisposition;
this.destinationEncryptionConfiguration = jobConfiguration.destinationEncryptionConfiguration;
Expand All @@ -80,6 +83,10 @@ private Builder(com.google.api.services.bigquery.model.JobConfiguration configur
if (copyConfigurationPb.getOperationType() != null) {
this.operationType = copyConfigurationPb.getOperationType();
}
if (copyConfigurationPb.getDestinationExpirationTime() != null) {
this.destinationExpirationTime =
copyConfigurationPb.getDestinationExpirationTime().toString();
}
if (copyConfigurationPb.getSourceTables() != null) {
this.sourceTables =
Lists.transform(copyConfigurationPb.getSourceTables(), TableId.FROM_PB_FUNCTION);
Expand Down Expand Up @@ -129,6 +136,16 @@ public Builder setOperationType(String operationType) {
return this;
}

/**
* Sets the time when the destination table expires. Expired tables will be deleted and their
* storage reclaimed. More info:
* https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#jobconfigurationtablecopy
*/
public Builder setDestinationExpirationTime(String destinationExpirationTime) {
this.destinationExpirationTime = destinationExpirationTime;
return this;
}

public Builder setDestinationEncryptionConfiguration(
EncryptionConfiguration encryptionConfiguration) {
this.destinationEncryptionConfiguration = encryptionConfiguration;
Expand Down Expand Up @@ -194,6 +211,7 @@ private CopyJobConfiguration(Builder builder) {
this.sourceTables = checkNotNull(builder.sourceTables);
this.destinationTable = checkNotNull(builder.destinationTable);
this.operationType = builder.operationType;
this.destinationExpirationTime = builder.destinationExpirationTime;
this.createDisposition = builder.createDisposition;
this.writeDisposition = builder.writeDisposition;
this.destinationEncryptionConfiguration = builder.destinationEncryptionConfiguration;
Expand All @@ -216,6 +234,11 @@ public String getOperationType() {
return operationType;
}

/** Returns the time when the destination table expires */
public String getDestinationExpirationTime() {
return destinationExpirationTime;
}

public EncryptionConfiguration getDestinationEncryptionConfiguration() {
return destinationEncryptionConfiguration;
}
Expand Down Expand Up @@ -263,6 +286,7 @@ ToStringHelper toStringHelper() {
.add("sourceTables", sourceTables)
.add("destinationTable", destinationTable)
.add("operationType", operationType)
.add("destinationExpirationTime", destinationExpirationTime)
.add("destinationEncryptionConfiguration", destinationEncryptionConfiguration)
.add("createDisposition", createDisposition)
.add("writeDisposition", writeDisposition)
Expand All @@ -283,6 +307,7 @@ public int hashCode() {
sourceTables,
destinationTable,
operationType,
destinationExpirationTime,
createDisposition,
writeDisposition,
labels,
Expand Down Expand Up @@ -322,6 +347,9 @@ com.google.api.services.bigquery.model.JobConfiguration toPb() {
if (operationType != null) {
configurationPb.setOperationType(operationType);
}
if (destinationExpirationTime != null) {
configurationPb.setDestinationExpirationTime(destinationExpirationTime);
}
if (createDisposition != null) {
configurationPb.setCreateDisposition(createDisposition.toString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3893,7 +3893,8 @@ public void testSnapshotTableCopyJob() throws InterruptedException {
}

@Test
public void testCopyJobWithLabels() throws InterruptedException {
public void testCopyJobWithLabelsAndExpTime() throws InterruptedException {
String destExpiryTime = "2025-12-31T23:59:59.999999999Z";
String sourceTableName = "test_copy_job_source_table_label";
String destinationTableName = "test_copy_job_destination_table_label";
Map<String, String> labels = ImmutableMap.of("test_job_name", "test_copy_job");
Expand All @@ -3904,12 +3905,17 @@ public void testCopyJobWithLabels() throws InterruptedException {
assertNotNull(createdTable);
TableId destinationTable = TableId.of(DATASET, destinationTableName);
CopyJobConfiguration configuration =
CopyJobConfiguration.newBuilder(destinationTable, sourceTable).setLabels(labels).build();
CopyJobConfiguration.newBuilder(destinationTable, sourceTable)
.setLabels(labels)
.setDestinationExpirationTime(destExpiryTime)
.build();
Job remoteJob = bigquery.create(JobInfo.of(configuration));
remoteJob = remoteJob.waitFor();
assertNull(remoteJob.getStatus().getError());
CopyJobConfiguration copyJobConfiguration = remoteJob.getConfiguration();
assertEquals(labels, copyJobConfiguration.getLabels());
assertNotNull(copyJobConfiguration.getDestinationExpirationTime());
assertEquals(destExpiryTime, copyJobConfiguration.getDestinationExpirationTime());
Table remoteTable = bigquery.getTable(DATASET, destinationTableName);
assertNotNull(remoteTable);
assertTrue(createdTable.delete());
Expand Down

0 comments on commit 9e0b351

Please sign in to comment.