3535
3636
3737public class WordCount {
38- // [START word_count_options]
3938 public interface WordCountOptions extends PipelineOptions {
4039 // Optional argument with a default value.
4140 @ Description ("Google Cloud Storage file pattern glob of the file(s) to read from" )
@@ -64,9 +63,7 @@ public interface WordCountOptions extends PipelineOptions {
6463
6564 void setIsCaseSensitive (Boolean value );
6665 }
67- // [END word_count_options]
6866
69- // [START static_value_provider]
7067 static class FilterWithSubstring extends DoFn <String , String > {
7168 ValueProvider <String > substring ;
7269 Boolean isCaseSensitive ;
@@ -95,17 +92,14 @@ public void processElement(ProcessContext c) {
9592 }
9693 }
9794 }
98- // [END static_value_provider]
9995
100- // [START value_provider]
10196 public static void main (String [] args ) {
10297 WordCountOptions options = PipelineOptionsFactory .fromArgs (args )
10398 .withValidation ().as (WordCountOptions .class );
10499
105100 Pipeline pipeline = Pipeline .create (options );
106101 pipeline
107102 .apply ("Read lines" , TextIO .read ().from (options .getInputFile ()))
108- // [END value_provider]
109103 .apply ("Find words" , FlatMapElements .into (TypeDescriptors .strings ())
110104 .via ((String line ) -> Arrays .asList (line .split ("[^\\ p{L}]+" ))))
111105 .apply ("Filter empty words" , Filter .by ((String word ) -> !word .isEmpty ()))
@@ -114,12 +108,10 @@ public static void main(String[] args) {
114108 .apply ("Count words" , Count .perElement ())
115109 .apply ("Format results" , MapElements .into (TypeDescriptors .strings ())
116110 .via ((KV <String , Long > wordCount ) -> wordCount .getKey () + ": " + wordCount .getValue ()))
117- // [START nested_value_provider]
118111 .apply ("Write results" , TextIO .write ().to (NestedValueProvider .of (
119112 options .getOutputBucket (),
120113 (String bucket ) -> String .format ("gs://%s/samples/dataflow/wordcount/outputs" , bucket )
121114 )));
122- // [END nested_value_provider]
123115 pipeline .run ();
124116 }
125117}
0 commit comments