Skip to content

Commit 2cfef6f

Browse files
committed
[JAVA-251]: some renaming and convenience added to map reduce
1 parent fe3d60c commit 2cfef6f

File tree

3 files changed

+22
-13
lines changed

3 files changed

+22
-13
lines changed

src/main/com/mongodb/DBCollection.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -978,9 +978,10 @@ public MapReduceOutput mapReduce( String map , String reduce , String outputTarg
978978
* @throws MongoException
979979
*/
980980
public MapReduceOutput mapReduce( MapReduceCommand command ) throws MongoException{
981-
CommandResult res = _db.command( command.toDBObject() );
981+
DBObject cmd = command.toDBObject();
982+
CommandResult res = _db.command( cmd );
982983
res.throwOnError();
983-
return new MapReduceOutput( this , res );
984+
return new MapReduceOutput( this , cmd, res );
984985
}
985986

986987
/**
@@ -996,7 +997,7 @@ public MapReduceOutput mapReduce( DBObject command ) throws MongoException{
996997
throw new IllegalArgumentException( "need mapreduce arg" );
997998
CommandResult res = _db.command( command );
998999
res.throwOnError();
999-
return new MapReduceOutput( this , res );
1000+
return new MapReduceOutput( this , command, res );
10001001
}
10011002

10021003
/**

src/main/com/mongodb/MapReduceCommand.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,19 @@
1919

2020
public class MapReduceCommand {
2121

22-
static enum OutputType {
23-
STANDARD, MERGE, REDUCE, INLINE
22+
/**
23+
* INLINE - Return results inline, no result is written to the DB server
24+
* REPLACE - Save the job output to a collection, replacing its previous content
25+
* MERGE - Merge the job output with the existing contents of outputTarget collection
26+
* REDUCE - Reduce the job output with the existing contents of outputTarget collection
27+
*/
28+
public static enum OutputType {
29+
REPLACE, MERGE, REDUCE, INLINE
2430
};
2531

2632
/**
2733
* Represents the command for a map reduce operation
28-
* Runs the command in STANDARD output to a named collection
34+
* Runs the command in REPLACE output type to a named collection
2935
*
3036
* @param input
3137
* the collection to read from
@@ -46,7 +52,7 @@ static enum OutputType {
4652
_map = map;
4753
_reduce = reduce;
4854
_outputTarget = outputTarget;
49-
_outputType = OutputType.STANDARD;
55+
_outputType = OutputType.REPLACE;
5056
_query = query;
5157
}
5258

@@ -164,10 +170,6 @@ public String getOutputTarget(){
164170

165171
/**
166172
* Gets the OutputType for this instance.
167-
* INLINE - Return results inline
168-
* STANDARD - Save the job output to outputTarget
169-
* MERGE - Merge the job output with the existing contents of outputTarget
170-
* REDUCE - Reduce the job output with the existing contents of outputTarget
171173
* @return The outputType.
172174
*/
173175
public OutputType getOutputType(){
@@ -273,7 +275,7 @@ DBObject toDBObject() {
273275
case INLINE:
274276
builder.add("out", new BasicDBObject("inline", 1));
275277
break;
276-
case STANDARD:
278+
case REPLACE:
277279
builder.add("out", _outputTarget);
278280
break;
279281
case MERGE:

src/main/com/mongodb/MapReduceOutput.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
*/
99
public class MapReduceOutput {
1010

11-
MapReduceOutput( DBCollection from , BasicDBObject raw ){
11+
MapReduceOutput( DBCollection from , DBObject cmd, BasicDBObject raw ){
1212
_raw = raw;
13+
_cmd = cmd;
1314

1415
if ( raw.containsKey( "results" ) ) {
1516
_coll = null;
@@ -52,6 +53,10 @@ public BasicDBObject getRaw(){
5253
return _raw;
5354
}
5455

56+
public DBObject getCommand() {
57+
return _cmd;
58+
}
59+
5560
public String toString(){
5661
return _raw.toString();
5762
}
@@ -62,4 +67,5 @@ public String toString(){
6267
final Iterable<DBObject> _resultSet;
6368
final DBCollection _coll;
6469
final BasicDBObject _counts;
70+
final DBObject _cmd;
6571
}

0 commit comments

Comments
 (0)