Uploaded image for project: 'Spark'
  1. Spark
  2. SPARK-4170

Closure problems when running Scala app that "extends App"

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 1.1.0
    • Fix Version/s: None
    • Component/s: Spark Core
    • Labels:
      None

      Description

      Michael Albert noted this problem on the mailing list (http://apache-spark-user-list.1001560.n3.nabble.com/BUG-when-running-as-quot-extends-App-quot-closures-don-t-capture-variables-td17675.html):

      object DemoBug extends App {
          val conf = new SparkConf()
          val sc = new SparkContext(conf)
      
          val rdd = sc.parallelize(List("A","B","C","D"))
          val str1 = "A"
      
          val rslt1 = rdd.filter(x => { x != "A" }).count
          val rslt2 = rdd.filter(x => { str1 != null && x != "A" }).count
          
          println("DemoBug: rslt1 = " + rslt1 + " rslt2 = " + rslt2)
      }
      

      This produces the output:

      DemoBug: rslt1 = 3 rslt2 = 0
      

      If instead there is a proper "main()", it works as expected.

      I also this week noticed that in a program which "extends App", some values were inexplicably null in a closure. When changing to use main(), it was fine.

      I assume there is a problem with variables not being added to the closure when main() doesn't appear in the standard way.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                srowen Sean Owen
                Reporter:
                srowen Sean Owen
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: