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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations