Skip to content

Commit ecb567b

Browse files
feat: Add Routine DataGovernanceType (#3006)
* 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>
1 parent 79959e5 commit ecb567b

File tree

6 files changed

+83
-2
lines changed

6 files changed

+83
-2
lines changed

google-cloud-bigquery/clirr-ignored-differences.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919
<className>com/google/cloud/bigquery/ExternalTableDefinition*</className>
2020
<method>*ReferenceFileSchemaUri(*)</method>
2121
</difference>
22+
<difference>
23+
<differenceType>7013</differenceType>
24+
<className>com/google/cloud/bigquery/RoutineInfo*</className>
25+
<method>*DataGovernanceType(*)</method>
26+
</difference>
2227
<difference>
2328
<differenceType>7013</differenceType>
2429
<className>com/google/cloud/bigquery/RoutineInfo*</className>

google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/Routine.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,12 @@ public Builder setRemoteFunctionOptions(RemoteFunctionOptions remoteFunctionOpti
135135
return this;
136136
}
137137

138+
@Override
139+
public Builder setDataGovernanceType(String dataGovernanceType) {
140+
infoBuilder.setDataGovernanceType(dataGovernanceType);
141+
return this;
142+
}
143+
138144
@Override
139145
public Routine build() {
140146
return new Routine(bigquery, infoBuilder);

google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/RoutineInfo.java

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ public Routine apply(RoutineInfo routineInfo) {
7272
private final String body;
7373
private final RemoteFunctionOptions remoteFunctionOptions;
7474

75+
private final String dataGovernanceType;
76+
7577
public abstract static class Builder {
7678

7779
abstract Builder setRoutineId(RoutineId id);
@@ -157,6 +159,13 @@ public abstract static class Builder {
157159
*/
158160
public abstract Builder setRemoteFunctionOptions(RemoteFunctionOptions remoteFunctionOptions);
159161

162+
/**
163+
* Sets the data governance type for the Builder (e.g. DATA_MASKING).
164+
*
165+
* <p>See https://cloud.google.com/bigquery/docs/reference/rest/v2/routines
166+
*/
167+
public abstract Builder setDataGovernanceType(String dataGovernanceType);
168+
160169
/** Creates a {@code RoutineInfo} object. */
161170
public abstract RoutineInfo build();
162171
}
@@ -177,6 +186,8 @@ static class BuilderImpl extends Builder {
177186
private String body;
178187
private RemoteFunctionOptions remoteFunctionOptions;
179188

189+
private String dataGovernanceType;
190+
180191
BuilderImpl() {}
181192

182193
BuilderImpl(RoutineInfo routineInfo) {
@@ -194,6 +205,7 @@ static class BuilderImpl extends Builder {
194205
this.importedLibrariesList = routineInfo.importedLibrariesList;
195206
this.body = routineInfo.body;
196207
this.remoteFunctionOptions = routineInfo.remoteFunctionOptions;
208+
this.dataGovernanceType = routineInfo.dataGovernanceType;
197209
}
198210

199211
BuilderImpl(Routine routinePb) {
@@ -225,6 +237,7 @@ static class BuilderImpl extends Builder {
225237
this.remoteFunctionOptions =
226238
RemoteFunctionOptions.fromPb(routinePb.getRemoteFunctionOptions());
227239
}
240+
this.dataGovernanceType = routinePb.getDataGovernanceType();
228241
}
229242

230243
@Override
@@ -311,6 +324,12 @@ public Builder setRemoteFunctionOptions(RemoteFunctionOptions remoteFunctionOpti
311324
return this;
312325
}
313326

327+
@Override
328+
public Builder setDataGovernanceType(String dataGovernanceType) {
329+
this.dataGovernanceType = dataGovernanceType;
330+
return this;
331+
}
332+
314333
@Override
315334
public RoutineInfo build() {
316335
return new RoutineInfo(this);
@@ -332,6 +351,7 @@ public RoutineInfo build() {
332351
this.importedLibrariesList = builder.importedLibrariesList;
333352
this.body = builder.body;
334353
this.remoteFunctionOptions = builder.remoteFunctionOptions;
354+
this.dataGovernanceType = builder.dataGovernanceType;
335355
}
336356

337357
/** Returns the RoutineId identified for the routine resource. * */
@@ -411,6 +431,11 @@ public RemoteFunctionOptions getRemoteFunctionOptions() {
411431
return remoteFunctionOptions;
412432
};
413433

434+
/** Returns the data governance type of the routine, e.g. DATA_MASKING. */
435+
public String getDataGovernanceType() {
436+
return dataGovernanceType;
437+
}
438+
414439
/** Returns a builder pre-populated using the current values of this routine. */
415440
public Builder toBuilder() {
416441
return new BuilderImpl(this);
@@ -433,6 +458,7 @@ public String toString() {
433458
.add("importedLibrariesList", importedLibrariesList)
434459
.add("body", body)
435460
.add("remoteFunctionOptions", remoteFunctionOptions)
461+
.add("dataGovernanceType", dataGovernanceType)
436462
.toString();
437463
}
438464

@@ -452,7 +478,8 @@ public int hashCode() {
452478
returnTableType,
453479
importedLibrariesList,
454480
body,
455-
remoteFunctionOptions);
481+
remoteFunctionOptions,
482+
dataGovernanceType);
456483
}
457484

458485
@Override
@@ -490,7 +517,8 @@ Routine toPb() {
490517
.setDescription(getDescription())
491518
.setDeterminismLevel(getDeterminismLevel())
492519
.setLastModifiedTime(getLastModifiedTime())
493-
.setLanguage(getLanguage());
520+
.setLanguage(getLanguage())
521+
.setDataGovernanceType(getDataGovernanceType());
494522
if (getRoutineId() != null) {
495523
routinePb.setRoutineReference(getRoutineId().toPb());
496524
}
@@ -506,6 +534,9 @@ Routine toPb() {
506534
if (getRemoteFunctionOptions() != null) {
507535
routinePb.setRemoteFunctionOptions(getRemoteFunctionOptions().toPb());
508536
}
537+
if (getImportedLibraries() != null) {
538+
routinePb.setImportedLibraries(getImportedLibraries());
539+
}
509540
return routinePb;
510541
}
511542

google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/RoutineInfoTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ public class RoutineInfoTest {
3333
private static final Long LAST_MODIFIED_TIME = 20L;
3434
private static final String LANGUAGE = "SQL";
3535

36+
private static final String DATA_GOVERNANCE_TYPE = "DATA_MASKING";
37+
3638
private static final RoutineArgument ARG_1 =
3739
RoutineArgument.newBuilder()
3840
.setDataType(StandardSQLDataType.newBuilder("STRING").build())
@@ -63,6 +65,7 @@ public class RoutineInfoTest {
6365
.setReturnType(RETURN_TYPE)
6466
.setImportedLibraries(IMPORTED_LIBRARIES)
6567
.setBody(BODY)
68+
.setDataGovernanceType(DATA_GOVERNANCE_TYPE)
6669
.build();
6770

6871
@Test
@@ -90,6 +93,7 @@ public void testBuilder() {
9093
assertEquals(RETURN_TYPE, ROUTINE_INFO.getReturnType());
9194
assertEquals(IMPORTED_LIBRARIES, ROUTINE_INFO.getImportedLibraries());
9295
assertEquals(BODY, ROUTINE_INFO.getBody());
96+
assertEquals(DATA_GOVERNANCE_TYPE, ROUTINE_INFO.getDataGovernanceType());
9397
}
9498

9599
@Test
@@ -107,8 +111,10 @@ public void testOf() {
107111
assertNull(routineInfo.getReturnType());
108112
assertNull(routineInfo.getImportedLibraries());
109113
assertNull(routineInfo.getBody());
114+
assertNull(routineInfo.getDataGovernanceType());
110115
}
111116

117+
@Test
112118
public void testToAndFromPb() {
113119
compareRoutineInfo(ROUTINE_INFO, RoutineInfo.fromPb(ROUTINE_INFO.toPb()));
114120
}
@@ -132,6 +138,7 @@ public void compareRoutineInfo(RoutineInfo expected, RoutineInfo value) {
132138
assertEquals(expected.getReturnType(), value.getReturnType());
133139
assertEquals(expected.getImportedLibraries(), value.getImportedLibraries());
134140
assertEquals(expected.getBody(), value.getBody());
141+
assertEquals(expected.getDataGovernanceType(), value.getDataGovernanceType());
135142
assertEquals(expected.hashCode(), value.hashCode());
136143
assertEquals(expected.toString(), value.toString());
137144
}

google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/RoutineTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ public class RoutineTest {
9191
.setMaxBatchingRows(10L)
9292
.build();
9393

94+
private static final String DATA_GOVERNANCE_TYPE = "DATA_MASKING";
95+
9496
private static final RoutineInfo ROUTINE_INFO =
9597
RoutineInfo.newBuilder(ROUTINE_ID)
9698
.setEtag(ETAG)
@@ -104,6 +106,7 @@ public class RoutineTest {
104106
.setImportedLibraries(IMPORTED_LIBRARIES)
105107
.setBody(BODY)
106108
.setRemoteFunctionOptions(REMOTE_FUNCTION_OPTIONS)
109+
.setDataGovernanceType(DATA_GOVERNANCE_TYPE)
107110
.build();
108111

109112
private static final RoutineInfo ROUTINE_INFO_TVF =
@@ -146,6 +149,7 @@ public void testBuilder() {
146149
.setImportedLibraries(IMPORTED_LIBRARIES)
147150
.setBody(BODY)
148151
.setRemoteFunctionOptions(REMOTE_FUNCTION_OPTIONS)
152+
.setDataGovernanceType(DATA_GOVERNANCE_TYPE)
149153
.build();
150154
assertEquals(ETAG, builtRoutine.getEtag());
151155
assertEquals(DETERMINISM_LEVEL, builtRoutine.getDeterminismLevel());
@@ -247,5 +251,6 @@ public void compareRoutineInfo(RoutineInfo expected, RoutineInfo value) {
247251
assertEquals(expected.getBody(), value.getBody());
248252
assertEquals(expected.hashCode(), value.hashCode());
249253
assertEquals(expected.getRemoteFunctionOptions(), value.getRemoteFunctionOptions());
254+
assertEquals(expected.getDataGovernanceType(), value.getDataGovernanceType());
250255
}
251256
}

google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2684,6 +2684,33 @@ public void testRoutineAPICreationTVF() {
26842684
assertEquals(routine.getReturnTableType(), returnTableType);
26852685
}
26862686

2687+
@Test
2688+
public void testRoutineDataGovernanceType() {
2689+
String routineName = RemoteBigQueryHelper.generateRoutineName();
2690+
RoutineId routineId = RoutineId.of(ROUTINE_DATASET, routineName);
2691+
RoutineInfo routineInfo =
2692+
RoutineInfo.newBuilder(routineId)
2693+
.setLanguage("SQL")
2694+
.setRoutineType("SCALAR_FUNCTION")
2695+
.setBody("x")
2696+
.setArguments(
2697+
ImmutableList.of(
2698+
RoutineArgument.newBuilder()
2699+
.setName("x")
2700+
.setDataType(StandardSQLDataType.newBuilder("INT64").build())
2701+
.build()))
2702+
.setReturnType(StandardSQLDataType.newBuilder("INT64").build())
2703+
.setDataGovernanceType("DATA_MASKING")
2704+
.build();
2705+
2706+
Routine routine = bigquery.create(routineInfo);
2707+
assertNotNull(routine);
2708+
assertEquals(routine.getLanguage(), "SQL");
2709+
assertEquals(routine.getRoutineType(), "SCALAR_FUNCTION");
2710+
assertEquals(routine.getReturnType(), StandardSQLDataType.newBuilder("INT64").build());
2711+
assertEquals(routine.getDataGovernanceType(), "DATA_MASKING");
2712+
}
2713+
26872714
@Test
26882715
public void testAuthorizeRoutine() {
26892716
String routineName = RemoteBigQueryHelper.generateRoutineName();

0 commit comments

Comments
 (0)