簡體   English   中英

與Spark結合使用的MongoHadoop Connector按分區數量重復結果

[英]MongoHadoop Connector used with Spark duplicates results by number of partitions

我正在嘗試使用mongo-hadoop連接器將數據讀入spark。 問題是,如果我嘗試設置有關讀取數據的限制,則在RDD中獲得限制*分區數。

mongodbConfig.set("mongo.job.input.format","com.mongodb.hadoop.MongoInputFormat");
mongodbConfig.set("mongo.input.uri", "mongodb://localhost:27017/test.restaurants");
mongodbConfig.set("mongo.input.limit","3");
JavaPairRDD<Object, BSONObject> documents = sc.newAPIHadoopRDD(
            mongodbConfig,            // Configuration
            MongoInputFormat.class,   // InputFormat: read from a live cluster.
            Object.class,             // Key class
            BSONObject.class          // Value class
    );

    long count = documents.count();
    System.out.println("Collection Count: " + count);
    System.out.println("Partitions: " + documents.partitions().size());

//9 elements in the RDD = limit * nrOfPartions = 3 * 3
//3 partitions

對於其他限制,此行為是可復制的(我總是得到限制* 3)。

如果我嘗試簡單地通過objectId進行查詢,則會得到類似的行為(它創建一個具有相同對象*分區數的RDD-在我的情況下是具有相同文檔的3個元素)。

如果有幫助,我還可以提供用於創建mongo集合的腳本。

這是一個功能,而不是錯誤。 mongo.input.limit用於設置MongoInputSplit limit參數 ,因此它逐個分區而不全局地應用。

通常,不可能(或者確切地說是實際的)限制全局獲取記錄的數量。 每個拆分都是獨立處理的,通常沒有關於每個拆分產生的記錄數量的先驗知識。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM