See https://cloud.google.com/bigquery/docs/reference/rest/v2/routines
+ */
+ public abstract Builder setDataGovernanceType(String dataGovernanceType);
+
/** Creates a {@code RoutineInfo} object. */
public abstract RoutineInfo build();
}
@@ -177,6 +186,8 @@ static class BuilderImpl extends Builder {
private String body;
private RemoteFunctionOptions remoteFunctionOptions;
+ private String dataGovernanceType;
+
BuilderImpl() {}
BuilderImpl(RoutineInfo routineInfo) {
@@ -194,6 +205,7 @@ static class BuilderImpl extends Builder {
this.importedLibrariesList = routineInfo.importedLibrariesList;
this.body = routineInfo.body;
this.remoteFunctionOptions = routineInfo.remoteFunctionOptions;
+ this.dataGovernanceType = routineInfo.dataGovernanceType;
}
BuilderImpl(Routine routinePb) {
@@ -225,6 +237,7 @@ static class BuilderImpl extends Builder {
this.remoteFunctionOptions =
RemoteFunctionOptions.fromPb(routinePb.getRemoteFunctionOptions());
}
+ this.dataGovernanceType = routinePb.getDataGovernanceType();
}
@Override
@@ -311,6 +324,12 @@ public Builder setRemoteFunctionOptions(RemoteFunctionOptions remoteFunctionOpti
return this;
}
+ @Override
+ public Builder setDataGovernanceType(String dataGovernanceType) {
+ this.dataGovernanceType = dataGovernanceType;
+ return this;
+ }
+
@Override
public RoutineInfo build() {
return new RoutineInfo(this);
@@ -332,6 +351,7 @@ public RoutineInfo build() {
this.importedLibrariesList = builder.importedLibrariesList;
this.body = builder.body;
this.remoteFunctionOptions = builder.remoteFunctionOptions;
+ this.dataGovernanceType = builder.dataGovernanceType;
}
/** Returns the RoutineId identified for the routine resource. * */
@@ -411,6 +431,11 @@ public RemoteFunctionOptions getRemoteFunctionOptions() {
return remoteFunctionOptions;
};
+ /** Returns the data governance type of the routine, e.g. DATA_MASKING. */
+ public String getDataGovernanceType() {
+ return dataGovernanceType;
+ }
+
/** Returns a builder pre-populated using the current values of this routine. */
public Builder toBuilder() {
return new BuilderImpl(this);
@@ -433,6 +458,7 @@ public String toString() {
.add("importedLibrariesList", importedLibrariesList)
.add("body", body)
.add("remoteFunctionOptions", remoteFunctionOptions)
+ .add("dataGovernanceType", dataGovernanceType)
.toString();
}
@@ -452,7 +478,8 @@ public int hashCode() {
returnTableType,
importedLibrariesList,
body,
- remoteFunctionOptions);
+ remoteFunctionOptions,
+ dataGovernanceType);
}
@Override
@@ -490,7 +517,8 @@ Routine toPb() {
.setDescription(getDescription())
.setDeterminismLevel(getDeterminismLevel())
.setLastModifiedTime(getLastModifiedTime())
- .setLanguage(getLanguage());
+ .setLanguage(getLanguage())
+ .setDataGovernanceType(getDataGovernanceType());
if (getRoutineId() != null) {
routinePb.setRoutineReference(getRoutineId().toPb());
}
@@ -506,6 +534,9 @@ Routine toPb() {
if (getRemoteFunctionOptions() != null) {
routinePb.setRemoteFunctionOptions(getRemoteFunctionOptions().toPb());
}
+ if (getImportedLibraries() != null) {
+ routinePb.setImportedLibraries(getImportedLibraries());
+ }
return routinePb;
}
diff --git a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/JobStatisticsTest.java b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/JobStatisticsTest.java
index af75a2391e..f32832b594 100644
--- a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/JobStatisticsTest.java
+++ b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/JobStatisticsTest.java
@@ -97,6 +97,7 @@ public class JobStatisticsTest {
.setEndTime(END_TIME)
.setStartTime(START_TIME)
.setDestinationUriFileCounts(FILE_COUNT)
+ .setInputBytes(INPUT_BYTES)
.build();
private static final LoadStatistics LOAD_STATISTICS =
LoadStatistics.newBuilder()
@@ -249,6 +250,7 @@ public void testBuilder() {
assertEquals(START_TIME, EXTRACT_STATISTICS.getStartTime());
assertEquals(END_TIME, EXTRACT_STATISTICS.getEndTime());
assertEquals(FILE_COUNT, EXTRACT_STATISTICS.getDestinationUriFileCounts());
+ assertEquals(INPUT_BYTES, EXTRACT_STATISTICS.getInputBytes());
assertEquals(CREATION_TIME, LOAD_STATISTICS.getCreationTime());
assertEquals(START_TIME, LOAD_STATISTICS.getStartTime());
@@ -385,6 +387,7 @@ private void compareExtractStatistics(ExtractStatistics expected, ExtractStatist
assertEquals(expected, value);
compareStatistics(expected, value);
assertEquals(expected.getDestinationUriFileCounts(), value.getDestinationUriFileCounts());
+ assertEquals(expected.getInputBytes(), value.getInputBytes());
}
private void compareLoadStatistics(LoadStatistics expected, LoadStatistics value) {
diff --git a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/RoutineInfoTest.java b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/RoutineInfoTest.java
index 1f1181433b..ae061b62f8 100644
--- a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/RoutineInfoTest.java
+++ b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/RoutineInfoTest.java
@@ -33,6 +33,8 @@ public class RoutineInfoTest {
private static final Long LAST_MODIFIED_TIME = 20L;
private static final String LANGUAGE = "SQL";
+ private static final String DATA_GOVERNANCE_TYPE = "DATA_MASKING";
+
private static final RoutineArgument ARG_1 =
RoutineArgument.newBuilder()
.setDataType(StandardSQLDataType.newBuilder("STRING").build())
@@ -63,6 +65,7 @@ public class RoutineInfoTest {
.setReturnType(RETURN_TYPE)
.setImportedLibraries(IMPORTED_LIBRARIES)
.setBody(BODY)
+ .setDataGovernanceType(DATA_GOVERNANCE_TYPE)
.build();
@Test
@@ -90,6 +93,7 @@ public void testBuilder() {
assertEquals(RETURN_TYPE, ROUTINE_INFO.getReturnType());
assertEquals(IMPORTED_LIBRARIES, ROUTINE_INFO.getImportedLibraries());
assertEquals(BODY, ROUTINE_INFO.getBody());
+ assertEquals(DATA_GOVERNANCE_TYPE, ROUTINE_INFO.getDataGovernanceType());
}
@Test
@@ -107,8 +111,10 @@ public void testOf() {
assertNull(routineInfo.getReturnType());
assertNull(routineInfo.getImportedLibraries());
assertNull(routineInfo.getBody());
+ assertNull(routineInfo.getDataGovernanceType());
}
+ @Test
public void testToAndFromPb() {
compareRoutineInfo(ROUTINE_INFO, RoutineInfo.fromPb(ROUTINE_INFO.toPb()));
}
@@ -132,6 +138,7 @@ public void compareRoutineInfo(RoutineInfo expected, RoutineInfo value) {
assertEquals(expected.getReturnType(), value.getReturnType());
assertEquals(expected.getImportedLibraries(), value.getImportedLibraries());
assertEquals(expected.getBody(), value.getBody());
+ assertEquals(expected.getDataGovernanceType(), value.getDataGovernanceType());
assertEquals(expected.hashCode(), value.hashCode());
assertEquals(expected.toString(), value.toString());
}
diff --git a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/RoutineTest.java b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/RoutineTest.java
index c9080e851a..eaf1420120 100644
--- a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/RoutineTest.java
+++ b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/RoutineTest.java
@@ -91,6 +91,8 @@ public class RoutineTest {
.setMaxBatchingRows(10L)
.build();
+ private static final String DATA_GOVERNANCE_TYPE = "DATA_MASKING";
+
private static final RoutineInfo ROUTINE_INFO =
RoutineInfo.newBuilder(ROUTINE_ID)
.setEtag(ETAG)
@@ -104,6 +106,7 @@ public class RoutineTest {
.setImportedLibraries(IMPORTED_LIBRARIES)
.setBody(BODY)
.setRemoteFunctionOptions(REMOTE_FUNCTION_OPTIONS)
+ .setDataGovernanceType(DATA_GOVERNANCE_TYPE)
.build();
private static final RoutineInfo ROUTINE_INFO_TVF =
@@ -146,6 +149,7 @@ public void testBuilder() {
.setImportedLibraries(IMPORTED_LIBRARIES)
.setBody(BODY)
.setRemoteFunctionOptions(REMOTE_FUNCTION_OPTIONS)
+ .setDataGovernanceType(DATA_GOVERNANCE_TYPE)
.build();
assertEquals(ETAG, builtRoutine.getEtag());
assertEquals(DETERMINISM_LEVEL, builtRoutine.getDeterminismLevel());
@@ -247,5 +251,6 @@ public void compareRoutineInfo(RoutineInfo expected, RoutineInfo value) {
assertEquals(expected.getBody(), value.getBody());
assertEquals(expected.hashCode(), value.hashCode());
assertEquals(expected.getRemoteFunctionOptions(), value.getRemoteFunctionOptions());
+ assertEquals(expected.getDataGovernanceType(), value.getDataGovernanceType());
}
}
diff --git a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java
index 8cada3e084..7bdb7a7fb0 100644
--- a/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java
+++ b/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java
@@ -87,6 +87,7 @@
import com.google.cloud.bigquery.JobId;
import com.google.cloud.bigquery.JobInfo;
import com.google.cloud.bigquery.JobStatistics;
+import com.google.cloud.bigquery.JobStatistics.ExtractStatistics;
import com.google.cloud.bigquery.JobStatistics.LoadStatistics;
import com.google.cloud.bigquery.JobStatistics.QueryStatistics;
import com.google.cloud.bigquery.JobStatistics.QueryStatistics.StatementType;
@@ -2683,6 +2684,33 @@ public void testRoutineAPICreationTVF() {
assertEquals(routine.getReturnTableType(), returnTableType);
}
+ @Test
+ public void testRoutineDataGovernanceType() {
+ String routineName = RemoteBigQueryHelper.generateRoutineName();
+ RoutineId routineId = RoutineId.of(ROUTINE_DATASET, routineName);
+ RoutineInfo routineInfo =
+ RoutineInfo.newBuilder(routineId)
+ .setLanguage("SQL")
+ .setRoutineType("SCALAR_FUNCTION")
+ .setBody("x")
+ .setArguments(
+ ImmutableList.of(
+ RoutineArgument.newBuilder()
+ .setName("x")
+ .setDataType(StandardSQLDataType.newBuilder("INT64").build())
+ .build()))
+ .setReturnType(StandardSQLDataType.newBuilder("INT64").build())
+ .setDataGovernanceType("DATA_MASKING")
+ .build();
+
+ Routine routine = bigquery.create(routineInfo);
+ assertNotNull(routine);
+ assertEquals(routine.getLanguage(), "SQL");
+ assertEquals(routine.getRoutineType(), "SCALAR_FUNCTION");
+ assertEquals(routine.getReturnType(), StandardSQLDataType.newBuilder("INT64").build());
+ assertEquals(routine.getDataGovernanceType(), "DATA_MASKING");
+ }
+
@Test
public void testAuthorizeRoutine() {
String routineName = RemoteBigQueryHelper.generateRoutineName();
@@ -5304,6 +5332,8 @@ public void testExtractJob() throws InterruptedException, TimeoutException {
assertNull(remoteLoadJob.getStatus().getError());
LoadJobConfiguration loadJobConfiguration = remoteLoadJob.getConfiguration();
assertEquals(labels, loadJobConfiguration.getLabels());
+ LoadStatistics loadStatistics = remoteLoadJob.getStatistics();
+ assertNotNull(loadStatistics);
ExtractJobConfiguration extractConfiguration =
ExtractJobConfiguration.newBuilder(destinationTable, "gs://" + BUCKET + "/" + EXTRACT_FILE)
@@ -5313,6 +5343,12 @@ public void testExtractJob() throws InterruptedException, TimeoutException {
remoteExtractJob = remoteExtractJob.waitFor();
assertNull(remoteExtractJob.getStatus().getError());
+ ExtractStatistics extractStatistics = remoteExtractJob.getStatistics();
+ assertNotNull(extractStatistics);
+ assertEquals(1L, extractStatistics.getDestinationUriFileCounts().size());
+ assertEquals(
+ loadStatistics.getOutputBytes().longValue(), extractStatistics.getInputBytes().longValue());
+
String extractedCsv =
new String(storage.readAllBytes(BUCKET, EXTRACT_FILE), StandardCharsets.UTF_8);
assertEquals(
diff --git a/pom.xml b/pom.xml
index 616aa52765..04dacf945c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@