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

[ad_1] 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) => … Read more

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

[ad_1] 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 [ad_2] 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

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