Search in sources :

Example 1 with DynamicOperandImpl

use of org.apache.jackrabbit.oak.query.ast.DynamicOperandImpl in project jackrabbit-oak by apache.

the class QueryImpl method canSortByIndex.

private boolean canSortByIndex() {
    boolean canSortByIndex = false;
    // TODO add issue about order by optimization for multiple selectors
    if (orderings != null && selectors.size() == 1) {
        IndexPlan plan = selectors.get(0).getExecutionPlan().getIndexPlan();
        if (plan != null) {
            List<OrderEntry> list = plan.getSortOrder();
            if (list != null && list.size() == orderings.length) {
                canSortByIndex = true;
                for (int i = 0; i < list.size(); i++) {
                    OrderEntry e = list.get(i);
                    OrderingImpl o = orderings[i];
                    DynamicOperandImpl op = o.getOperand();
                    if (!(op instanceof PropertyValueImpl)) {
                        // ordered by a function: currently not supported
                        canSortByIndex = false;
                        break;
                    }
                    // we only have one selector, so no need to check that
                    // TODO support joins
                    String pn = ((PropertyValueImpl) op).getPropertyName();
                    if (!pn.equals(e.getPropertyName())) {
                        // ordered by another property
                        canSortByIndex = false;
                        break;
                    }
                    if (o.isDescending() != (e.getOrder() == Order.DESCENDING)) {
                        // ordered ascending versus descending
                        canSortByIndex = false;
                        break;
                    }
                }
            }
        }
    }
    return canSortByIndex;
}
Also used : DynamicOperandImpl(org.apache.jackrabbit.oak.query.ast.DynamicOperandImpl) OrderEntry(org.apache.jackrabbit.oak.spi.query.QueryIndex.OrderEntry) IndexPlan(org.apache.jackrabbit.oak.spi.query.QueryIndex.IndexPlan) OrderingImpl(org.apache.jackrabbit.oak.query.ast.OrderingImpl) PropertyValueImpl(org.apache.jackrabbit.oak.query.ast.PropertyValueImpl)

Example 2 with DynamicOperandImpl

use of org.apache.jackrabbit.oak.query.ast.DynamicOperandImpl in project jackrabbit-oak by apache.

the class SQL2Parser method parseOrder.

private OrderingImpl[] parseOrder() throws ParseException {
    ArrayList<OrderingImpl> orderList = new ArrayList<OrderingImpl>();
    do {
        OrderingImpl ordering;
        DynamicOperandImpl op = parseDynamicOperand();
        if (readIf("DESC")) {
            ordering = factory.descending(op);
        } else {
            readIf("ASC");
            ordering = factory.ascending(op);
        }
        orderList.add(ordering);
    } while (readIf(","));
    OrderingImpl[] orderings = new OrderingImpl[orderList.size()];
    orderList.toArray(orderings);
    return orderings;
}
Also used : DynamicOperandImpl(org.apache.jackrabbit.oak.query.ast.DynamicOperandImpl) OrderingImpl(org.apache.jackrabbit.oak.query.ast.OrderingImpl) ArrayList(java.util.ArrayList)

Example 3 with DynamicOperandImpl

use of org.apache.jackrabbit.oak.query.ast.DynamicOperandImpl in project jackrabbit-oak by apache.

the class SQL2Parser method parseExpressionFunction.

private DynamicOperandImpl parseExpressionFunction(String functionName) throws ParseException {
    DynamicOperandImpl op;
    if ("LENGTH".equalsIgnoreCase(functionName)) {
        op = factory.length(parseDynamicOperand());
    } else if ("NAME".equalsIgnoreCase(functionName)) {
        if (isToken(")")) {
            op = factory.nodeName(getOnlySelectorName());
        } else {
            op = factory.nodeName(readName());
        }
    } else if ("LOCALNAME".equalsIgnoreCase(functionName)) {
        if (isToken(")")) {
            op = factory.nodeLocalName(getOnlySelectorName());
        } else {
            op = factory.nodeLocalName(readName());
        }
    } else if ("SCORE".equalsIgnoreCase(functionName)) {
        if (isToken(")")) {
            op = factory.fullTextSearchScore(getOnlySelectorName());
        } else {
            op = factory.fullTextSearchScore(readName());
        }
    } else if ("COALESCE".equalsIgnoreCase(functionName)) {
        DynamicOperandImpl op1 = parseDynamicOperand();
        read(",");
        DynamicOperandImpl op2 = parseDynamicOperand();
        op = factory.coalesce(op1, op2);
    } else if ("LOWER".equalsIgnoreCase(functionName)) {
        op = factory.lowerCase(parseDynamicOperand());
    } else if ("UPPER".equalsIgnoreCase(functionName)) {
        op = factory.upperCase(parseDynamicOperand());
    } else if ("PROPERTY".equalsIgnoreCase(functionName)) {
        PropertyValueImpl pv = parsePropertyValue(readName());
        read(",");
        op = factory.propertyValue(pv.getSelectorName(), pv.getPropertyName(), readString().getValue(Type.STRING));
    } else {
        throw getSyntaxError("LENGTH, NAME, LOCALNAME, SCORE, COALESCE, LOWER, UPPER, or PROPERTY");
    }
    read(")");
    return op;
}
Also used : DynamicOperandImpl(org.apache.jackrabbit.oak.query.ast.DynamicOperandImpl) PropertyValueImpl(org.apache.jackrabbit.oak.query.ast.PropertyValueImpl)

