I have written this function to be able to create 5 dictionaries from a single one and to pass it into Mapin apache beam to produce another Pcollection.
Input : col1,Col2, Col3, Market_0_30, DealerMake_0_30, Market_31_60, DealerMake_31_60, Market_61_90, DealerMake_61_90, Market_91_120, DealerMake_91_120, Market_121, DealerMake_121,
Output: line 1: col1, col2, Col3, Market, DealerMake, Age: 0_30
line 2: col1, col2, Col3, Market, DealerMake, Age: 31_60
line 3: col1, col2, Col3, Market, DealerMake, Age: 31_60
def _expand(element: Dict) -> List:
common_columns = {}
for key in element.keys():
if key not in markets and key not in dealermakers:
common_columns[key] = element[key]
lines = {}
for i, (market, dealermaker) in enumerate(zip(markets, dealermakers)):
line = {}
line = common_columns.copy()
line[market] = element[market]
line[dealermaker] = element[dealermaker]
return lines
output = sources_data["group_stocks_view"] | "EXPAND" >> beam.Map(_expand) | "PRINT" >> beam.Map(print)
But I always get an empty Pcollection at the end.
Any help please ?
Regards,