Search in sources :

Example 6 with OSQLFilterCondition

use of com.orientechnologies.orient.core.sql.filter.OSQLFilterCondition in project orientdb by orientechnologies.

the class OCommandExecutorSQLResultsetAbstract method getRange.

protected ORID[] getRange() {
    final ORID beginRange;
    final ORID endRange;
    final OSQLFilterCondition rootCondition = compiledFilter == null ? null : compiledFilter.getRootCondition();
    if (compiledFilter == null || rootCondition == null) {
        if (request instanceof OSQLSynchQuery)
            beginRange = ((OSQLSynchQuery<ODocument>) request).getNextPageRID();
        else
            beginRange = null;
        endRange = null;
    } else {
        final ORID conditionBeginRange = rootCondition.getBeginRidRange();
        final ORID conditionEndRange = rootCondition.getEndRidRange();
        final ORID nextPageRid;
        if (request instanceof OSQLSynchQuery)
            nextPageRid = ((OSQLSynchQuery<ODocument>) request).getNextPageRID();
        else
            nextPageRid = null;
        if (conditionBeginRange != null && nextPageRid != null)
            beginRange = conditionBeginRange.compareTo(nextPageRid) > 0 ? conditionBeginRange : nextPageRid;
        else if (conditionBeginRange != null)
            beginRange = conditionBeginRange;
        else
            beginRange = nextPageRid;
        endRange = conditionEndRange;
    }
    return new ORID[] { beginRange, endRange };
}
Also used : OSQLFilterCondition(com.orientechnologies.orient.core.sql.filter.OSQLFilterCondition) OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) ORID(com.orientechnologies.orient.core.id.ORID)

Example 7 with OSQLFilterCondition

use of com.orientechnologies.orient.core.sql.filter.OSQLFilterCondition in project orientdb by orientechnologies.

the class OCommandExecutorSQLResultsetAbstract method optimizeBranch.

protected void optimizeBranch(final OSQLFilterCondition iParentCondition, OSQLFilterCondition iCondition) {
    if (iCondition == null)
        return;
    Object left = iCondition.getLeft();
    if (left instanceof OSQLFilterCondition) {
        // ANALYSE LEFT RECURSIVELY
        optimizeBranch(iCondition, (OSQLFilterCondition) left);
    } else if (left instanceof OSQLFunctionRuntime) {
        left = optimizeFunction((OSQLFunctionRuntime) left);
        iCondition.setLeft(left);
    }
    Object right = iCondition.getRight();
    if (right instanceof OSQLFilterCondition) {
        // ANALYSE RIGHT RECURSIVELY
        optimizeBranch(iCondition, (OSQLFilterCondition) right);
    } else if (right instanceof OSQLFunctionRuntime) {
        right = optimizeFunction((OSQLFunctionRuntime) right);
        iCondition.setRight(right);
    }
    final OQueryOperator oper = iCondition.getOperator();
    Object result = null;
    if (left instanceof OSQLFilterItemField && right instanceof OSQLFilterItemField) {
        if (((OSQLFilterItemField) left).getRoot().equals(((OSQLFilterItemField) right).getRoot())) {
            if (oper instanceof OQueryOperatorEquals)
                result = Boolean.TRUE;
            else if ((oper instanceof OQueryOperatorNotEquals) || (oper instanceof OQueryOperatorNotEquals2))
                result = Boolean.FALSE;
        }
    }
    if (result != null) {
        if (iParentCondition != null)
            if (iCondition == iParentCondition.getLeft())
                // REPLACE LEFT
                iCondition.setLeft(result);
            else
                // REPLACE RIGHT
                iCondition.setRight(result);
        else {
            // REPLACE ROOT CONDITION
            if (result instanceof Boolean && ((Boolean) result))
                compiledFilter.setRootCondition(null);
        }
    }
}
Also used : OSQLFilterCondition(com.orientechnologies.orient.core.sql.filter.OSQLFilterCondition) OSQLFunctionRuntime(com.orientechnologies.orient.core.sql.functions.OSQLFunctionRuntime) OSQLFilterItemField(com.orientechnologies.orient.core.sql.filter.OSQLFilterItemField) OQueryOperatorNotEquals(com.orientechnologies.orient.core.sql.operator.OQueryOperatorNotEquals) OQueryOperatorNotEquals2(com.orientechnologies.orient.core.sql.operator.OQueryOperatorNotEquals2) OQueryOperator(com.orientechnologies.orient.core.sql.operator.OQueryOperator) OQueryOperatorEquals(com.orientechnologies.orient.core.sql.operator.OQueryOperatorEquals)

