@@ -83,7 +83,7 @@ private static void numericalStatsAnalysis(
83
83
String subscriptionId )
84
84
throws Exception {
85
85
86
- // instantiate a client
86
+ // Instantiates a client
87
87
try (DlpServiceClient dlpServiceClient = DlpServiceClient .create ()) {
88
88
BigQueryTable bigQueryTable =
89
89
BigQueryTable .newBuilder ()
@@ -104,7 +104,7 @@ private static void numericalStatsAnalysis(
104
104
105
105
PublishToPubSub publishToPubSub = PublishToPubSub .newBuilder ().setTopic (topicName ).build ();
106
106
107
- // create action to publish job status notifications over Google Cloud Pub/Sub
107
+ // Create action to publish job status notifications over Google Cloud Pub/Sub
108
108
Action action = Action .newBuilder ().setPubSub (publishToPubSub ).build ();
109
109
110
110
RiskAnalysisJobConfig riskAnalysisJobConfig =
@@ -125,7 +125,7 @@ private static void numericalStatsAnalysis(
125
125
126
126
final SettableApiFuture <Boolean > done = SettableApiFuture .create ();
127
127
128
- // setup a Pub/Sub subscriber to listen on the job completion status
128
+ // Set up a Pub/Sub subscriber to listen on the job completion status
129
129
Subscriber subscriber =
130
130
Subscriber .newBuilder (
131
131
ProjectSubscriptionName .newBuilder ()
@@ -143,15 +143,16 @@ private static void numericalStatsAnalysis(
143
143
.build ();
144
144
subscriber .startAsync ();
145
145
146
- // wait for job completion
146
+ // Wait for job completion semi-synchronously
147
+ // For long jobs, consider using a truly asynchronous execution model such as Cloud Functions
147
148
try {
148
149
done .get (1 , TimeUnit .MINUTES );
149
- Thread .sleep (500 );
150
+ Thread .sleep (500 ); // Wait for the job to become available
150
151
} catch (TimeoutException e ) {
151
152
System .out .println ("Unable to verify job completion." );
152
153
}
153
154
154
- // retrieve completed job status
155
+ // Retrieve completed job status
155
156
DlpJob completedJob =
156
157
dlpServiceClient .getDlpJob (GetDlpJobRequest .newBuilder ().setName (dlpJobName ).build ());
157
158
@@ -198,7 +199,7 @@ private static void categoricalStatsAnalysis(
198
199
String topicId ,
199
200
String subscriptionId ){
200
201
201
- // instantiate a client
202
+ // Instantiates a client
202
203
try (DlpServiceClient dlpServiceClient = DlpServiceClient .create ()) {
203
204
204
205
FieldId fieldId = FieldId .newBuilder ().setName (columnName ).build ();
@@ -222,7 +223,7 @@ private static void categoricalStatsAnalysis(
222
223
.setTopic (topicName .toString ())
223
224
.build ();
224
225
225
- // create action to publish job status notifications over Google Cloud Pub/Sub
226
+ // Create action to publish job status notifications over Google Cloud Pub/Sub
226
227
Action action = Action .newBuilder ().setPubSub (publishToPubSub ).build ();
227
228
228
229
RiskAnalysisJobConfig riskAnalysisJobConfig =
@@ -243,7 +244,7 @@ private static void categoricalStatsAnalysis(
243
244
244
245
final SettableApiFuture <Boolean > done = SettableApiFuture .create ();
245
246
246
- // setup a Pub/Sub subscriber to listen on the job completion status
247
+ // Set up a Pub/Sub subscriber to listen on the job completion status
247
248
Subscriber subscriber =
248
249
Subscriber .newBuilder (
249
250
ProjectSubscriptionName .newBuilder ()
@@ -261,15 +262,16 @@ private static void categoricalStatsAnalysis(
261
262
.build ();
262
263
subscriber .startAsync ();
263
264
264
- // wait for job completion
265
+ // Wait for job completion semi-synchronously
266
+ // For long jobs, consider using a truly asynchronous execution model such as Cloud Functions
265
267
try {
266
268
done .get (1 , TimeUnit .MINUTES );
267
- Thread .sleep (500 );
269
+ Thread .sleep (500 ); // Wait for the job to become available
268
270
} catch (TimeoutException e ) {
269
271
System .out .println ("Unable to verify job completion." );
270
272
}
271
273
272
- // retrieve completed job status
274
+ // Retrieve completed job status
273
275
DlpJob completedJob =
274
276
dlpServiceClient .getDlpJob (GetDlpJobRequest .newBuilder ().setName (dlpJobName ).build ());
275
277
@@ -316,7 +318,7 @@ private static void calculateKAnonymity(
316
318
String topicId ,
317
319
String subscriptionId )
318
320
throws Exception {
319
- // instantiate a client
321
+ // Instantiates a client
320
322
try (DlpServiceClient dlpServiceClient = DlpServiceClient .create ()) {
321
323
322
324
List <FieldId > quasiIdFields =
@@ -342,7 +344,7 @@ private static void calculateKAnonymity(
342
344
343
345
PublishToPubSub publishToPubSub = PublishToPubSub .newBuilder ().setTopic (topicName ).build ();
344
346
345
- // create action to publish job status notifications over Google Cloud Pub/Sub
347
+ // Create action to publish job status notifications over Google Cloud Pub/Sub
346
348
Action action = Action .newBuilder ().setPubSub (publishToPubSub ).build ();
347
349
348
350
RiskAnalysisJobConfig riskAnalysisJobConfig =
@@ -363,7 +365,7 @@ private static void calculateKAnonymity(
363
365
364
366
final SettableApiFuture <Boolean > done = SettableApiFuture .create ();
365
367
366
- // setup a Pub/Sub subscriber to listen on the job completion status
368
+ // Set up a Pub/Sub subscriber to listen on the job completion status
367
369
Subscriber subscriber =
368
370
Subscriber .newBuilder (
369
371
ProjectSubscriptionName .newBuilder ()
@@ -381,15 +383,16 @@ private static void calculateKAnonymity(
381
383
.build ();
382
384
subscriber .startAsync ();
383
385
384
- // wait for job completion
386
+ // Wait for job completion semi-synchronously
387
+ // For long jobs, consider using a truly asynchronous execution model such as Cloud Functions
385
388
try {
386
389
done .get (1 , TimeUnit .MINUTES );
387
- Thread .sleep (500 );
390
+ Thread .sleep (500 ); // Wait for the job to become available
388
391
} catch (TimeoutException e ) {
389
392
System .out .println ("Unable to verify job completion." );
390
393
}
391
394
392
- // retrieve completed job status
395
+ // Retrieve completed job status
393
396
DlpJob completedJob =
394
397
dlpServiceClient .getDlpJob (GetDlpJobRequest .newBuilder ().setName (dlpJobName ).build ());
395
398
@@ -421,9 +424,8 @@ private static void calculateKAnonymity(
421
424
}
422
425
// [END dlp_k_anonymity]
423
426
427
+ // [START dlp_l_diversity]
424
428
/**
425
- * [START dlp_l_diversity]
426
- *
427
429
* Calculate l-diversity for an attribute relative to quasi-identifiers in a BigQuery table.
428
430
*
429
431
* @param projectId The Google Cloud Platform project ID to run the API call under.
@@ -445,7 +447,7 @@ private static void calculateLDiversity(
445
447
String subscriptionId )
446
448
throws Exception {
447
449
448
- // instantiate a client
450
+ // Instantiates a client
449
451
try (DlpServiceClient dlpServiceClient = DlpServiceClient .create ()) {
450
452
451
453
FieldId sensitiveAttributeField = FieldId .newBuilder ().setName (sensitiveAttribute ).build ();
@@ -476,7 +478,7 @@ private static void calculateLDiversity(
476
478
477
479
PublishToPubSub publishToPubSub = PublishToPubSub .newBuilder ().setTopic (topicName ).build ();
478
480
479
- // create action to publish job status notifications over Google Cloud Pub/Sub
481
+ // Create action to publish job status notifications over Google Cloud Pub/Sub
480
482
Action action = Action .newBuilder ().setPubSub (publishToPubSub ).build ();
481
483
482
484
RiskAnalysisJobConfig riskAnalysisJobConfig =
@@ -497,7 +499,7 @@ private static void calculateLDiversity(
497
499
498
500
final SettableApiFuture <Boolean > done = SettableApiFuture .create ();
499
501
500
- // setup a Pub/Sub subscriber to listen on the job completion status
502
+ // Set up a Pub/Sub subscriber to listen on the job completion status
501
503
Subscriber subscriber =
502
504
Subscriber .newBuilder (
503
505
ProjectSubscriptionName .newBuilder ()
@@ -515,10 +517,11 @@ private static void calculateLDiversity(
515
517
.build ();
516
518
subscriber .startAsync ();
517
519
518
- // wait for job completion
520
+ // Wait for job completion semi-synchronously
521
+ // For long jobs, consider using a truly asynchronous execution model such as Cloud Functions
519
522
try {
520
523
done .get (1 , TimeUnit .MINUTES );
521
- Thread .sleep (500 );
524
+ Thread .sleep (500 ); // Wait for the job to become available
522
525
} catch (TimeoutException e ) {
523
526
System .out .println ("Unable to verify job completion." );
524
527
}
@@ -554,8 +557,8 @@ private static void calculateLDiversity(
554
557
} catch (Exception e ) {
555
558
System .out .println ("Error in lDiversityAnalysis: " + e .getMessage ());
556
559
}
557
- // [END dlp_l_diversity]
558
560
}
561
+ // [END dlp_l_diversity]
559
562
560
563
/**
561
564
* Command line application to perform risk analysis using the Data Loss Prevention API. Supported
0 commit comments