Spark/Scala update the value of a variable in another map?Apache spark: map csv file to key: value formatHow to define a global scala variable in Spark which will be shared by all workers?Spark performance for Scala vs PythonNoSuchMethodError on a Map (Spark Scala class)How to sort an RDD of tuples with 5 elements in Spark Scala?word count(frequency) spark rdd scalaspark map partitions to fill nan valuesSpark combineByKey on values that contains tuplesHow to update a global variable inside RDD map operationspark: value histogram is not a member of org.apache.spark.rdd.RDD[Option[Any]]

Are spot colors limited and why CMYK mix is not treated same as spot color mix?

In Endgame, wouldn't Stark have remembered Hulk busting out of the stairwell?

Do application leftovers have any impact on performance?

Convert shapefille to KML

Why does the weaker C–H bond have a higher wavenumber than the C=O bond?

Should I use the words "pyromancy" and "necromancy" even if they don't mean what people think they do?

Count the number of triangles

Why does Sauron not permit his followers to use his name?

Is there a way to tell what frequency I need a PWM to be?

Printing a list as "a, b, c." using Python

What checks exist against overuse of presidential pardons in the USA?

Inspiration for failed idea?

Journal published a paper, ignoring my objections as a referee

Can two aircraft stay on the same runway at the same time?

How to differentiate between two people with the same name in a story?

How can I fix cracks between the bathtub and the wall surround?

Is it recommended to point out a professor's mistake during their lecture?

Why do presidential pardons exist in a country having a clear separation of powers?

What should be done with the carbon when using magic to get oxygen from carbon dioxide?

Notice period 60 days but I need to join in 45 days

Why is 3/4 a simple meter while 6/8 is a compound meter?

How do Barton (Hawkeye/Ronin) and Romanov (Black Widow) end up on the Benatar on Morag in 2014?

In what language did Túrin converse with Mím?

Are sweatpants frowned upon on flights?



Spark/Scala update the value of a variable in another map?


Apache spark: map csv file to key: value formatHow to define a global scala variable in Spark which will be shared by all workers?Spark performance for Scala vs PythonNoSuchMethodError on a Map (Spark Scala class)How to sort an RDD of tuples with 5 elements in Spark Scala?word count(frequency) spark rdd scalaspark map partitions to fill nan valuesSpark combineByKey on values that contains tuplesHow to update a global variable inside RDD map operationspark: value histogram is not a member of org.apache.spark.rdd.RDD[Option[Any]]






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















In Spark, I have a



closest: org.apache.spark.rdd.RDD[(Int, (breeze.linalg.Vector[Double], Int))] = MapPartitionsRDD[476] at map at command-1043253026161724:1


I want to calculate some total distance:



var tempDist=0.0
closest.foreach(x=> tempDist=tempDist+squaredDistance(x._2._1, kPoints(x._1)))


But this doesn't change tempDist's value at all. I suspect Spark doesn't do anything. So how can I calculate the distance?










