@cleaton Thanks for your advice, I agree with your point that avoid using too many classes and using object instead. logInfo() is a member function of trait org.apache.spark.Logging. It is weird that I read source code of apache spark 1.6, I found some codes such as JdbcUtils (org.apache.spark.sql.execution.datasources.jdbc) also use member functions of Logging in foreachPartition and based on my previous experience, in other function(map, reduceByKey), logInfo works well, exception only occurs in foreachPartition. Besides, how to log for debug while developing spark application, do you have any advice?
Jesper Lundgren
@cleaton
I mean is it a class or an object that you extend with the spark.Logging trait?
JdbcUtils is an object.
If you only change foreachPartition to foreach it works?
JamJam
@jaminglam
yes, does you mean that If I have a class which include codes doing foreachPartition. Spark will serialize the whole class code?
Jesper Lundgren
@cleaton
Yes
the function will be a member of the class instance, and thus it will only exist on the driver at first
when you try to call that function inside foreach/foreachpartition the driver will need to send the whole class instance to the executor machine
if it's an object it is initalized separately
for each jvm
and thus spark only needs to give the method reference
(and any parameter you give on the driver side)
You should be able to see more information in the log from the spark driver
this error happens before it reaches any of the executor nodes.