Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
TEIID-3166: Updated default version of the MongoDB to 2.6, which incl…
…udes the useDisk=true by default as this is only available after 2.4, also fixed an error with and functions when used with version 2.6
  • Loading branch information
rareddy committed May 15, 2015
1 parent 377c15d commit 15838c2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
Expand Up @@ -55,6 +55,7 @@ public class MongoDBExecutionFactory extends ExecutionFactory<ConnectionFactory,
private static final String MONGO = "mongo"; //$NON-NLS-1$
public static final Version TWO_4 = Version.getVersion("2.4"); //$NON-NLS-1$
public static final Version TWO_6 = Version.getVersion("2.6"); //$NON-NLS-1$
public static final Version THREE_0 = Version.getVersion("3.0"); //$NON-NLS-1$

public static final String FUNC_GEO_WITHIN = "geoWithin"; //$NON-NLS-1$
public static final String FUNC_GEO_INTERSECTS = "geoIntersects"; //$NON-NLS-1$
Expand All @@ -67,7 +68,7 @@ public class MongoDBExecutionFactory extends ExecutionFactory<ConnectionFactory,
public static final String AVOID_PROJECTION = "AVOID_PROJECTION"; //$NON-NLS-1$

protected Map<String, FunctionModifier> functionModifiers = new TreeMap<String, FunctionModifier>(String.CASE_INSENSITIVE_ORDER);
private Version version = TWO_4;
private Version version = TWO_6;
private boolean useDisk = true;
private boolean supportsAggregatesCount = true;

Expand Down Expand Up @@ -604,10 +605,10 @@ else if (value instanceof Object[]) {
}

public AggregationOptions getOptions(int batchSize) {
if (this.version.equals(TWO_6)) {
return AggregationOptions.builder().batchSize(batchSize).outputMode(AggregationOptions.OutputMode.CURSOR)
.allowDiskUse(useDisk()).build();
if (this.version.compareTo(TWO_4) < 0) {
return AggregationOptions.builder().batchSize(batchSize).outputMode(AggregationOptions.OutputMode.INLINE).build();
}
return AggregationOptions.builder().batchSize(batchSize).outputMode(AggregationOptions.OutputMode.INLINE).build();
return AggregationOptions.builder().batchSize(batchSize).outputMode(AggregationOptions.OutputMode.CURSOR)
.allowDiskUse(useDisk()).build();
}
}
Expand Up @@ -978,8 +978,14 @@ private DBObject buildGeoNearFunction(Function function) {

// maxdistance
append(args.get(paramIndex++));
builder.pop().add("$maxDistance", this.onGoingExpression.pop()); //$NON-NLS-1$
BasicDBObjectBuilder b= builder.pop();
b.add("$maxDistance", this.onGoingExpression.pop()); //$NON-NLS-1$

if (this.executionFactory.getVersion().compareTo(MongoDBExecutionFactory.TWO_6) >= 0) {
// mindistance
append(args.get(paramIndex++));
b.add("$minDistance", this.onGoingExpression.pop()); //$NON-NLS-1$
}
return builder.get();
}

Expand Down
Expand Up @@ -431,9 +431,9 @@ public void testGeoWithinPloygonFunction() throws Exception {

@Test
public void testGeoNearFunction() throws Exception {
String query = "SELECT mongo.geonear(user_id, (cast(1.0 as double), cast(2.0 as double)), 22) FROM users";
String query = "SELECT mongo.geonear(user_id, (cast(1.0 as double), cast(2.0 as double)), 22, 10) FROM users";
helpExecute(query, "users",
"{ \"_m0\" : { \"user_id\" : { \"$near\" : { \"$geometry\" : { \"type\" : \"Point\" , \"coordinates\" : [ [ 1.0 , 2.0]]} , \"$maxDistance\" : 22}}}}",
"{ \"_m0\" : { \"user_id\" : { \"$near\" : { \"$geometry\" : { \"type\" : \"Point\" , \"coordinates\" : [ [ 1.0 , 2.0]]} , \"$maxDistance\" : 22 , \"$minDistance\" : 10}}}}",
null);
}

Expand Down

0 comments on commit 15838c2

Please sign in to comment.