Support Questions
Find answers, ask questions, and share your expertise

it does not stop at the breakpoint line within an anonymous function

it does not stop at the breakpoint line within an anonymous function

New Contributor

Hello ALL,

I am new to spark. I use IDEA ver 14.0.3 to debug spark recently.It is strange to me that any breakpoint set within an anonymous function,such as breakpoint-1 in the below code snippet, is invalid(a red X appears on the left of the line, mouse hovering message showing that "no executable code found at line xx in class apache.spark.example.sparkpi$"). The breakpoint-1 will be skipped., it stop at breakpoint-2 directly. However, the ultimate result PI value is correct.

I am running a "local" run/debug configuration

package org.apache.spark.examples
import scala.math.random
import org.apache.spark._
import scala.util.logging.Logged

/** Computes an approximation to pi */
object SparkPi{
  def main(args: Array[String]) {

    val conf = new SparkConf().setAppName("Spark Pi").setMaster("local")
    val spark = new SparkContext(conf)
    val slices = if (args.length > 0) args(0).toInt else 2
    val n = math.min(100000L * slices, Int.MaxValue).toInt // avoid overflow
    val count = spark.parallelize(1 until n, slices).map { i =>
        val x = random * 2 - 1  (breakpoint-1)
        val y = random * 2 - 1
        if (x*x + y*y < 1) 1 else 0
      }.reduce(_ + _)
    println("Pi is roughly " + 4.0 * count / (n - 1)) (breakpoint-2)
    spark.stop()
  }
}
Don't have an account?