Skip to content
This repository was archived by the owner on Oct 16, 2025. It is now read-only.

Commit cfb29c4

Browse files
authored
Merge pull request #41 from GoogleCloudPlatform/teleport-test
Tagging code snippet for solution guide
2 parents d3909f6 + e46d44c commit cfb29c4

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

src/main/java/com/google/swarm/tokenization/DLPTextToBigQueryStreaming.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,12 +191,14 @@ public static PipelineResult run(TokenizePipelineOptions options) {
191191
* - Setup a window for 30 secs to capture the list of files emited.
192192
* - Group by file name as key and ReadableFile as a value.
193193
*/
194+
// [START loadSnippet_1]
194195
.apply(
195196
"Poll Input Files",
196197
FileIO.match()
197198
.filepattern(options.getInputFilePattern())
198199
.continuously(DEFAULT_POLL_INTERVAL, Watch.Growth.never()))
199200
.apply("Find Pattern Match", FileIO.readMatches().withCompression(Compression.AUTO))
201+
// [END loadSnippet_1]
200202
.apply("Add File Name as Key", WithKeys.of(file -> getFileName(file)))
201203
.setCoder(KvCoder.of(StringUtf8Coder.of(), ReadableFileCoder.of()))
202204
.apply(
@@ -212,6 +214,7 @@ public static PipelineResult run(TokenizePipelineOptions options) {
212214
* Side input for the window to capture list of headers for each file emited so that it can be
213215
* used in the next transform.
214216
*/
217+
// [START loadSnippet_2]
215218
final PCollectionView<List<KV<String, List<String>>>> headerMap =
216219
csvFiles
217220

@@ -239,7 +242,7 @@ public void processElement(ProcessContext c) {
239242
}
240243
}))
241244
.apply("View As List", View.asList());
242-
245+
// [END loadSnippet_2]
243246
PCollection<KV<String, TableRow>> bqDataMap =
244247
csvFiles
245248

@@ -352,7 +355,7 @@ public interface TokenizePipelineOptions extends DataflowPipelineOptions {
352355

353356
void setDlpProjectId(ValueProvider<String> value);
354357
}
355-
358+
// [START loadSnippet_3]
356359
/**
357360
* The {@link CSVReader} class uses experimental Split DoFn to split each csv file contents in
358361
* chunks and process it in non-monolithic fashion. For example: if a CSV file has 100 rows and
@@ -440,6 +443,7 @@ public void processElement(ProcessContext c, RestrictionTracker<OffsetRange, Lon
440443
*
441444
* @throws IOException
442445
*/
446+
//
443447
@GetInitialRestriction
444448
public OffsetRange getInitialRestriction(KV<String, ReadableFile> csvFile) throws IOException {
445449

@@ -486,6 +490,7 @@ public void splitRestriction(
486490
public OffsetRangeTracker newTracker(OffsetRange range) {
487491
return new OffsetRangeTracker(new OffsetRange(range.getFrom(), range.getTo()));
488492
}
493+
// [END loadSnippet_3]
489494

490495
private Table.Row convertCsvRowToTableRow(CSVRecord csvRow) {
491496
/** convert from CSV row to DLP Table Row */
@@ -643,6 +648,7 @@ private static TableRow createBqRow(Table.Row tokenizedValue, String[] headers)
643648
}
644649
}
645650

651+
// [START loadSnippet_4]
646652
/**
647653
* The {@link BQDestination} class creates BigQuery table destination and table schema based on
648654
* the CSV file processed in earlier transformations. Table id is same as filename Table schema is
@@ -693,7 +699,7 @@ public TableSchema getSchema(KV<String, TableRow> destination) {
693699
return schema;
694700
}
695701
}
696-
702+
// [END loadSnippet_4]
697703
private static String getFileName(ReadableFile file) {
698704
String csvFileName = file.getMetadata().resourceId().getFilename().toString();
699705
/** taking out .csv extension from file name e.g fileName.csv->fileName */

0 commit comments

Comments
 (0)