-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode_01_BeamCreate_String.java
More file actions
40 lines (34 loc) · 1.39 KB
/
code_01_BeamCreate_String.java
File metadata and controls
40 lines (34 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package com.example;
import org.apache.beam.sdk.Pipeline;
import org.apache.beam.sdk.transforms.Create;
import org.apache.beam.sdk.transforms.MapElements;
import org.apache.beam.sdk.values.PCollection;
import org.apache.beam.sdk.values.TypeDescriptor;
public class code_01_BeamCreate_String {
public static void main(String[] args) {
// Create a pipeline
Pipeline p = Pipeline.create();
// Apply a transform to create a PCollection
PCollection<String> words = p.apply("Creating Strings", Create.of("Hello", "World"));
// Apply a transform to convert words to uppercase
PCollection<String> uppercasedWords = words.apply("Applying Transformations",
MapElements
.into(TypeDescriptor.of(String.class))
.via((String word) -> {
assert word != null;
return word.toUpperCase();
})
);
// Apply a transform to print each word
uppercasedWords.apply("Printing Strings",
MapElements
.into(TypeDescriptor.of(Void.class))
.via((String word) -> {
System.out.println(word);
return null;
})
);
// Run the pipeline
p.run().waitUntilFinish();
}
}