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

                    Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                    SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                    은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현