Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add destinationExpirationTime to CopyJobConfiguration #2031

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Expand Up @@ -52,20 +52,20 @@ If you are using Maven without BOM, add this to your dependencies:
If you are using Gradle 5.x or later, add this to your dependencies

```Groovy
implementation platform('com.google.cloud:libraries-bom:25.2.0')
implementation platform('com.google.cloud:libraries-bom:25.3.0')

implementation 'com.google.cloud:google-cloud-bigquery'
```
If you are using Gradle without BOM, add this to your dependencies

```Groovy
implementation 'com.google.cloud:google-cloud-bigquery:2.10.10'
implementation 'com.google.cloud:google-cloud-bigquery:2.12.0'
```

If you are using SBT, add this to your dependencies

```Scala
libraryDependencies += "com.google.cloud" % "google-cloud-bigquery" % "2.10.10"
libraryDependencies += "com.google.cloud" % "google-cloud-bigquery" % "2.12.0"
```

## Authentication
Expand Down
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
Expand Up @@ -3880,7 +3880,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 @@ -3891,12 +3892,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