Skip to content

Commit

Permalink
feat: Add Routine DataGovernanceType (#3006)
Browse files Browse the repository at this point in the history
* feat: Add Routine DataGovernanceType

This also:
- fix an issue where RoutineInfo unit test was being skipped
- fix an issue where ImportLibaries were not being exported in the toPb method

* 🦉 Updates from OwlBot post-processor

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

* fix: Add DataGovernanceType to clirr ignored difference

---------

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
  • Loading branch information
PhongChuong and gcf-owl-bot[bot] authored Nov 30, 2023
1 parent 79959e5 commit ecb567b
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 2 deletions.
5 changes: 5 additions & 0 deletions google-cloud-bigquery/clirr-ignored-differences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
<className>com/google/cloud/bigquery/ExternalTableDefinition*</className>
<method>*ReferenceFileSchemaUri(*)</method>
</difference>
<difference>
<differenceType>7013</differenceType>
<className>com/google/cloud/bigquery/RoutineInfo*</className>
<method>*DataGovernanceType(*)</method>
</difference>
<difference>
<differenceType>7013</differenceType>
<className>com/google/cloud/bigquery/RoutineInfo*</className>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,12 @@ public Builder setRemoteFunctionOptions(RemoteFunctionOptions remoteFunctionOpti
return this;
}

@Override
public Builder setDataGovernanceType(String dataGovernanceType) {
infoBuilder.setDataGovernanceType(dataGovernanceType);
return this;
}

@Override
public Routine build() {
return new Routine(bigquery, infoBuilder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ public Routine apply(RoutineInfo routineInfo) {
private final String body;
private final RemoteFunctionOptions remoteFunctionOptions;

private final String dataGovernanceType;

public abstract static class Builder {

abstract Builder setRoutineId(RoutineId id);
Expand Down Expand Up @@ -157,6 +159,13 @@ public abstract static class Builder {
*/
public abstract Builder setRemoteFunctionOptions(RemoteFunctionOptions remoteFunctionOptions);

/**
* Sets the data governance type for the Builder (e.g. DATA_MASKING).
*
* <p>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();
}
Expand All @@ -177,6 +186,8 @@ static class BuilderImpl extends Builder {
private String body;
private RemoteFunctionOptions remoteFunctionOptions;

private String dataGovernanceType;

BuilderImpl() {}

BuilderImpl(RoutineInfo routineInfo) {
Expand All @@ -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) {
Expand Down Expand Up @@ -225,6 +237,7 @@ static class BuilderImpl extends Builder {
this.remoteFunctionOptions =
RemoteFunctionOptions.fromPb(routinePb.getRemoteFunctionOptions());
}
this.dataGovernanceType = routinePb.getDataGovernanceType();
}

@Override
Expand Down Expand Up @@ -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);
Expand All @@ -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. * */
Expand Down Expand Up @@ -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);
Expand All @@ -433,6 +458,7 @@ public String toString() {
.add("importedLibrariesList", importedLibrariesList)
.add("body", body)
.add("remoteFunctionOptions", remoteFunctionOptions)
.add("dataGovernanceType", dataGovernanceType)
.toString();
}

Expand All @@ -452,7 +478,8 @@ public int hashCode() {
returnTableType,
importedLibrariesList,
body,
remoteFunctionOptions);
remoteFunctionOptions,
dataGovernanceType);
}

@Override
Expand Down Expand Up @@ -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());
}
Expand All @@ -506,6 +534,9 @@ Routine toPb() {
if (getRemoteFunctionOptions() != null) {
routinePb.setRemoteFunctionOptions(getRemoteFunctionOptions().toPb());
}
if (getImportedLibraries() != null) {
routinePb.setImportedLibraries(getImportedLibraries());
}
return routinePb;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -63,6 +65,7 @@ public class RoutineInfoTest {
.setReturnType(RETURN_TYPE)
.setImportedLibraries(IMPORTED_LIBRARIES)
.setBody(BODY)
.setDataGovernanceType(DATA_GOVERNANCE_TYPE)
.build();

@Test
Expand Down Expand Up @@ -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
Expand All @@ -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()));
}
Expand All @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 =
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2684,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();
Expand Down

0 comments on commit ecb567b

Please sign in to comment.