0
votes

I have a Dataframe. I need to create one or more rows from each row in dataframe. I am hoping FlapMap could help me in solving the problem. One or More rows would be created by applying logic on 2 columns of the row.

Example Input dataframe

+--------------------+  
|  Name|Float1|Float2|
+--------------------+  
|  Java|   2.3|   0.2|
|Python|   3.2|   0.5|
| Scala|   4.3|   0.8|
+--------------------+ 

Logic:

If *|Float1 + Float2| = |Float1)|* Then one row is created.
eg : 2.3 +0.2 = |2.5| = 2
|2.3| = 2
if *|Float1 +Float2| > |Float1|* Then two rows are created
eg: 4.3+0.8 = |5.1| = 5
|4.3| = 4

Can we solve this problem using flatmap or any other transformation in spark?

1
what will be the value of new Rows ? can you add the required output? - koiralo

1 Answers

0
votes

Create a UDF that takes in two columns and returns back a list. Once you have a list, then use the explode function on the column which will give you what you desire