Example 8 with OSQLFilterCondition

use of com.orientechnologies.orient.core.sql.filter.OSQLFilterCondition in project orientdb by orientechnologies.

the class OQueryOperatorAnd method getEndRidRange.

@Override
public ORID getEndRidRange(final Object iLeft, final Object iRight) {
    final ORID leftRange;
    final ORID rightRange;
    if (iLeft instanceof OSQLFilterCondition)
        leftRange = ((OSQLFilterCondition) iLeft).getEndRidRange();
    else
        leftRange = null;
    if (iRight instanceof OSQLFilterCondition)
        rightRange = ((OSQLFilterCondition) iRight).getEndRidRange();
    else
        rightRange = null;
    if (leftRange == null && rightRange == null)
        return null;
    else if (leftRange == null)
        return rightRange;
    else if (rightRange == null)
        return leftRange;
    else
        return leftRange.compareTo(rightRange) >= 0 ? rightRange : leftRange;
}
Also used : OSQLFilterCondition(com.orientechnologies.orient.core.sql.filter.OSQLFilterCondition) ORID(com.orientechnologies.orient.core.id.ORID)

Example 9 with OSQLFilterCondition

use of com.orientechnologies.orient.core.sql.filter.OSQLFilterCondition in project orientdb by orientechnologies.

the class OQueryOperatorAnd method getBeginRidRange.

@Override
public ORID getBeginRidRange(final Object iLeft, final Object iRight) {
    final ORID leftRange;
    final ORID rightRange;
    if (iLeft instanceof OSQLFilterCondition)
        leftRange = ((OSQLFilterCondition) iLeft).getBeginRidRange();
    else
        leftRange = null;
    if (iRight instanceof OSQLFilterCondition)
        rightRange = ((OSQLFilterCondition) iRight).getBeginRidRange();
    else
        rightRange = null;
    if (leftRange == null && rightRange == null)
        return null;
    else if (leftRange == null)
        return rightRange;
    else if (rightRange == null)
        return leftRange;
    else
        return leftRange.compareTo(rightRange) <= 0 ? rightRange : leftRange;
}
Also used : OSQLFilterCondition(com.orientechnologies.orient.core.sql.filter.OSQLFilterCondition) ORID(com.orientechnologies.orient.core.id.ORID)

Example 10 with OSQLFilterCondition

use of com.orientechnologies.orient.core.sql.filter.OSQLFilterCondition in project orientdb by orientechnologies.

the class OQueryOperatorContains method evaluateExpression.

