[Solved] How to get answer from this Spark Scala program for Input : s= ‘aaabbbccaabb’ Output : 3a3b2c2a2b

You can foldLeft over the input string, with a state of List[(Char, Int)]. Note that if you use Map[Char, Int], all occurrences of each character would be added up, weather they’re beside each other or not. s.foldLeft(List.empty[(Char, Int)]) { case (Nil, newChar) => (newChar, 1) :: Nil case (list@(headChar, headCount) :: tail, newChar) => if … Read more

[Solved] python : reduce by key with if condition statement?

IIUC, you need to change the key before the reduce, and then map your values back in the desired format. You should be able to do the following: new_rdd = rdd.map(lambda row: ((row[0], row[1][0]), row[1][1]))\ .reduceByKey(sum). .map(lambda row: (row[0][0], (row[0][1], row[1]))) 0 solved python : reduce by key with if condition statement?

[Solved] How to perform self join with same row of previous group(month) to bring in additional columns with different expressions in Pyspark

How to perform self join with same row of previous group(month) to bring in additional columns with different expressions in Pyspark solved How to perform self join with same row of previous group(month) to bring in additional columns with different expressions in Pyspark