/**
   * Scan the given index query and add the results to the provided set. The set comparator of the
   * dynamic columns are compared via a tree comparator
   *
   * @param query
   * @return
   */
  public ScanBuffer scanIndex(IndexQuery query, Keyspace keyspace) {

    DynamicComposite startScan = newComposite();
    DynamicComposite endScan = newComposite();

    // add the discriminator value so we're querying for the specified class
    // and it's children

    startScan.addComponent(discriminatorValue, stringSerializer);
    endScan.addComponent(discriminatorValue, stringSerializer);

    int length = fields.length;

    int last = length - 1;
    int componentIndex = 1;

    FieldExpression exp = null;

    for (int i = 0; i < last; i++, componentIndex++) {

      exp = query.getExpression(this.fields[i].getMetaData());

      this.fields[i].addToComposite(
          startScan, componentIndex, exp.getStart(), ComponentEquality.EQUAL);
      this.fields[i].addToComposite(endScan, componentIndex, exp.getEnd(), ComponentEquality.EQUAL);
    }

    exp = query.getExpression(this.fields[last].getMetaData());

    this.fields[last].addToComposite(
        startScan, componentIndex, exp.getStart(), exp.getStartEquality());
    this.fields[last].addToComposite(endScan, componentIndex, exp.getEnd(), exp.getEndEquality());

    return new ScanBuffer(keyspace, startScan, endScan, indexName);
  }
Esempio n. 2
0
  /**
   * 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;
  }
Esempio n. 3
0
 public void addExpression(FieldExpression expression) {
   log.debug("adding fieldExpression: {}", expression);
   expressions.put(expression.getField(), expression);
 }