@Override
@SuppressWarnings("unchecked")
protected boolean evaluateExpression(final OIdentifiable iRecord, final OSQLFilterCondition iCondition, final Object iLeft, final Object iRight, OCommandContext iContext) {
    final OSQLFilterCondition condition;
    if (iCondition.getLeft() instanceof OSQLFilterCondition)
        condition = (OSQLFilterCondition) iCondition.getLeft();
    else if (iCondition.getRight() instanceof OSQLFilterCondition)
        condition = (OSQLFilterCondition) iCondition.getRight();
    else
        condition = null;
    if (iLeft instanceof Iterable<?>) {
        final Iterable<Object> iterable = (Iterable<Object>) iLeft;
        if (condition != null) {
            // CHECK AGAINST A CONDITION
            for (final Object o : iterable) {
                final OIdentifiable id;
                if (o instanceof OIdentifiable)
                    id = (OIdentifiable) o;
                else if (o instanceof Map<?, ?>) {
                    final Iterator<Object> iter = ((Map<?, Object>) o).values().iterator();
                    final Object v = iter.hasNext() ? iter.next() : null;
                    if (v instanceof OIdentifiable)
                        id = (OIdentifiable) v;
                    else
                        // TRANSFORM THE ENTIRE MAP IN A DOCUMENT. PROBABLY HAS BEEN IMPORTED FROM JSON
                        id = new ODocument((Map) o);
                } else if (o instanceof Iterable<?>) {
                    final Iterator<OIdentifiable> iter = ((Iterable<OIdentifiable>) o).iterator();
                    id = iter.hasNext() ? iter.next() : null;
                } else
                    continue;
                if ((Boolean) condition.evaluate(id, null, iContext) == Boolean.TRUE)
                    return true;
            }
        } else {
            // CHECK AGAINST A SINGLE VALUE
            OType type = null;
            if (iCondition.getLeft() instanceof OSQLFilterItemField && ((OSQLFilterItemField) iCondition.getLeft()).isFieldChain() && ((OSQLFilterItemField) iCondition.getLeft()).getFieldChain().getItemCount() == 1) {
                String fieldName = ((OSQLFilterItemField) iCondition.getLeft()).getFieldChain().getItemName(0);
                if (fieldName != null) {
                    Object record = iRecord.getRecord();
                    if (record instanceof ODocument) {
                        OProperty property = ((ODocument) record).getSchemaClass().getProperty(fieldName);
                        if (property != null && property.getType().isMultiValue()) {
                            type = property.getLinkedType();
                        }
                    }
                }
            }
            for (final Object o : iterable) {
                if (OQueryOperatorEquals.equals(iRight, o, type))
                    return true;
            }
        }
    } else if (iRight instanceof Iterable<?>) {
        // CHECK AGAINST A CONDITION
        final Iterable<OIdentifiable> iterable = (Iterable<OIdentifiable>) iRight;
        if (condition != null) {
            for (final OIdentifiable o : iterable) {
                if ((Boolean) condition.evaluate(o, null, iContext) == Boolean.TRUE)
                    return true;
            }
        } else {
            // CHECK AGAINST A SINGLE VALUE
            for (final Object o : iterable) {
                if (OQueryOperatorEquals.equals(iLeft, o))
                    return true;
            }
        }
    }
    return false;
}
Also used : OProperty(com.orientechnologies.orient.core.metadata.schema.OProperty) OType(com.orientechnologies.orient.core.metadata.schema.OType) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) OSQLFilterCondition(com.orientechnologies.orient.core.sql.filter.OSQLFilterCondition) OSQLFilterItemField(com.orientechnologies.orient.core.sql.filter.OSQLFilterItemField) Iterator(java.util.Iterator) Map(java.util.Map) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Aggregations

OSQLFilterCondition (com.orientechnologies.orient.core.sql.filter.OSQLFilterCondition)13 ORID (com.orientechnologies.orient.core.id.ORID)8 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)3 OSQLFilterItemField (com.orientechnologies.orient.core.sql.filter.OSQLFilterItemField)3 Map (java.util.Map)3 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)2 OProperty (com.orientechnologies.orient.core.metadata.schema.OProperty)2 OType (com.orientechnologies.orient.core.metadata.schema.OType)2 OCommandExecutionException (com.orientechnologies.orient.core.exception.OCommandExecutionException)1 ORecord (com.orientechnologies.orient.core.record.ORecord)1 OSQLFunctionRuntime (com.orientechnologies.orient.core.sql.functions.OSQLFunctionRuntime)1 OQueryOperator (com.orientechnologies.orient.core.sql.operator.OQueryOperator)1 OQueryOperatorEquals (com.orientechnologies.orient.core.sql.operator.OQueryOperatorEquals)1 OQueryOperatorNotEquals (com.orientechnologies.orient.core.sql.operator.OQueryOperatorNotEquals)1 OQueryOperatorNotEquals2 (com.orientechnologies.orient.core.sql.operator.OQueryOperatorNotEquals2)1 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1