spark-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "octavian.ganea" <>
Subject NullPointerException when using Accumulators on cluster
Date Sat, 25 Oct 2014 18:38:21 GMT

I have a simple accumulator that needs to be passed to a foo() function
inside a map job:

val myCounter = sc.accumulator(0)
val myRDD = sc.textFile(inputpath) // :spark.RDD[String]
myRDD.flatMap(line => foo(line))

def foo(line: String) = {
   myCounter += 1  // line throwing NullPointerException
   // compute something on the input

If I pass myCounter as a parameter to foo(), then I get : noSerializable
exception for SparkContext. If I keep myCounter global (in a scala singleton
object), I get nullpointer exception. 

What is the proper way send an accumulator distributed to all nodes when
running on a cluster?


View this message in context:
Sent from the Apache Spark User List mailing list archive at

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message