class ModelKeyParser {

    public static FieldMapping parseKey(Key key, Set<Authorizations> auths) {
        FieldMapping mapping = new FieldMapping();
        String row = key.getRow().toString();
        String[] colf = key.getColumnFamily().toString().split(NULL_BYTE);
        String[] colq = key.getColumnQualifier().toString().split(NULL_BYTE);
        String cv = key.getColumnVisibility().toString();
        
        String datatype = null;
        Direction direction;
        String dataField;
        String modelField;
        Boolean indexOnlyField = false;
        
        if (colf.length == 1) {
            // Older style, no datatype
        } else if (colf.length == 2) {
            datatype = colf[1];
        } else {
            throw new IllegalArgumentException("Key in unknown format, colf parts: " + colf.length);
        }
        if (2 == colq.length) {
            direction = Direction.getDirection(colq[1]);
            if (Direction.REVERSE.equals(direction)) {
                dataField = row;
                modelField = colq[0];
            } else {
                dataField = colq[0];
                modelField = row;
            }
        } else if (3 == colq.length && Direction.FORWARD == Direction.getDirection(colq[2])) {
            dataField = colq[0];
            modelField = row;
            direction = Direction.FORWARD; // we already checked it in the if condition
        } else {
            log.error("Error parsing key: " + key);
            throw new IllegalArgumentException("Key in unknown format, colq parts: " + colq.length);
        }
        
        mapping.setColumnVisibility(cv);
        mapping.setDatatype(datatype);
        mapping.setDirection(direction);
        mapping.setFieldName(dataField);
        mapping.setModelFieldName(modelField);
        return mapping;
    }

}