Search in sources :

Example 71 with BasicDBList

use of com.mongodb.BasicDBList in project teiid by teiid.

the class MongoDBSelectVisitor method visit.

@Override
public void visit(Array array) {
    append(array.getExpressions());
    BasicDBList values = new BasicDBList();
    for (int i = 0; i < array.getExpressions().size(); i++) {
        values.add(0, this.onGoingExpression.pop());
    }
    this.onGoingExpression.push(values);
}
Also used : BasicDBList(com.mongodb.BasicDBList)

Example 72 with BasicDBList

use of com.mongodb.BasicDBList in project teiid by teiid.

the class MongoDBSelectVisitor method visitDerivedExpression.

private void visitDerivedExpression(Comparison obj) {
    append(obj.getLeftExpression());
    Object leftExpr = this.onGoingExpression.pop();
    append(obj.getRightExpression());
    Object rightExpr = this.onGoingExpression.pop();
    BasicDBList values = new BasicDBList();
    values.add(0, leftExpr);
    values.add(1, rightExpr);
    switch(obj.getOperator()) {
        case EQ:
            // $NON-NLS-1$
            this.onGoingExpression.push(new BasicDBObject("$eq", values));
            break;
        case NE:
            // $NON-NLS-1$
            this.onGoingExpression.push(new BasicDBObject("$ne", values));
            break;
        case LT:
            // $NON-NLS-1$
            this.onGoingExpression.push(new BasicDBObject("$lt", values));
            break;
        case LE:
            // $NON-NLS-1$
            this.onGoingExpression.push(new BasicDBObject("$lte", values));
            break;
        case GT:
            // $NON-NLS-1$
            this.onGoingExpression.push(new BasicDBObject("$gt", values));
            break;
        case GE:
            // $NON-NLS-1$
            this.onGoingExpression.push(new BasicDBObject("$gte", values));
            break;
    }
}
Also used : BasicDBList(com.mongodb.BasicDBList) BasicDBObject(com.mongodb.BasicDBObject) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject)

Example 73 with BasicDBList

use of com.mongodb.BasicDBList in project teiid by teiid.

the class MongoDBSelectVisitor method buildNE.

private BasicDBObject buildNE(Object leftExpr, Object rightExpr) {
    BasicDBList values = new BasicDBList();
    values.add(0, leftExpr);
    values.add(1, rightExpr);
    return new BasicDBObject("$ne", values);
}
Also used : BasicDBList(com.mongodb.BasicDBList) BasicDBObject(com.mongodb.BasicDBObject)

Example 74 with BasicDBList

use of com.mongodb.BasicDBList in project teiid by teiid.

the class MongoDBSelectVisitor method buildGeoNearFunction.

private DBObject buildGeoNearFunction(Function function) throws TranslatorException {
    List<Expression> args = function.getParameters();
    // Column Name
    int paramIndex = 0;
    ColumnDetail column = getExpressionAlias(args.get(paramIndex++));
    BasicDBObjectBuilder builder = BasicDBObjectBuilder.start();
    builder.push(column.documentFieldName);
    builder.push(function.getName());
    append(args.get(paramIndex++));
    Object object = this.onGoingExpression.pop();
    if (object instanceof GeometryType) {
        convertGeometryToJson(builder, (GeometryType) object);
    } else {
        // $NON-NLS-1$
        builder.push("$geometry");
        // $NON-NLS-1$
        builder.add("type", SpatialType.Point.name());
        // walk the co-ordinates
        BasicDBList coordinates = new BasicDBList();
        coordinates.add(object);
        // $NON-NLS-1$
        builder.add("coordinates", coordinates);
    }
    // maxdistance
    append(args.get(paramIndex++));
    BasicDBObjectBuilder b = builder.pop();
    // $NON-NLS-1$
    b.add("$maxDistance", this.onGoingExpression.pop());
    if (this.executionFactory.getVersion().compareTo(MongoDBExecutionFactory.TWO_6) >= 0) {
        // mindistance
        append(args.get(paramIndex++));
        // $NON-NLS-1$
        b.add("$minDistance", this.onGoingExpression.pop());
    }
    return builder.get();
}
Also used : GeometryType(org.teiid.core.types.GeometryType) BasicDBList(com.mongodb.BasicDBList) BasicDBObjectBuilder(com.mongodb.BasicDBObjectBuilder) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject)

Example 75 with BasicDBList

use of com.mongodb.BasicDBList in project teiid by teiid.

the class MongoDBSelectVisitor method buildGeoFunction.

private DBObject buildGeoFunction(Function function) throws TranslatorException {
    List<Expression> args = function.getParameters();
    // Column Name
    int paramIndex = 0;
    ColumnDetail column = getExpressionAlias(args.get(paramIndex++));
    BasicDBObjectBuilder builder = BasicDBObjectBuilder.start();
    builder.push(column.documentFieldName);
    builder.push(function.getName());
    append(args.get(paramIndex++));
    Object object = this.onGoingExpression.pop();
    if (object instanceof GeometryType) {
        convertGeometryToJson(builder, (GeometryType) object);
    } else {
        // Type: Point, LineString, Polygon..
        SpatialType type = SpatialType.valueOf((String) object);
        append(args.get(paramIndex++));
        // $NON-NLS-1$
        builder.push("$geometry");
        // $NON-NLS-1$
        builder.add("type", type.name());
        // walk the co-ordinates
        BasicDBList coordinates = new BasicDBList();
        coordinates.add(this.onGoingExpression.pop());
        // $NON-NLS-1$
        builder.add("coordinates", coordinates);
    }
    return builder.get();
}
Also used : GeometryType(org.teiid.core.types.GeometryType) BasicDBList(com.mongodb.BasicDBList) BasicDBObjectBuilder(com.mongodb.BasicDBObjectBuilder) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject)

Aggregations

BasicDBList (com.mongodb.BasicDBList)108 BasicDBObject (com.mongodb.BasicDBObject)69 DBObject (com.mongodb.DBObject)50 Test (org.junit.jupiter.api.Test)17 Document (org.springframework.data.mongodb.core.mapping.Document)14 DBCollection (com.mongodb.DBCollection)11 ArrayList (java.util.ArrayList)11 Test (org.junit.Test)11 DBCursor (com.mongodb.DBCursor)8 DBRef (com.mongodb.DBRef)8 List (java.util.List)7 Document (org.bson.Document)7 HashMap (java.util.HashMap)6 ObjectId (org.bson.types.ObjectId)6 MongoClient (com.mongodb.MongoClient)4 Map (java.util.Map)4 NotFoundException (org.graylog2.database.NotFoundException)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 MongoInputSplit (com.mongodb.hadoop.input.MongoInputSplit)3 IOException (java.io.IOException)3