久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

<legend id='z4iOR'><style id='z4iOR'><dir id='z4iOR'><q id='z4iOR'></q></dir></style></legend>

<tfoot id='z4iOR'></tfoot>
    <i id='z4iOR'><tr id='z4iOR'><dt id='z4iOR'><q id='z4iOR'><span id='z4iOR'><b id='z4iOR'><form id='z4iOR'><ins id='z4iOR'></ins><ul id='z4iOR'></ul><sub id='z4iOR'></sub></form><legend id='z4iOR'></legend><bdo id='z4iOR'><pre id='z4iOR'><center id='z4iOR'></center></pre></bdo></b><th id='z4iOR'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='z4iOR'><tfoot id='z4iOR'></tfoot><dl id='z4iOR'><fieldset id='z4iOR'></fieldset></dl></div>
  1. <small id='z4iOR'></small><noframes id='z4iOR'>

        <bdo id='z4iOR'></bdo><ul id='z4iOR'></ul>

      使用 Apache Spark 將鍵值對縮減為鍵列表對

      Reduce a key-value pair into a key-list pair with Apache Spark(使用 Apache Spark 將鍵值對縮減為鍵列表對)

          <tbody id='pZEpj'></tbody>
          <bdo id='pZEpj'></bdo><ul id='pZEpj'></ul>
        • <legend id='pZEpj'><style id='pZEpj'><dir id='pZEpj'><q id='pZEpj'></q></dir></style></legend>
          <i id='pZEpj'><tr id='pZEpj'><dt id='pZEpj'><q id='pZEpj'><span id='pZEpj'><b id='pZEpj'><form id='pZEpj'><ins id='pZEpj'></ins><ul id='pZEpj'></ul><sub id='pZEpj'></sub></form><legend id='pZEpj'></legend><bdo id='pZEpj'><pre id='pZEpj'><center id='pZEpj'></center></pre></bdo></b><th id='pZEpj'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='pZEpj'><tfoot id='pZEpj'></tfoot><dl id='pZEpj'><fieldset id='pZEpj'></fieldset></dl></div>
            • <small id='pZEpj'></small><noframes id='pZEpj'>

                <tfoot id='pZEpj'></tfoot>
              1. 本文介紹了使用 Apache Spark 將鍵值對縮減為鍵列表對的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                我正在編寫一個 Spark 應用程序,并希望將一組鍵值對 (K, V1), (K, V2), ..., (K, Vn) 組合成一個鍵-多值對(K, [V1, V2, ..., Vn]).我覺得我應該能夠使用具有某種風味的 reduceByKey 函數來做到這一點:

                I am writing a Spark application and want to combine a set of Key-Value pairs (K, V1), (K, V2), ..., (K, Vn) into one Key-Multivalue pair (K, [V1, V2, ..., Vn]). I feel like I should be able to do this using the reduceByKey function with something of the flavor:

                My_KMV = My_KV.reduce(lambda a, b: a.append([b]))
                

                發生這種情況時我得到的錯誤是:

                The error that I get when this occurs is:

                NoneType"對象沒有附加"屬性.

                'NoneType' object has no attribue 'append'.

                我的鍵是整數,值 V1,...,Vn 是元組.我的目標是使用鍵和值列表(元組)創建一對.

                My keys are integers and values V1,...,Vn are tuples. My goal is to create a single pair with the key and a list of the values (tuples).

                推薦答案

                Map和ReduceByKey

                reduce的輸入類型和輸出類型必須相同,所以如果你想聚合一個列表,你必須map輸入到列表.然后將這些列表合并為一個列表.

                Input type and output type of reduce must be the same, therefore if you want to aggregate a list, you have to map the input to lists. Afterwards you combine the lists into one list.

                組合列表

                您需要一種將列表合并為一個列表的方法.Python 提供了一些組合列表的方法.

                You'll need a method to combine lists into one list. Python provides some methods to combine lists.

                append 修改第一個列表,并且總是返回 None.

                append modifies the first list and will always return None.

                x = [1, 2, 3]
                x.append([4, 5])
                # x is [1, 2, 3, [4, 5]]
                

                extend 做同樣的事情,但解開列表:

                extend does the same, but unwraps lists:

                x = [1, 2, 3]
                x.extend([4, 5])
                # x is [1, 2, 3, 4, 5]
                

                這兩種方法都返回 None,但您需要一個返回組合列表的方法,因此只需 使用加號.

                Both methods return None, but you'll need a method that returns the combined list, therefore just use the plus sign.

                x = [1, 2, 3] + [4, 5]
                # x is [1, 2, 3, 4, 5]
                

                火花

                file = spark.textFile("hdfs://...")
                counts = file.flatMap(lambda line: line.split(" ")) 
                         .map(lambda actor: (actor.split(",")[0], actor))  
                
                         # transform each value into a list
                         .map(lambda nameTuple: (nameTuple[0], [ nameTuple[1] ])) 
                
                         # combine lists: ([1,2,3] + [4,5]) becomes [1,2,3,4,5]
                         .reduceByKey(lambda a, b: a + b)
                

                <小時>

                組合鍵

                也可以使用 combineByKey 來解決這個問題,它在內部用于實現 reduceByKey,但它更復雜并且 在 Spark 中使用一種專門的按鍵組合器可以更快"一個>.對于上面的解決方案,您的用例已經足夠簡單了.

                It's also possible to solve this with combineByKey, which is used internally to implement reduceByKey, but it's more complex and "using one of the specialized per-key combiners in Spark can be much faster". Your use case is simple enough for the upper solution.

                GroupByKey

                也可以使用 groupByKey、但它會減少并行化,因此對于大數據集可能會慢得多.

                It's also possible to solve this with groupByKey, but it reduces parallelization and therefore could be much slower for big data sets.

                這篇關于使用 Apache Spark 將鍵值對縮減為鍵列表對的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                相關文檔推薦

                python: Two modules and classes with the same name under different packages(python:不同包下同名的兩個模塊和類)
                Configuring Python to use additional locations for site-packages(配置 Python 以使用站點包的其他位置)
                How to structure python packages without repeating top level name for import(如何在不重復導入頂級名稱的情況下構造python包)
                Install python packages on OpenShift(在 OpenShift 上安裝 python 包)
                How to refresh sys.path?(如何刷新 sys.path?)
                Distribute a Python package with a compiled dynamic shared library(分發帶有已編譯動態共享庫的 Python 包)
                <i id='NNJjG'><tr id='NNJjG'><dt id='NNJjG'><q id='NNJjG'><span id='NNJjG'><b id='NNJjG'><form id='NNJjG'><ins id='NNJjG'></ins><ul id='NNJjG'></ul><sub id='NNJjG'></sub></form><legend id='NNJjG'></legend><bdo id='NNJjG'><pre id='NNJjG'><center id='NNJjG'></center></pre></bdo></b><th id='NNJjG'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='NNJjG'><tfoot id='NNJjG'></tfoot><dl id='NNJjG'><fieldset id='NNJjG'></fieldset></dl></div>
                <legend id='NNJjG'><style id='NNJjG'><dir id='NNJjG'><q id='NNJjG'></q></dir></style></legend>

                    <bdo id='NNJjG'></bdo><ul id='NNJjG'></ul>
                  • <tfoot id='NNJjG'></tfoot>

                      <small id='NNJjG'></small><noframes id='NNJjG'>

                        <tbody id='NNJjG'></tbody>
                        • 主站蜘蛛池模板: 成人在线中文字幕 | 国产一区二区在线91 | 精品亚洲一区二区三区 | av在线三级| 久久久久国产一区二区三区 | 久久久久国产精品一区二区 | 久久久久久九九九九 | 午夜色婷婷 | 天堂网中文字幕在线观看 | 99亚洲精品 | 亚洲一区二区三区免费在线观看 | 91porn在线观看 | 99精品欧美一区二区三区综合在线 | av网址在线 | 国产亚洲精品久久久久久豆腐 | 免费一级做a爰片久久毛片潮喷 | 色资源站| 一级毛片在线播放 | 成人做爰999 | 成人亚洲在线 | 亚洲品质自拍视频网站 | 欧美999| 黄色片在线免费看 | 欧美日日日日bbbbb视频 | 欧美视频成人 | 精品一区久久 | 午夜丁香视频在线观看 | 日韩中文视频 | 成人在线精品 | 国产在线一区二区 | 韩日一区二区 | 成人在线中文字幕 | 欧美日韩精品一区二区三区视频 | 久久精品视频在线播放 | 久久最新 | 国产精品久久久久久久久久久久冷 | 在线2区 | 99精品国产一区二区青青牛奶 | 99re66在线观看精品热 | 美女视频黄色的 | 欧美人成在线视频 |