} else if (rangeCond != null) { if (!rangeCond.getName().equals(fieldDef.getName())) { throw new MalformedQueryException("Query defines range condition on field " + rangeCond.getName() + " but has no equals condition on field " + fieldDef.getName() + " which comes earlier in the index definition."); final Object fromValue = query.getRangeCondition().getFromValue(); final Object toValue = query.getRangeCondition().getToValue(); if (query.getCondition(fieldDef.getName()) != null) { message.append(fieldDef.getName()); } else if (rangeCond != null && rangeCond.getName().equals(fieldDef.getName())) { message.append(fieldDef.getName()); rangeCond != null && (rangeCond.isUpperBoundInclusive() || rangeCond.getToValue() == Query.MAX_VALUE); CompareOp op = rangeCondSet && !upperBoundInclusive ? CompareOp.LESS : CompareOp.LESS_OR_EQUAL; Filter toFilter = new RowFilter(op, new BinaryPrefixComparator(toKey)); if (rangeCondSet && !rangeCond.isLowerBoundInclusive()) {
/** * Validates that all fields used in the query actually exist in the index definition. * * TODO: shouldn't we also validate that the requested sort order corresponds with the indexed order etc? * * @param query query to validate */ private void validateQuery(Query query) { for (Query.EqualsCondition eqCond : query.getEqConditions()) { if (definition.getField(eqCond.getName()) == null) { throw new MalformedQueryException( String.format("The query refers to a field which does not exist in this index: %1$s", eqCond.getName())); } } if (query.getRangeCondition() != null && definition.getField(query.getRangeCondition().getName()) == null) { throw new MalformedQueryException( String.format("The query refers to a field which does not exist in this index: %1$s", query.getRangeCondition().getName())); } }
/** * Sets the range condition. * * <p>The fromValue and toValue can be: * <ul> * <li>a value of the correct type, corresponding to the index definition * <li>null, which searches from or to null. Thus supplying null does NOT mean * that there is no lower or upper bound on the range. * <li>{@link #MIN_VALUE} or {@link #MAX_VALUE}, which are values that are * smaller or larger than any other value. * </ul> * * @param lowerBoundInclusive true means >= fromValue, false means > fromValue * @param upperBoundInclusive true means <= toValue, false means < toValue */ public void setRangeCondition(String fieldName, Object fromValue, Object toValue, boolean lowerBoundInclusive, boolean upperBoundInclusive) { rangeCondition = new RangeCondition(fieldName, fromValue, toValue, lowerBoundInclusive, upperBoundInclusive); }
/** * Sets the range condition to search on the given field for >= fromValue and * <= toValue. To use exclusive bounds, see the other setRangeCondition method. */ public void setRangeCondition(String fieldName, Object fromValue, Object toValue) { rangeCondition = new RangeCondition(fieldName, fromValue, toValue, true, true); }