[Solved] Find cartesian product of 2 lists with Apache Beam

mattwilsn Asks: Find cartesian product of 2 lists with Apache Beam
I have 2 PCollections:

Code:
PCollection<List<String>> ListA =
        pipeline.apply("getListA", ParDo.of(new getListA()))
PCollection<List<String>> ListB =
        pipeline.apply("getListB", ParDo.of(new getListB()))

ListA contains:

Code:
["1","2","3"]

ListB contains:

Code:
["A","B","C"]

How do I end up with a PCollection that contains:

Code:
[
 ["A","1"],["A","2"],["A","3"],
 ["B","1"],["B","2"],["B","3"],
 ["C","1"],["C","2"],["C","3"],
]

My search has pointed me to:

How to do a cartesian product of two PCollections in Dataflow?

But this is dealing with KV using coGroupby with 2 outputs. It’s possible that coGroupby can be used to create the cartesian product of 2 lists but I am not seeing it.

Ten-tools.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your response here to help other visitors like you. Thank you, Ten-tools.