Search in sources :

Example 1 with WriteToText

use of com.google.cloud.dataflow.examples.complete.game.utils.WriteToText in project DataflowJavaSDK-examples by GoogleCloudPlatform.

the class HourlyTeamScore method configureOutput.

/**
   * Create a map of information that describes how to write pipeline output to text. This map
   * is passed to the {@link WriteToText} constructor to write team score sums and
   * includes information about window start time.
   */
protected static Map<String, WriteToText.FieldFn<KV<String, Integer>>> configureOutput() {
    Map<String, WriteToText.FieldFn<KV<String, Integer>>> config = new HashMap<String, WriteToText.FieldFn<KV<String, Integer>>>();
    config.put("team", (c, w) -> c.element().getKey());
    config.put("total_score", (c, w) -> c.element().getValue());
    config.put("window_start", (c, w) -> {
        IntervalWindow window = (IntervalWindow) w;
        return fmt.print(window.start());
    });
    return config;
}
Also used : WriteToText(com.google.cloud.dataflow.examples.complete.game.utils.WriteToText) HashMap(java.util.HashMap) KV(org.apache.beam.sdk.values.KV) IntervalWindow(org.apache.beam.sdk.transforms.windowing.IntervalWindow)

Aggregations

WriteToText (com.google.cloud.dataflow.examples.complete.game.utils.WriteToText)1 HashMap (java.util.HashMap)1 IntervalWindow (org.apache.beam.sdk.transforms.windowing.IntervalWindow)1 KV (org.apache.beam.sdk.values.KV)1