private void checkQueryValueType(IndexFieldDefinition fieldDef, Object value) { if (value != null) { final RowKey rowKey = fieldDef.asRowKey(); if (!rowKey.getDeserializedClass().isAssignableFrom(value.getClass())) { throw new MalformedQueryException("query for field " + fieldDef.getName() + " contains" + " a value of an incorrect type. Expected: " + rowKey.getDeserializedClass() + ", found: " + value.getClass().getName()); } } }
/** * 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())); } }
private Object decodeIndexFieldFrom(String fieldName, byte[] rowKey) throws IOException { final StructRowKey structRowKey = definition.asStructRowKey(); structRowKey.iterateOver(rowKey); final StructIterator iterator = structRowKey.iterator(); int fieldPosition = definition.getFieldPosition(fieldName); if (fieldPosition == -1) { throw new MalformedQueryException("field [" + fieldName + "] is not part of the index"); } // skip all fields up to fieldPosition for (int i = 0; i < fieldPosition; i++) { iterator.skip(); } // return the requested field return iterator.next(); }
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."); throw new MalformedQueryException(message.toString());