Search in sources :

Example 1 with MongoOp

use of org.apache.drill.exec.store.mongo.common.MongoOp in project drill by apache.

the class MongoFilterBuilder method createFunctionCall.

private Document createFunctionCall(String functionName, SchemaPath field, Object fieldValue) {
    // extract the field name
    String fieldName = field.getRootSegmentPath();
    MongoOp compareOp = null;
    switch(functionName) {
        case FunctionNames.EQ:
            compareOp = MongoOp.EQUAL;
            break;
        case FunctionNames.NE:
            compareOp = MongoOp.NOT_EQUAL;
            break;
        case FunctionNames.GE:
            compareOp = MongoOp.GREATER_OR_EQUAL;
            break;
        case FunctionNames.GT:
            compareOp = MongoOp.GREATER;
            break;
        case FunctionNames.LE:
            compareOp = MongoOp.LESS_OR_EQUAL;
            break;
        case FunctionNames.LT:
            compareOp = MongoOp.LESS;
            break;
        case FunctionNames.IS_NULL:
        case "isNull":
        case "is null":
            compareOp = MongoOp.IFNULL;
            break;
        case FunctionNames.IS_NOT_NULL:
        case "isNotNull":
        case "is not null":
            compareOp = MongoOp.IFNOTNULL;
            break;
    }
    if (compareOp != null) {
        Document queryFilter = new Document();
        if (compareOp == MongoOp.IFNULL) {
            queryFilter.put(fieldName, new Document(MongoOp.EQUAL.getCompareOp(), null));
        } else if (compareOp == MongoOp.IFNOTNULL) {
            queryFilter.put(fieldName, new Document(MongoOp.NOT_EQUAL.getCompareOp(), null));
        } else {
            queryFilter.put(fieldName, new Document(compareOp.getCompareOp(), fieldValue));
        }
        return queryFilter;
    }
    return null;
}
Also used : Document(org.bson.Document) MongoOp(org.apache.drill.exec.store.mongo.common.MongoOp)

Aggregations

MongoOp (org.apache.drill.exec.store.mongo.common.MongoOp)1 Document (org.bson.Document)1