Search in sources :

Example 6 with MarshalException

use of org.apache.cassandra.db.marshal.MarshalException in project eiger by wlloyd.

the class ThriftValidation method validateFilterClauses.

// return true if index_clause contains an indexed columns with operator EQ
public static boolean validateFilterClauses(CFMetaData metadata, List<IndexExpression> index_clause) throws InvalidRequestException {
    if (isEmpty(index_clause))
        // no filter to apply
        return false;
    Set<ByteBuffer> indexedColumns = Table.open(metadata.ksName).getColumnFamilyStore(metadata.cfName).indexManager.getIndexedColumns();
    AbstractType nameValidator = ColumnFamily.getComparatorFor(metadata.ksName, metadata.cfName, null);
    boolean isIndexed = false;
    for (IndexExpression expression : index_clause) {
        try {
            nameValidator.validate(expression.column_name);
        } catch (MarshalException me) {
            throw new InvalidRequestException(String.format("[%s]=[%s] failed name validation (%s)", ByteBufferUtil.bytesToHex(expression.column_name), ByteBufferUtil.bytesToHex(expression.value), me.getMessage()));
        }
        AbstractType valueValidator = Schema.instance.getValueValidator(metadata.ksName, metadata.cfName, expression.column_name);
        try {
            valueValidator.validate(expression.value);
        } catch (MarshalException me) {
            throw new InvalidRequestException(String.format("[%s]=[%s] failed value validation (%s)", ByteBufferUtil.bytesToHex(expression.column_name), ByteBufferUtil.bytesToHex(expression.value), me.getMessage()));
        }
        isIndexed |= (expression.op == IndexOperator.EQ) && indexedColumns.contains(expression.column_name);
    }
    return isIndexed;
}
Also used : MarshalException(org.apache.cassandra.db.marshal.MarshalException) AbstractType(org.apache.cassandra.db.marshal.AbstractType) ByteBuffer(java.nio.ByteBuffer)

Aggregations

MarshalException (org.apache.cassandra.db.marshal.MarshalException)6 AbstractType (org.apache.cassandra.db.marshal.AbstractType)4 ByteBuffer (java.nio.ByteBuffer)2 QueryPath (org.apache.cassandra.db.filter.QueryPath)2 ClientContext (org.apache.cassandra.client.ClientContext)1