In this case, if you already know that the size of your result is quite small 
and fits into memory than you need to have to materialise your results on one 
worker in the same JVM. You can do that with assigning the same key for all 
result elements and then apply GroupByKey transform over this 
PCollection<KV<K,String>>. Alternatively, you can use GroupIntoBatches (see 
example in Javadoc [1]) transform for better control on this.

[1] 
https://github.com/apache/beam/blob/master/sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/GroupIntoBatches.java
 
<https://github.com/apache/beam/blob/master/sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/GroupIntoBatches.java>

—
Alexey

> On 21 Apr 2022, at 14:31, Kayal P <kayalpaarthi...@gmail.com> wrote:
> 
> Hi Alexey,
> 
> I have a small result of Pcollection<String> from SQLTransform. I have to 
> pass this result to a mailing class that sends mail, with body as values from 
> Pcollection<String>, In a tabular format. The number of elements in 
> Pcollection<String> will be less than 10 always.
> 
> Regards,
> Kayal
> 
>> 
>> On Apr 21, 2022, at 5:13 AM, Alexey Romanenko <aromanenko....@gmail.com> 
>> wrote:
>> 
>> Hi Kayal,
>> 
>> In general, PCollection is infinite collection of elements. So, there is no 
>> only one simple way to do what you are asking and the solution will depend 
>> on a case where it’s needed.
>> 
>> Could you give an example why and where in your pipeline you do need this? 
>> 
>> —
>> Alexey
>> 
>>> On 21 Apr 2022, at 06:28, Kayal P <kayalpaarthi...@gmail.com 
>>> <mailto:kayalpaarthi...@gmail.com>> wrote:
>>> 
>>> Hi All,
>>> 
>>> I am trying to convert Pcollection<String> to List<String> using Java sdk. 
>>> Seems there is combiners.ToList transform available in python sdk. Is there 
>>> any similar option available in Java sdk? If not can someone guide me with 
>>> right way of doing this? The Pcollection<String> is very small collection 
>>> less than 10 items. Thanks in advance.
>>> 
>>> Regards,
>>> Kayal 
>> 

Reply via email to