/**
   * 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);
  }