// 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.base.MoreObjects;
import com.google.common.collect.ImmutableList;
import com.stumbleupon.async.Callback;
import com.stumbleupon.async.Deferred;
import java.util.List;
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.Insert;
import org.apache.kudu.client.Upsert;
import org.apache.kudu.client.KuduPredicate;
import org.apache.kudu.client.KuduTable;
import org.apache.kudu.client.RowResult;
import org.apache.kudu.client.RowResultIterator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
    Upsert insert = table.newUpsert();
    insert.getRow().addString(Tables.METRICS_METRIC_INDEX, metric);
    insert.getRow().addInt(Tables.METRICS_TAGSET_ID_INDEX, tagsetID);
    insert.getRow().addLong(Tables.METRICS_TIME_INDEX, time);
    insert.getRow().addDouble(Tables.METRICS_VALUE_INDEX, value);
    return insert;
  }

  public Deferred<Datapoints> scanSeries(final String metric,
                                         final int tagsetID,
                                         final long startTime,
                                         final long endTime,
                                         final Aggregator downsampler,
                                         final long downsampleInterval) {
    KuduPredicate metricPred =
        KuduPredicate.newComparisonPredicate(Tables.METRICS_METRIC_COLUMN,
                                             KuduPredicate.ComparisonOp.EQUAL, metric);

    KuduPredicate tagsetIdPred =
        KuduPredicate.newComparisonPredicate(Tables.METRICS_TAGSET_ID_COLUMN,
                                             KuduPredicate.ComparisonOp.EQUAL, tagsetID);

    KuduPredicate startTimestampPred =
        KuduPredicate.newComparisonPredicate(Tables.METRICS_TIME_COLUMN,
                                             KuduPredicate.ComparisonOp.GREATER_EQUAL, startTime);

    KuduPredicate endTimestampPred =
        KuduPredicate.newComparisonPredicate(Tables.METRICS_TIME_COLUMN,
                                             KuduPredicate.ComparisonOp.LESS, endTime);

// 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/Metrics.java
import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableList;
import com.stumbleupon.async.Callback;
import com.stumbleupon.async.Deferred;
import java.util.List;
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.Insert;
import org.apache.kudu.client.Upsert;
import org.apache.kudu.client.KuduPredicate;
import org.apache.kudu.client.KuduTable;
import org.apache.kudu.client.RowResult;
import org.apache.kudu.client.RowResultIterator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

    Upsert insert = table.newUpsert();
    insert.getRow().addString(Tables.METRICS_METRIC_INDEX, metric);
    insert.getRow().addInt(Tables.METRICS_TAGSET_ID_INDEX, tagsetID);
    insert.getRow().addLong(Tables.METRICS_TIME_INDEX, time);
    insert.getRow().addDouble(Tables.METRICS_VALUE_INDEX, value);
    return insert;
  }

  public Deferred<Datapoints> scanSeries(final String metric,
                                         final int tagsetID,
                                         final long startTime,
                                         final long endTime,
                                         final Aggregator downsampler,
                                         final long downsampleInterval) {
    KuduPredicate metricPred =
        KuduPredicate.newComparisonPredicate(Tables.METRICS_METRIC_COLUMN,
                                             KuduPredicate.ComparisonOp.EQUAL, metric);

    KuduPredicate tagsetIdPred =
        KuduPredicate.newComparisonPredicate(Tables.METRICS_TAGSET_ID_COLUMN,
                                             KuduPredicate.ComparisonOp.EQUAL, tagsetID);

    KuduPredicate startTimestampPred =
        KuduPredicate.newComparisonPredicate(Tables.METRICS_TIME_COLUMN,
                                             KuduPredicate.ComparisonOp.GREATER_EQUAL, startTime);

    KuduPredicate endTimestampPred =
        KuduPredicate.newComparisonPredicate(Tables.METRICS_TIME_COLUMN,
                                             KuduPredicate.ComparisonOp.LESS, endTime);

    final AsyncKuduScanner scanner = AbstractionBulldozer.sortResultsByPrimaryKey(