/**
   * Get the index for the query
   *
   * @param query
   * @return
   */
  private AbstractIndexOperation getIndexOp(
      IndexQuery query,
      Value[] ordering,
      boolean[] orderAscending,
      CassandraClassMetaData metaData) {

    Collection<FieldExpression> expFields = query.getExpressions();

    FieldOrder[] fields = new FieldOrder[expFields.size()];

    IndexOrder[] orders = new IndexOrder[ordering.length];

    Iterator<FieldExpression> expFieldsItr = expFields.iterator();

    // all fields are ascending by default in field equality.
    for (int i = 0; i < fields.length; i++) {
      FieldExpression current = expFieldsItr.next();

      // if there's not start but an end then this column must be
      // descending in
      // the index

      fields[i] = new FieldOrder(current.getField().getName(), true);
      log.debug("in getIndexOp with field: {}", fields[i]);
    }

    for (int i = 0; i < orders.length; i++) {
      orders[i] = new IndexOrder(((Path) ordering[i]).last().getName(), orderAscending[i]);
    }

    EntityFacade classMeta = conf.getMetaCache().getFacade(metaData, conf.getSerializer());

    AbstractIndexOperation indexOp = classMeta.getIndexOperation(fields, orders);

    if (indexOp == null) {
      throw new UnsupportedException(
          String.format(
              "You attempted to query an index that does not exist.  To perform this query you must define an index in the following format.  '%s'",
              getIndexExpression(fields, orders)));
    }

    return indexOp;
  }
Exemple #2
0
 public void addExpression(FieldExpression expression) {
   log.debug("adding fieldExpression: {}", expression);
   expressions.put(expression.getField(), expression);
 }