@SuppressWarnings("unchecked")
  public void bulkLoadStringTuples(IIndexTestContext ctx, int numTuples, Random rnd)
      throws Exception {
    int fieldCount = ctx.getFieldCount();
    int numKeyFields = ctx.getKeyFieldCount();
    String[] fieldValues = new String[fieldCount];
    TreeSet<CheckTuple> tmpCheckTuples = new TreeSet<CheckTuple>();
    for (int i = 0; i < numTuples; i++) {
      // Set keys.
      for (int j = 0; j < numKeyFields; j++) {
        int length = (Math.abs(rnd.nextInt()) % 10) + 1;
        fieldValues[j] = getRandomString(length, rnd);
      }
      // Set values.
      for (int j = numKeyFields; j < fieldCount; j++) {
        fieldValues[j] = getRandomString(5, rnd);
      }
      // Set expected values. We also use these as the pre-sorted stream
      // for bulk loading.
      ctx.insertCheckTuple(
          createStringCheckTuple(fieldValues, ctx.getKeyFieldCount()), tmpCheckTuples);
    }
    bulkLoadCheckTuples(ctx, tmpCheckTuples);

    // Add tmpCheckTuples to ctx check tuples for comparing searches.
    for (CheckTuple checkTuple : tmpCheckTuples) {
      ctx.insertCheckTuple(checkTuple, ctx.getCheckTuples());
    }
  }
  @SuppressWarnings("unchecked")
  public void insertSortedIntTuples(IIndexTestContext ctx, int numTuples, Random rnd)
      throws Exception {
    int fieldCount = ctx.getFieldCount();
    int numKeyFields = ctx.getKeyFieldCount();
    int[] fieldValues = new int[ctx.getFieldCount()];
    int maxValue = (int) Math.ceil(Math.pow(numTuples, 1.0 / (double) numKeyFields));
    Collection<CheckTuple> tmpCheckTuples = createCheckTuplesCollection();
    for (int i = 0; i < numTuples; i++) {
      // Set keys.
      setIntKeyFields(fieldValues, numKeyFields, maxValue, rnd);
      // Set values.
      setIntPayloadFields(fieldValues, numKeyFields, fieldCount);

      // Set expected values. (We also use these as the pre-sorted stream
      // for ordered indexes bulk loading).
      ctx.insertCheckTuple(
          createIntCheckTuple(fieldValues, ctx.getKeyFieldCount()), tmpCheckTuples);
    }
    insertCheckTuples(ctx, tmpCheckTuples);

    // Add tmpCheckTuples to ctx check tuples for comparing searches.
    for (CheckTuple checkTuple : tmpCheckTuples) {
      ctx.insertCheckTuple(checkTuple, ctx.getCheckTuples());
    }
  }
 @SuppressWarnings("unchecked")
 public void insertStringTuples(IIndexTestContext ctx, int numTuples, Random rnd)
     throws Exception {
   int fieldCount = ctx.getFieldCount();
   int numKeyFields = ctx.getKeyFieldCount();
   String[] fieldValues = new String[fieldCount];
   for (int i = 0; i < numTuples; i++) {
     if (LOGGER.isLoggable(Level.INFO)) {
       if ((i + 1) % (numTuples / Math.min(10, numTuples)) == 0) {
         LOGGER.info("Inserting Tuple " + (i + 1) + "/" + numTuples);
       }
     }
     // Set keys.
     for (int j = 0; j < numKeyFields; j++) {
       int length = (Math.abs(rnd.nextInt()) % 10) + 1;
       fieldValues[j] = getRandomString(length, rnd);
     }
     // Set values.
     for (int j = numKeyFields; j < fieldCount; j++) {
       fieldValues[j] = getRandomString(5, rnd);
     }
     TupleUtils.createTuple(
         ctx.getTupleBuilder(), ctx.getTuple(), ctx.getFieldSerdes(), (Object[]) fieldValues);
     try {
       ctx.getIndexAccessor().insert(ctx.getTuple());
       // Set expected values. Do this only after insertion succeeds
       // because we ignore duplicate keys.
       ctx.insertCheckTuple(
           createStringCheckTuple(fieldValues, ctx.getKeyFieldCount()), ctx.getCheckTuples());
     } catch (TreeIndexDuplicateKeyException e) {
       // Ignore duplicate key insertions.
     }
   }
 }