You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@beam.apache.org by Jesse Anderson <je...@smokinghand.com> on 2016/05/16 16:05:12 UTC

TypeDescriptors Example Code

Does anyone have any thoughts or concerns with me changing the example code
to use the new TypeDescriptors class from the inline creation of a
TypeDescriptor?

For example, MinimalWordCountJava8 would change from:


p.apply(TextIO.Read.from("gs://dataflow-samples/shakespeare/*"))

    .apply(FlatMapElements.via((String word) ->
Arrays.asList(word.split("[^a-zA-Z']+")))

        .withOutputType(new TypeDescriptor<String>() {}))

to:

p.apply(TextIO.Read.from("gs://dataflow-samples/shakespeare/*"))

    .apply(FlatMapElements.via((String word) ->
Arrays.asList(word.split("[^a-zA-Z']+")))
        .withOutputType(strings()))

I'd use a static import to decrease the code footprint.

Thanks,

Jesse

Re: TypeDescriptors Example Code

Posted by Davor Bonaci <da...@google.com.INVALID>.
Sure -- go ahead. (I'd probably avoid static import, however. One word
more, but more readable.)

On Mon, May 16, 2016 at 9:05 AM, Jesse Anderson <je...@smokinghand.com>
wrote:

> Does anyone have any thoughts or concerns with me changing the example code
> to use the new TypeDescriptors class from the inline creation of a
> TypeDescriptor?
>
> For example, MinimalWordCountJava8 would change from:
>
>
> p.apply(TextIO.Read.from("gs://dataflow-samples/shakespeare/*"))
>
>     .apply(FlatMapElements.via((String word) ->
> Arrays.asList(word.split("[^a-zA-Z']+")))
>
>         .withOutputType(new TypeDescriptor<String>() {}))
>
> to:
>
> p.apply(TextIO.Read.from("gs://dataflow-samples/shakespeare/*"))
>
>     .apply(FlatMapElements.via((String word) ->
> Arrays.asList(word.split("[^a-zA-Z']+")))
>         .withOutputType(strings()))
>
> I'd use a static import to decrease the code footprint.
>
> Thanks,
>
> Jesse
>