Implement aggregateByKey() using functions, getting error


#1

Hi,
i followed Durga’s tutorial on getting daily revenue order per product using reducceByKey, it was working fine.And I wanted to implement same using aggregateBykey, it is throwing typemismatch errors. Please look at below error and help me out to resolve the issue:

ERROR:
:47: error: type mismatch;
** found : (Float, Float) => Double**
** required: (Double, Double) => Double**
** val dailyRevenue=ordersJoinMap.aggregateByKey(zeroval)(seqOp,comOp)**
** ^**
:47: error: type mismatch;
** found : (Float, Float) => Double**
** required: (Double, Double) => Double**
** val dailyRevenue=ordersJoinMap.aggregateByKey(zeroval)(seqOp,comOp)**

Below is the input data(ordersJoinMap) :
((2014-05-23 00:00:00.0,365),119.98)
((2014-05-23 00:00:00.0,730),400.0)
((2014-05-23 00:00:00.0,1004),399.98)
((2014-05-23 00:00:00.0,627),199.95)
((2014-05-23 00:00:00.0,191),199.98)

below is the code that i have written:
val zeroval=(0.0);
def seqOp(accumulator: Float,element: Float)= {
| (accumulator+element)
| }
def seqOp(accumulator1: Float,accumulator2: Float) = {
| (accumulator1 + accumulator2)
| }
val dailyRevenue=ordersJoinMap.aggregateByKey(zeroval)(seqOp,comOp)


#2

small correction on comOp function::

val zeroval=(0.0);
def seqOp(accumulator: Float,element: Float)= {
| (accumulator+element)
| }
def comOp(accumulator1: Float,accumulator2: Float) = {
| (accumulator1 + accumulator2)
| }
val dailyRevenue=ordersJoinMap.aggregateByKey(zeroval)(seqOp,comOp)