0

これは私のmapreduceコードです:

DBCollection mongoCollection = MongoDAO.getCollection();
String map = "function() {"
        + "for (index in this.positions.positionList) {"
        + "emit(this._id+'|'+this.headline+'|'+"
        + "this.location.name+'|'+this.location.country.code+'|'+this.publicProfileUrl+'|'+"
        + "this.positions.positionList[index].title+'|'+"
        + "this.positions.positionList[index].company.name+'|'+this.positions.positionList[index].company.industry+'|'+"
        + "this.positions.positionList[index].company.type+'|'+this.positions.positionList[index].company.size+'|'+"
        + "this.lastName+'|'+this.firstName+'|'+this.industry+'|'+this.updatedDate+'|' , {count: 1});"
        + "}}";
String reduce = "";
MapReduceCommand mapReduceCommand = new MapReduceCommand(
        mongoCollection, map, reduce.toString(), "final_result",
        MapReduceCommand.OutputType.REPLACE, null);

MapReduceOutput out = mongoCollection.mapReduce(mapReduceCommand);

現在、140,000レコードを処理しています。しかし、mapreduceを実行している間、レコードの数は90,000に減少します。データセットに重複するレコードはありません。

4

1 に答える 1

1

エミットを変更して、_id をキーとして、パイプで区切られた文字列を値として出力します。例として:

emit(this._id, [this._id, this.a, this.b,...].join('|'))

私が考えているのは、キーに過度に長い文字列を作成していることです。キーとなる _id 値には 1KB (2.0 では以前の 800B から増加) の制限があります。

また、独自に展開するのではなく、事前にパッケージ化された mongodb-hadoop コネクタを調べることをお勧めします: https://github.com/mongodb/mongo-hadoop

于 2012-05-04T17:10:58.717 に答える