Example 4 with DynamicOperandImpl

use of org.apache.jackrabbit.oak.query.ast.DynamicOperandImpl in project jackrabbit-oak by apache.

the class QueryImpl method getSortOrder.

private List<OrderEntry> getSortOrder(FilterImpl filter) {
    if (orderings == null) {
        return null;
    }
    ArrayList<OrderEntry> sortOrder = new ArrayList<OrderEntry>();
    for (OrderingImpl o : orderings) {
        DynamicOperandImpl op = o.getOperand();
        OrderEntry e = op.getOrderEntry(filter.getSelector(), o);
        if (e == null) {
            continue;
        }
        sortOrder.add(e);
    }
    if (sortOrder.size() == 0) {
        return null;
    }
    return sortOrder;
}
Also used : DynamicOperandImpl(org.apache.jackrabbit.oak.query.ast.DynamicOperandImpl) OrderEntry(org.apache.jackrabbit.oak.spi.query.QueryIndex.OrderEntry) OrderingImpl(org.apache.jackrabbit.oak.query.ast.OrderingImpl) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) ArrayList(java.util.ArrayList)

Example 5 with DynamicOperandImpl

use of org.apache.jackrabbit.oak.query.ast.DynamicOperandImpl in project jackrabbit-oak by apache.

the class SQL2Parser method parseCondition.

private ConstraintImpl parseCondition() throws ParseException {
    ConstraintImpl a;
    if (readIf("NOT")) {
        a = factory.not(parseCondition());
    } else if (readIf("(")) {
        a = parseConstraint();
        read(")");
    } else if (currentTokenType == IDENTIFIER) {
        String identifier = readName();
        if (readIf("(")) {
            a = parseConditionFunctionIf(identifier);
            if (a == null) {
                DynamicOperandImpl op = parseExpressionFunction(identifier);
                a = parseCondition(op);
            }
        } else if (readIf(".")) {
            a = parseCondition(factory.propertyValue(identifier, readName()));
        } else {
            a = parseCondition(factory.propertyValue(getOnlySelectorName(), identifier));
        }
    } else if ("[".equals(currentToken)) {
        String name = readName();
        if (readIf(".")) {
            a = parseCondition(factory.propertyValue(name, readName()));
        } else {
            a = parseCondition(factory.propertyValue(getOnlySelectorName(), name));
        }
    } else if (supportSQL1) {
        StaticOperandImpl left = parseStaticOperand();
        if (readIf("IN")) {
            DynamicOperandImpl right = parseDynamicOperand();
            ConstraintImpl c = factory.comparison(right, Operator.EQUAL, left);
            return c;
        } else {
            throw getSyntaxError();
        }
    } else {
        throw getSyntaxError();
    }
    return a;
}
Also used : DynamicOperandImpl(org.apache.jackrabbit.oak.query.ast.DynamicOperandImpl) ConstraintImpl(org.apache.jackrabbit.oak.query.ast.ConstraintImpl) StaticOperandImpl(org.apache.jackrabbit.oak.query.ast.StaticOperandImpl)

Aggregations

DynamicOperandImpl (org.apache.jackrabbit.oak.query.ast.DynamicOperandImpl)5 OrderingImpl (org.apache.jackrabbit.oak.query.ast.OrderingImpl)3 ArrayList (java.util.ArrayList)2 PropertyValueImpl (org.apache.jackrabbit.oak.query.ast.PropertyValueImpl)2 OrderEntry (org.apache.jackrabbit.oak.spi.query.QueryIndex.OrderEntry)2 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)1 ConstraintImpl (org.apache.jackrabbit.oak.query.ast.ConstraintImpl)1 StaticOperandImpl (org.apache.jackrabbit.oak.query.ast.StaticOperandImpl)1 IndexPlan (org.apache.jackrabbit.oak.spi.query.QueryIndex.IndexPlan)1