Is there a way to directly take a PCollection<KV> and make it a
PCollection<String>? I need to make the PCollection a PCollection<String>
before writing it out with TextIO.Write.

I tried using:
withCoder(KvCoder.of(StringDelegateCoder.of(String.class),
StringDelegateCoder.of(Long.class))

but that causes binary data to be written out by the KV coder.

The only way appears to be a manual transform with:
PCollection<String> stringCounts = counts.apply(MapElements
    .via((KV<String, Long> count) ->
    count.getKey() + ":" + count.getValue())
    .withOutputType(TypeDescriptors.strings()));

If this is missing, that manual step should be baked into the API. That
should be something either in StringDelegateCoder or a new String
transform. The new StringDelegateCoder method would take in any KV (or list
types) and put a specific String delimiter. The new transform would take in
any type in a PCollection<T> and makes it a PCollection<String> using a
specific String delimiter.

Thanks,

Jesse

Reply via email to