aggregateByKey issue in pyspark


#1

hi,
i m trying to get the solution for below problem statement.
PS: get revenue and minimum subtotal of items for each order id

for eg:
(2, 199.99)
(2, 250.0)
(2, 129.99)

final output I am expecting : (2,(579.98,129.99))

ERROR i m getting:

orderItemsAggrByKey = orderItemsMap.aggregateByKey((0.0,0.0),lambda x,y:(x[0] + y, x[1] if(x[1] < x)else x)),lambda x,y:(x[0] + y[0], x[1] if(x[1] < y[1]) else y[1]))
File “”, line 1
orderItemsAggrByKey = orderItemsMap.aggregateByKey((0.0,0.0),lambda x,y:(x[0] + y, x[1] if(x[1] < x)else x)),lambda x,y:(x[0] + y[0], x[1] if(x[1] < y[1]) else y[1]))
^
SyntaxError: invalid syntax

please help me to find where I am going wrong with the syntax?

full code for reference:
orderItems = sc.textFile("/public/retail_db/order_items")
orderItemsMap = orderItems.map(lambda oi:(int(oi.split(",")[1]),float(oi.split(",")[4])))
orderItemsAggrByKey = orderItemsMap.aggregateByKey((0.0,0.0),lambda x,y:(x[0] + y, x[1] if(x[1] < x)else x)),lambda x,y:(x[0] + y[0], x[1] if(x[1] < y[1]) else y[1]))


#2

@Mudassir Try this below code.

orderItemsAggrByKey = orderItemsMap.aggregateByKey((0.0,0.0),lambda x,y:(x[0] + y, x[1] if(x[1] < x)else x),lambda x,y:(x[0] + y[0], x[1] if(x[1] < y[1]) else y[1]))