I have the below pyspark dataframe.
Column_1 Column_2 Column_3 Column_4
1 A U1 12345
1 A A1 549BZ4G
Expected output:
Group by on column 1 and column 2. Collect set column 3 and 4 while preserving the order in input dataframe. It should be in the same order as input. There is no dependency in ordering between column 3 and 4. Both has to retain input dataframe ordering
Column_1 Column_2 Column_3 Column_4
1 A U1,A1 12345,549BZ4G
What I tried so far:
I first tried using window method. Where I partitioned by column 1 and 2 and order by column 1 and 2. I then grouped by column 1 and 2 and did a collect set on column 3 and 4.
I didn't get the expected output. My result was as below.
Column_1 Column_2 Column_3 Column_4
1 A U1,A1 549BZ4G,12345
I also tried using monotonically increasing id to create an index and then order by the index and then did a group by and collect set to get the output. But still no luck.
Is it due to alphanumeric and numeric values ? How to retain the order of column 3 and column 4 as it is there in input with no change of ordering.