share|improve this question






























    0















    In Spark, I have a



    closest: org.apache.spark.rdd.RDD[(Int, (breeze.linalg.Vector[Double], Int))] = MapPartitionsRDD[476] at map at command-1043253026161724:1


    I want to calculate some total distance:



    var tempDist=0.0
    closest.foreach(x=> tempDist=tempDist+squaredDistance(x._2._1, kPoints(x._1)))


    But this doesn't change tempDist's value at all. I suspect Spark doesn't do anything. So how can I calculate the distance?










    share|improve this question


























      0












      0








      0








      In Spark, I have a



      closest: org.apache.spark.rdd.RDD[(Int, (breeze.linalg.Vector[Double], Int))] = MapPartitionsRDD[476] at map at command-1043253026161724:1


      I want to calculate some total distance:



      var tempDist=0.0
      closest.foreach(x=> tempDist=tempDist+squaredDistance(x._2._1, kPoints(x._1)))


      But this doesn't change tempDist's value at all. I suspect Spark doesn't do anything. So how can I calculate the distance?










      share|improve this question














      In Spark, I have a



      closest: org.apache.spark.rdd.RDD[(Int, (breeze.linalg.Vector[Double], Int))] = MapPartitionsRDD[476] at map at command-1043253026161724:1


      I want to calculate some total distance:



      var tempDist=0.0
      closest.foreach(x=> tempDist=tempDist+squaredDistance(x._2._1, kPoints(x._1)))


      But this doesn't change tempDist's value at all. I suspect Spark doesn't do anything. So how can I calculate the distance?







      scala apache-spark rdd






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 27 at 22:05









      Jiapeng ZhangJiapeng Zhang

      2992 silver badges22 bronze badges




      2992 silver badges22 bronze badges

























          1 Answer
          1






          active

          oldest

          votes


















          2















          Don't do mutable vars. It's a bad idea in general, and doesn't work at all with spark, at least, not the way you are doing it, because it's a distributed system.
          Different partitions of the sequence are located on different computers, and are being processed independently in parallel and in different JVMs, each of which has its own copy of the var.



           val tempDist = closest
          .map x => squaredDistance(x._2._1, kPoints(x._1)
          .fold(0) _ + _





          share|improve this answer


























            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55387196%2fspark-scala-update-the-value-of-a-variable-in-another-map%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            2















            Don't do mutable vars. It's a bad idea in general, and doesn't work at all with spark, at least, not the way you are doing it, because it's a distributed system.
            Different partitions of the sequence are located on different computers, and are being processed independently in parallel and in different JVMs, each of which has its own copy of the var.



             val tempDist = closest
            .map x => squaredDistance(x._2._1, kPoints(x._1)
            .fold(0) _ + _





            share|improve this answer































              2















              Don't do mutable vars. It's a bad idea in general, and doesn't work at all with spark, at least, not the way you are doing it, because it's a distributed system.
              Different partitions of the sequence are located on different computers, and are being processed independently in parallel and in different JVMs, each of which has its own copy of the var.



               val tempDist = closest
              .map x => squaredDistance(x._2._1, kPoints(x._1)
              .fold(0) _ + _





              share|improve this answer





























                2














                2










                2









                Don't do mutable vars. It's a bad idea in general, and doesn't work at all with spark, at least, not the way you are doing it, because it's a distributed system.
                Different partitions of the sequence are located on different computers, and are being processed independently in parallel and in different JVMs, each of which has its own copy of the var.



                 val tempDist = closest
                .map x => squaredDistance(x._2._1, kPoints(x._1)
                .fold(0) _ + _





                share|improve this answer















                Don't do mutable vars. It's a bad idea in general, and doesn't work at all with spark, at least, not the way you are doing it, because it's a distributed system.
                Different partitions of the sequence are located on different computers, and are being processed independently in parallel and in different JVMs, each of which has its own copy of the var.



                 val tempDist = closest
                .map x => squaredDistance(x._2._1, kPoints(x._1)
                .fold(0) _ + _






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Mar 28 at 0:29

























                answered Mar 27 at 23:06









                DimaDima

                27.8k3 gold badges27 silver badges44 bronze badges




                27.8k3 gold badges27 silver badges44 bronze badges





















                    Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







                    Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid …


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55387196%2fspark-scala-update-the-value-of-a-variable-in-another-map%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    How to preserve electronics (computers, tablets and phones) for hundreds of years Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) The network's official Twitter account is up and running again. What content…How might modern humans leave a message for 50,000 years?How would an aquatic race develop computers?How do we make computers care for human life?Keeping supplies for 1000 yearsWhat will cell phones become in 100 years?What body armor protects against a laser?Could a society attain 1800s technology if limited to using copper and bronze?Electricity power (magic) and electronicsScavenging metal resources in post-apocalypse after 100 yearsWhy would precursors create devices that can survive and still work after hundreds of years?

                    155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해

                    해남서초등학교 학교 연혁 학교 동문 외부 링크 둘러보기 메뉴북위 34° 34′ 21″ 동경 126° 35′ 50″ / 북위 34.5726385° 동경 126.5972670°  / 34.5726385; 126.5972670해남서초등학교eh