// Path: core/src/main/java/org/kududb/client/AbstractionBulldozer.java
// public final class AbstractionBulldozer {
// 
//   private AbstractionBulldozer() {}
// 
//   /**
//    * Set {@link AbstractKuduScannerBuilder#sortResultsByPrimaryKey} on a scanner builder.
//    *
//    * @param builder to set primary key sorting on
//    * @return the builder
//    */
//   public static <S extends AbstractKuduScannerBuilder<S, T>, T> AbstractKuduScannerBuilder<S, T>
//   sortResultsByPrimaryKey(AbstractKuduScannerBuilder<S, T> builder) {
//     builder.sortResultsByPrimaryKey();
//     return builder;
//   }
// }


import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.MoreObjects;
import com.google.common.base.Preconditions;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.google.common.collect.ImmutableList;
import com.google.common.hash.Hashing;
import com.google.common.primitives.Ints;
import com.stumbleupon.async.Callback;
import com.stumbleupon.async.Deferred;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;
import javax.annotation.concurrent.ThreadSafe;
import org.apache.kudu.annotations.InterfaceAudience;
import org.apache.kudu.client.AbstractionBulldozer;
import org.apache.kudu.client.AsyncKuduClient;
import org.apache.kudu.client.AsyncKuduScanner;
import org.apache.kudu.client.AsyncKuduSession;
import org.apache.kudu.client.Insert;
import org.apache.kudu.client.KuduException;
import org.apache.kudu.client.KuduPredicate;
import org.apache.kudu.client.KuduPredicate.ComparisonOp;
import org.apache.kudu.client.KuduTable;
import org.apache.kudu.client.OperationResponse;
import org.apache.kudu.client.RowResult;
import org.apache.kudu.client.RowResultIterator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
    return lookupTagset(tagset, id).addCallbackDeferring(new LookupCB())
                                   .addErrback(new LookupErrback());
  }

  private Deferred<TagsetLookupResult> lookupTagset(SerializedTagset tagset, int id) {
    LOG.debug("Looking up tagset; id: {}, tags: {}", id, tagset);
    AsyncKuduScanner tagsetScanner = tagsetScanner(id);

    return tagsetScanner.nextRows().addCallbackDeferring(
        new TagsetScanCB(tagset, id, tagsetScanner));
  }

  /**
   * Creates an {@link AsyncKuduScanner} over the tagset table beginning with
   * the specified ID.
   *
   * @param id the ID to begin scanning from
   * @return the scanner
   */
  private AsyncKuduScanner tagsetScanner(int id) {
    AsyncKuduScanner.AsyncKuduScannerBuilder scanBuilder = client.newScannerBuilder(tagsetsTable);
    scanBuilder.addPredicate(KuduPredicate.newComparisonPredicate(Tables.TAGSETS_ID_COLUMN,
                                                                  ComparisonOp.GREATER_EQUAL,
                                                                  id));
    if (id < Integer.MAX_VALUE - TAGSETS_PER_SCAN) {
      scanBuilder.addPredicate(KuduPredicate.newComparisonPredicate(Tables.TAGSETS_ID_COLUMN,
                                                                    ComparisonOp.LESS,
                                                                    id + TAGSETS_PER_SCAN));
    }
    scanBuilder.setProjectedColumnIndexes(columnIndexes);
// Path: core/src/main/java/org/kududb/client/AbstractionBulldozer.java
// public final class AbstractionBulldozer {
// 
//   private AbstractionBulldozer() {}
// 
//   /**
//    * Set {@link AbstractKuduScannerBuilder#sortResultsByPrimaryKey} on a scanner builder.
//    *
//    * @param builder to set primary key sorting on
//    * @return the builder
//    */
//   public static <S extends AbstractKuduScannerBuilder<S, T>, T> AbstractKuduScannerBuilder<S, T>
//   sortResultsByPrimaryKey(AbstractKuduScannerBuilder<S, T> builder) {
//     builder.sortResultsByPrimaryKey();
//     return builder;
//   }
// }


// Path: core/src/main/java/org/kududb/ts/core/Tagsets.java
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.MoreObjects;
import com.google.common.base.Preconditions;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.google.common.collect.ImmutableList;
import com.google.common.hash.Hashing;
import com.google.common.primitives.Ints;
import com.stumbleupon.async.Callback;
import com.stumbleupon.async.Deferred;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;
import javax.annotation.concurrent.ThreadSafe;
import org.apache.kudu.annotations.InterfaceAudience;
import org.apache.kudu.client.AbstractionBulldozer;
import org.apache.kudu.client.AsyncKuduClient;
import org.apache.kudu.client.AsyncKuduScanner;
import org.apache.kudu.client.AsyncKuduSession;
import org.apache.kudu.client.Insert;
import org.apache.kudu.client.KuduException;
import org.apache.kudu.client.KuduPredicate;
import org.apache.kudu.client.KuduPredicate.ComparisonOp;
import org.apache.kudu.client.KuduTable;
import org.apache.kudu.client.OperationResponse;
import org.apache.kudu.client.RowResult;
import org.apache.kudu.client.RowResultIterator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

    return lookupTagset(tagset, id).addCallbackDeferring(new LookupCB())
                                   .addErrback(new LookupErrback());
  }

  private Deferred<TagsetLookupResult> lookupTagset(SerializedTagset tagset, int id) {
    LOG.debug("Looking up tagset; id: {}, tags: {}", id, tagset);
    AsyncKuduScanner tagsetScanner = tagsetScanner(id);

    return tagsetScanner.nextRows().addCallbackDeferring(
        new TagsetScanCB(tagset, id, tagsetScanner));
  }

  /**
   * Creates an {@link AsyncKuduScanner} over the tagset table beginning with
   * the specified ID.
   *
   * @param id the ID to begin scanning from
   * @return the scanner
   */
  private AsyncKuduScanner tagsetScanner(int id) {
    AsyncKuduScanner.AsyncKuduScannerBuilder scanBuilder = client.newScannerBuilder(tagsetsTable);
    scanBuilder.addPredicate(KuduPredicate.newComparisonPredicate(Tables.TAGSETS_ID_COLUMN,
                                                                  ComparisonOp.GREATER_EQUAL,
                                                                  id));
    if (id < Integer.MAX_VALUE - TAGSETS_PER_SCAN) {
      scanBuilder.addPredicate(KuduPredicate.newComparisonPredicate(Tables.TAGSETS_ID_COLUMN,
                                                                    ComparisonOp.LESS,
                                                                    id + TAGSETS_PER_SCAN));
    }
    scanBuilder.setProjectedColumnIndexes(columnIndexes);
    AbstractionBulldozer.sortResultsByPrimaryKey(scanBuilder);