What is Mapreduce equivalent to top() function in Spark?












0















I am trying to find the equivalent solution to top() and take() functions in spark, for Mapreduce implementation. I want to extract the top k values, without saving the whole key, value pairs.










share|improve this question





























    0















    I am trying to find the equivalent solution to top() and take() functions in spark, for Mapreduce implementation. I want to extract the top k values, without saving the whole key, value pairs.










    share|improve this question



























      0












      0








      0








      I am trying to find the equivalent solution to top() and take() functions in spark, for Mapreduce implementation. I want to extract the top k values, without saving the whole key, value pairs.










      share|improve this question
















      I am trying to find the equivalent solution to top() and take() functions in spark, for Mapreduce implementation. I want to extract the top k values, without saving the whole key, value pairs.







      apache-spark mapreduce






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 21 '18 at 6:47









      Ram Ghadiyaram

      16.4k64477




      16.4k64477










      asked Nov 21 '18 at 4:32









      Sadaf TafazoliSadaf Tafazoli

      1




      1
























          1 Answer
          1






          active

          oldest

          votes


















          0














          There is not a direct equivalent. If you need to do something similar without having Spark, I generally use Pig



          It requires at least two map reduce phases. One to process the data, then another to collect the data you actually want



          In the mapper, you set null writable (or some, single valued key), then emit all values, forcing them to a single reducer.



          In the reducer, you collect all values you want to sort or emit into a limited size collection. I recommend a TreeMap or Binary Heap, because they auto-sort. Then, you loop over the size of that collection for K values






          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%2f53405293%2fwhat-is-mapreduce-equivalent-to-top-function-in-spark%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









            0














            There is not a direct equivalent. If you need to do something similar without having Spark, I generally use Pig



            It requires at least two map reduce phases. One to process the data, then another to collect the data you actually want



            In the mapper, you set null writable (or some, single valued key), then emit all values, forcing them to a single reducer.



            In the reducer, you collect all values you want to sort or emit into a limited size collection. I recommend a TreeMap or Binary Heap, because they auto-sort. Then, you loop over the size of that collection for K values






            share|improve this answer




























              0














              There is not a direct equivalent. If you need to do something similar without having Spark, I generally use Pig



              It requires at least two map reduce phases. One to process the data, then another to collect the data you actually want



              In the mapper, you set null writable (or some, single valued key), then emit all values, forcing them to a single reducer.



              In the reducer, you collect all values you want to sort or emit into a limited size collection. I recommend a TreeMap or Binary Heap, because they auto-sort. Then, you loop over the size of that collection for K values






              share|improve this answer


























                0












                0








                0







                There is not a direct equivalent. If you need to do something similar without having Spark, I generally use Pig



                It requires at least two map reduce phases. One to process the data, then another to collect the data you actually want



                In the mapper, you set null writable (or some, single valued key), then emit all values, forcing them to a single reducer.



                In the reducer, you collect all values you want to sort or emit into a limited size collection. I recommend a TreeMap or Binary Heap, because they auto-sort. Then, you loop over the size of that collection for K values






                share|improve this answer













                There is not a direct equivalent. If you need to do something similar without having Spark, I generally use Pig



                It requires at least two map reduce phases. One to process the data, then another to collect the data you actually want



                In the mapper, you set null writable (or some, single valued key), then emit all values, forcing them to a single reducer.



                In the reducer, you collect all values you want to sort or emit into a limited size collection. I recommend a TreeMap or Binary Heap, because they auto-sort. Then, you loop over the size of that collection for K values







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 21 '18 at 4:36









                cricket_007cricket_007

                80.8k1142110




                80.8k1142110






























                    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%2f53405293%2fwhat-is-mapreduce-equivalent-to-top-function-in-spark%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

                    Paul Cézanne

                    UIScrollView CustomStickyHeader Resize height generates problems when scroll is too fast

                    Angular material date-picker (MatDatepicker) auto completes the date on focus out