当前位置: 首页>>代码示例>>Java>>正文


Java Sketches.heapifySketch方法代码示例

本文整理汇总了Java中com.yahoo.sketches.tuple.Sketches.heapifySketch方法的典型用法代码示例。如果您正苦于以下问题:Java Sketches.heapifySketch方法的具体用法?Java Sketches.heapifySketch怎么用?Java Sketches.heapifySketch使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.yahoo.sketches.tuple.Sketches的用法示例。


在下文中一共展示了Sketches.heapifySketch方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: partial1ModeIntKeysDefaultParams

import com.yahoo.sketches.tuple.Sketches; //导入方法依赖的package包/类
@Test
public void partial1ModeIntKeysDefaultParams() throws Exception {
  ObjectInspector[] inspectors = new ObjectInspector[] { intInspector, doubleInspector };
  GenericUDAFParameterInfo info = new SimpleGenericUDAFParameterInfo(inspectors, false, false);
  try (GenericUDAFEvaluator eval = new DataToDoubleSummarySketchUDAF().getEvaluator(info)) {
    ObjectInspector resultInspector = eval.init(Mode.PARTIAL1, inspectors);
    checkIntermediateResultInspector(resultInspector);
  
    @SuppressWarnings("unchecked")
    State<DoubleSummary> state = (State<DoubleSummary>) eval.getNewAggregationBuffer();
    eval.iterate(state, new Object[] {new IntWritable(1), new DoubleWritable(1)});
    eval.iterate(state, new Object[] {new IntWritable(2), new DoubleWritable(1)});
  
    Object result = eval.terminatePartial(state);
    Assert.assertNotNull(result);
    Assert.assertTrue(result instanceof List);
    List<?> r = (List<?>) result;
    Assert.assertEquals(r.size(), 2);
    Assert.assertEquals(((IntWritable) r.get(0)).get(), DEFAULT_NOMINAL_ENTRIES);
    Sketch<DoubleSummary> resultSketch = Sketches.heapifySketch(Memory.wrap(((BytesWritable) r.get(1)).getBytes()));
    Assert.assertFalse(resultSketch.isEstimationMode());
    Assert.assertEquals(resultSketch.getEstimate(), 2.0);
  }
}
 
开发者ID:DataSketches,项目名称:sketches-hive,代码行数:25,代码来源:DataToDoubleSummarySketchUDAFTest.java

示例2: algebraicIntermediateFinalMaxMode

import com.yahoo.sketches.tuple.Sketches; //导入方法依赖的package包/类
@Test
public void algebraicIntermediateFinalMaxMode() throws Exception {
  EvalFunc<Tuple> func = new DataToDoubleSummarySketch.IntermediateFinal("32", "Max");
  Tuple inputTuple = TupleFactory.getInstance().newTuple(1);
  DataBag bag = BagFactory.getInstance().newDefaultBag();
  inputTuple.set(0, bag);

  // this is to simulate the output from Initial
  bag.add(PigUtil.objectsToTuple(PigUtil.tuplesToBag(PigUtil.objectsToTuple("a", 1.0))));
  bag.add(PigUtil.objectsToTuple(PigUtil.tuplesToBag(PigUtil.objectsToTuple("b", 1.0))));
  bag.add(PigUtil.objectsToTuple(PigUtil.tuplesToBag(PigUtil.objectsToTuple("a", 2.0))));
  bag.add(PigUtil.objectsToTuple(PigUtil.tuplesToBag(PigUtil.objectsToTuple("b", 2.0))));

  Tuple resultTuple = func.exec(inputTuple);
  Assert.assertNotNull(resultTuple);
  Assert.assertEquals(resultTuple.size(), 1);
  DataByteArray bytes = (DataByteArray) resultTuple.get(0);
  Assert.assertTrue(bytes.size() > 0);
  Sketch<DoubleSummary> sketch = Sketches.heapifySketch(Memory.wrap(bytes.get()));
  Assert.assertEquals(sketch.getEstimate(), 2.0, 0.0);

  for (DoubleSummary summary: sketch.getSummaries()) {
    Assert.assertEquals(summary.getValue(), 2.0);
  }
}
 
开发者ID:DataSketches,项目名称:sketches-pig,代码行数:26,代码来源:DataToDoubleSummarySketchTest.java

示例3: completeModeIntKeysDefaultParams

import com.yahoo.sketches.tuple.Sketches; //导入方法依赖的package包/类
@Test
public void completeModeIntKeysDefaultParams() throws Exception {
  ObjectInspector[] inspectors = new ObjectInspector[] { intInspector, doubleInspector };
  GenericUDAFParameterInfo info = new SimpleGenericUDAFParameterInfo(inspectors, false, false);
  try (GenericUDAFEvaluator eval = new DataToDoubleSummarySketchUDAF().getEvaluator(info)) {
    ObjectInspector resultInspector = eval.init(Mode.COMPLETE, inspectors);
    checkFinalResultInspector(resultInspector);

    @SuppressWarnings("unchecked")
    State<DoubleSummary> state = (State<DoubleSummary>) eval.getNewAggregationBuffer();
    eval.iterate(state, new Object[] {new IntWritable(1), new DoubleWritable(1)});
    eval.iterate(state, new Object[] {new IntWritable(2), new DoubleWritable(1)});

    Object result = eval.terminate(state);
    Assert.assertNotNull(result);
    Assert.assertTrue(result instanceof BytesWritable);
    Sketch<DoubleSummary> resultSketch = Sketches.heapifySketch(Memory.wrap(((BytesWritable) result).getBytes()));
    Assert.assertEquals(resultSketch.getEstimate(), 2.0);

    eval.reset(state);
    result = eval.terminate(state);
    Assert.assertNull(result);
  }
}
 
开发者ID:DataSketches,项目名称:sketches-hive,代码行数:25,代码来源:DataToDoubleSummarySketchUDAFTest.java

示例4: exec

import com.yahoo.sketches.tuple.Sketches; //导入方法依赖的package包/类
@Override
public Tuple exec(final Tuple input) throws IOException {
  if ((input == null) || (input.size() == 0)) {
    return null;
  }

  final DataByteArray dba = (DataByteArray) input.get(0);
  final Sketch<DoubleSummary> sketch = Sketches.heapifySketch(Memory.wrap(dba.get()));

  final Tuple output = TupleFactory.getInstance().newTuple(2);
  output.set(0, sketch.getEstimate());
  double sum = 0;
  final SketchIterator<DoubleSummary> it = sketch.iterator();
  while (it.next()) {
    sum += it.getSummary().getValue();
  }
  output.set(1, sum / sketch.getTheta());

  return output;
}
 
开发者ID:DataSketches,项目名称:sketches-pig,代码行数:21,代码来源:DoubleSummarySketchToEstimates.java

示例5: exec

import com.yahoo.sketches.tuple.Sketches; //导入方法依赖的package包/类
@Override
public Double exec(final Tuple input) throws IOException {
  if (input.size() != 2) {
    throw new IllegalArgumentException("expected two inputs: sketch and pecentile");
  }

  final DataByteArray dba = (DataByteArray) input.get(0);
  final Sketch<DoubleSummary> sketch = Sketches.heapifySketch(Memory.wrap(dba.get()));

  final double percentile = (double) input.get(1);
  if ((percentile < 0) || (percentile > 100)) {
    throw new IllegalArgumentException("percentile must be between 0 and 100");
  }

  final UpdateDoublesSketch qs = DoublesSketch.builder().setK(QUANTILES_SKETCH_SIZE).build();
  final SketchIterator<DoubleSummary> it = sketch.iterator();
  while (it.next()) {
    qs.update(it.getSummary().getValue());
  }
  return qs.getQuantile(percentile / 100);
}
 
开发者ID:DataSketches,项目名称:sketches-pig,代码行数:22,代码来源:DoubleSummarySketchToPercentile.java

示例6: evaluate

import com.yahoo.sketches.tuple.Sketches; //导入方法依赖的package包/类
/**
 * Get percentile from a given Sketch&lt;DoubleSummary&gt;
 * @param serializedSketch DoubleSummarySketch in as serialized binary
 * @param percentile normalized rank in percent
 * @return percentile value
 */
public Double evaluate(final BytesWritable serializedSketch, final double percentile) {
  if (serializedSketch == null) { return null; }
  if ((percentile < 0) || (percentile > 100)) {
    throw new IllegalArgumentException("percentile must be between 0 and 100");
  }
  final Sketch<DoubleSummary> sketch =
      Sketches.heapifySketch(Memory.wrap(serializedSketch.getBytes()));
  final UpdateDoublesSketch qs = DoublesSketch.builder().setK(QUANTILES_SKETCH_SIZE).build();
  final SketchIterator<DoubleSummary> it = sketch.iterator();
  while (it.next()) {
    qs.update(it.getSummary().getValue());
  }
  return qs.getQuantile(percentile / 100);
}
 
开发者ID:DataSketches,项目名称:sketches-hive,代码行数:21,代码来源:DoubleSummarySketchToPercentileUDF.java

示例7: finalMode

import com.yahoo.sketches.tuple.Sketches; //导入方法依赖的package包/类
@Test
public void finalMode() throws Exception {
  ObjectInspector[] inspectors = new ObjectInspector[] { binaryInspector };
  GenericUDAFParameterInfo info = new SimpleGenericUDAFParameterInfo(inspectors, false, false);
  try (GenericUDAFEvaluator eval = new UnionDoubleSummarySketchUDAF().getEvaluator(info)) {
    ObjectInspector resultInspector = eval.init(Mode.FINAL, new ObjectInspector[] {structInspector});
    DataToDoubleSummarySketchUDAFTest.checkFinalResultInspector(resultInspector);

    @SuppressWarnings("unchecked")
    State<DoubleSummary> state = (State<DoubleSummary>) eval.getNewAggregationBuffer();

    UpdatableSketch<Double, DoubleSummary> sketch1 = new UpdatableSketchBuilder<Double, DoubleSummary>(new DoubleSummaryFactory()).build();
    sketch1.update(1, 1.0);
    eval.merge(state, Arrays.asList(
      new IntWritable(DEFAULT_NOMINAL_ENTRIES),
      new BytesWritable(sketch1.compact().toByteArray()))
    );

    UpdatableSketch<Double, DoubleSummary> sketch2 = new UpdatableSketchBuilder<Double, DoubleSummary>(new DoubleSummaryFactory()).build();
    sketch2.update(2, 1.0);
    eval.merge(state, Arrays.asList(
      new IntWritable(DEFAULT_NOMINAL_ENTRIES),
      new BytesWritable(sketch2.compact().toByteArray()))
    );

    Object result = eval.terminate(state);
    Assert.assertNotNull(result);
    Assert.assertTrue(result instanceof BytesWritable);
    Sketch<DoubleSummary> resultSketch = Sketches.heapifySketch(Memory.wrap(((BytesWritable) result).getBytes()));
    Assert.assertEquals(resultSketch.getEstimate(), 2.0);
  }
}
 
开发者ID:DataSketches,项目名称:sketches-hive,代码行数:33,代码来源:UnionDoubleSummarySketchUDAFTest.java

示例8: finalMode

import com.yahoo.sketches.tuple.Sketches; //导入方法依赖的package包/类
@Test
public void finalMode() throws Exception {
  ObjectInspector[] inspectors = new ObjectInspector[] { intInspector, doubleInspector };
  GenericUDAFParameterInfo info = new SimpleGenericUDAFParameterInfo(inspectors, false, false);
  try (GenericUDAFEvaluator eval = new DataToDoubleSummarySketchUDAF().getEvaluator(info)) {
    ObjectInspector resultInspector = eval.init(Mode.FINAL, new ObjectInspector[] {structInspector});
    checkFinalResultInspector(resultInspector);

    @SuppressWarnings("unchecked")
    State<DoubleSummary> state = (State<DoubleSummary>) eval.getNewAggregationBuffer();

    UpdatableSketch<Double, DoubleSummary> sketch1 = new UpdatableSketchBuilder<Double, DoubleSummary>(new DoubleSummaryFactory()).build();
    sketch1.update(1, 1.0);
    eval.merge(state, Arrays.asList(
      new IntWritable(DEFAULT_NOMINAL_ENTRIES),
      new BytesWritable(sketch1.compact().toByteArray()))
    );

    UpdatableSketch<Double, DoubleSummary> sketch2 = new UpdatableSketchBuilder<Double, DoubleSummary>(new DoubleSummaryFactory()).build();
    sketch2.update(2, 1.0);
    eval.merge(state, Arrays.asList(
      new IntWritable(DEFAULT_NOMINAL_ENTRIES),
      new BytesWritable(sketch2.compact().toByteArray()))
    );

    Object result = eval.terminate(state);
    Assert.assertNotNull(result);
    Assert.assertTrue(result instanceof BytesWritable);
    Sketch<DoubleSummary> resultSketch = Sketches.heapifySketch(Memory.wrap(((BytesWritable) result).getBytes()));
    Assert.assertEquals(resultSketch.getEstimate(), 2.0);
  }
}
 
开发者ID:DataSketches,项目名称:sketches-hive,代码行数:33,代码来源:DataToDoubleSummarySketchUDAFTest.java

示例9: accumulatorNullInput

import com.yahoo.sketches.tuple.Sketches; //导入方法依赖的package包/类
@Test
public void accumulatorNullInput() throws Exception {
  Accumulator<Tuple> func = new UnionDoubleSummarySketch("32");
  func.accumulate(null);
  Tuple resultTuple = func.getValue();
  Assert.assertNotNull(resultTuple);
  Assert.assertEquals(resultTuple.size(), 1);
  DataByteArray bytes = (DataByteArray) resultTuple.get(0);
  Assert.assertTrue(bytes.size() > 0);
  Sketch<DoubleSummary> sketch = Sketches.heapifySketch(Memory.wrap(bytes.get()));
  Assert.assertEquals(sketch.getEstimate(), 0.0);
}
 
开发者ID:DataSketches,项目名称:sketches-pig,代码行数:13,代码来源:UnionDoubleSummarySketchTest.java

示例10: partial1ModeIntKeysDefaultParams

import com.yahoo.sketches.tuple.Sketches; //导入方法依赖的package包/类
@Test
public void partial1ModeIntKeysDefaultParams() throws Exception {
  ObjectInspector[] inspectors = new ObjectInspector[] { intInspector, doubleInspector };
  GenericUDAFParameterInfo info = new SimpleGenericUDAFParameterInfo(inspectors, false, false);
  try (GenericUDAFEvaluator eval = new DataToDoubleSummaryWithModeSketchUDAF().getEvaluator(info)) {
    ObjectInspector resultInspector = eval.init(Mode.PARTIAL1, inspectors);
    checkIntermediateResultInspector(resultInspector);

    @SuppressWarnings("unchecked")
    State<DoubleSummary> state = (State<DoubleSummary>) eval.getNewAggregationBuffer();
    eval.iterate(state, new Object[] {new IntWritable(1), new DoubleWritable(1)});
    eval.iterate(state, new Object[] {new IntWritable(2), new DoubleWritable(2)});
    eval.iterate(state, new Object[] {new IntWritable(1), new DoubleWritable(2)});
    eval.iterate(state, new Object[] {new IntWritable(2), new DoubleWritable(1)});

    Object result = eval.terminatePartial(state);
    Assert.assertNotNull(result);
    Assert.assertTrue(result instanceof List);
    List<?> r = (List<?>) result;
    Assert.assertEquals(r.size(), 3);
    Assert.assertEquals(((IntWritable) r.get(0)).get(), DEFAULT_NOMINAL_ENTRIES);
    Assert.assertEquals(((Text) r.get(1)).toString(), DoubleSummary.Mode.Sum.toString());
    Sketch<DoubleSummary> resultSketch = Sketches.heapifySketch(Memory.wrap(((BytesWritable) r.get(2)).getBytes()));
    Assert.assertFalse(resultSketch.isEstimationMode());
    Assert.assertEquals(resultSketch.getEstimate(), 2.0);
    SketchIterator<DoubleSummary> it = resultSketch.iterator();
    while (it.next()) {
      Assert.assertEquals(it.getSummary().getValue(), 3.0);
    }
  }
}
 
开发者ID:DataSketches,项目名称:sketches-hive,代码行数:32,代码来源:DataToDoubleSummaryWithModeSketchUDAFTest.java

示例11: partial1ModeStringKeysExplicitParams

import com.yahoo.sketches.tuple.Sketches; //导入方法依赖的package包/类
@Test
public void partial1ModeStringKeysExplicitParams() throws Exception {
  ObjectInspector[] inspectors = new ObjectInspector[] { stringInspector, doubleInspector, intInspector, floatInspector, stringInspector };
  GenericUDAFParameterInfo info = new SimpleGenericUDAFParameterInfo(inspectors, false, false);
  try (GenericUDAFEvaluator eval = new DataToDoubleSummaryWithModeSketchUDAF().getEvaluator(info)) {
    ObjectInspector resultInspector = eval.init(Mode.PARTIAL1, inspectors);
    checkIntermediateResultInspector(resultInspector);

    @SuppressWarnings("unchecked")
    State<DoubleSummary> state = (State<DoubleSummary>) eval.getNewAggregationBuffer();
    eval.iterate(state, new Object[] {new Text("a"), new DoubleWritable(1), new IntWritable(32), new FloatWritable(0.99f), new Text("Min")});
    eval.iterate(state, new Object[] {new Text("b"), new DoubleWritable(2), new IntWritable(32), new FloatWritable(0.99f), new Text("Min")});
    eval.iterate(state, new Object[] {new Text("a"), new DoubleWritable(2), new IntWritable(32), new FloatWritable(0.99f), new Text("Min")});
    eval.iterate(state, new Object[] {new Text("b"), new DoubleWritable(1), new IntWritable(32), new FloatWritable(0.99f), new Text("Min")});

    Object result = eval.terminatePartial(state);
    Assert.assertNotNull(result);
    Assert.assertTrue(result instanceof List);
    List<?> r = (List<?>) result;
    Assert.assertEquals(r.size(), 3);
    Assert.assertEquals(((IntWritable) r.get(0)).get(), 32);
    Assert.assertEquals(((Text) r.get(1)).toString(), DoubleSummary.Mode.Min.toString());
    Sketch<DoubleSummary> resultSketch = Sketches.heapifySketch(Memory.wrap(((BytesWritable) r.get(2)).getBytes()));
    // because of sampling probability < 1
    Assert.assertTrue(resultSketch.isEstimationMode());
    Assert.assertEquals(resultSketch.getEstimate(), 2.0, 0.05);
    SketchIterator<DoubleSummary> it = resultSketch.iterator();
    while (it.next()) {
      Assert.assertEquals(it.getSummary().getValue(), 1.0);
    }
  }
}
 
开发者ID:DataSketches,项目名称:sketches-hive,代码行数:33,代码来源:DataToDoubleSummaryWithModeSketchUDAFTest.java

示例12: partial2Mode

import com.yahoo.sketches.tuple.Sketches; //导入方法依赖的package包/类
@Test
public void partial2Mode() throws Exception {
  ObjectInspector[] inspectors = new ObjectInspector[] { binaryInspector };
  GenericUDAFParameterInfo info = new SimpleGenericUDAFParameterInfo(inspectors, false, false);
  try (GenericUDAFEvaluator eval = new UnionDoubleSummarySketchUDAF().getEvaluator(info)) {
    ObjectInspector resultInspector = eval.init(Mode.PARTIAL2, new ObjectInspector[] {structInspector});
    DataToDoubleSummarySketchUDAFTest.checkIntermediateResultInspector(resultInspector);

    @SuppressWarnings("unchecked")
    State<DoubleSummary> state = (State<DoubleSummary>) eval.getNewAggregationBuffer();

    UpdatableSketch<Double, DoubleSummary> sketch1 = new UpdatableSketchBuilder<Double, DoubleSummary>(new DoubleSummaryFactory()).build();
    sketch1.update(1, 1.0);
    eval.merge(state, Arrays.asList(
      new IntWritable(DEFAULT_NOMINAL_ENTRIES),
      new BytesWritable(sketch1.compact().toByteArray()))
    );

    UpdatableSketch<Double, DoubleSummary> sketch2 = new UpdatableSketchBuilder<Double, DoubleSummary>(new DoubleSummaryFactory()).build();
    sketch2.update(2, 1.0);
    eval.merge(state, Arrays.asList(
      new IntWritable(DEFAULT_NOMINAL_ENTRIES),
      new BytesWritable(sketch2.compact().toByteArray()))
    );

    Object result = eval.terminatePartial(state);
    Assert.assertNotNull(result);
    Assert.assertTrue(result instanceof List);
    List<?> r = (List<?>) result;
    Assert.assertEquals(r.size(), 2);
    Assert.assertEquals(((IntWritable) (r.get(0))).get(), DEFAULT_NOMINAL_ENTRIES);
    Sketch<DoubleSummary> resultSketch = Sketches.heapifySketch(Memory.wrap(((BytesWritable) (r.get(1))).getBytes()));
    Assert.assertEquals(resultSketch.getEstimate(), 2.0);

    eval.reset(state);
    result = eval.terminate(state);
    Assert.assertNull(result);
  }
}
 
开发者ID:DataSketches,项目名称:sketches-hive,代码行数:40,代码来源:UnionDoubleSummarySketchUDAFTest.java

示例13: accumulatorEmptyInputTuple

import com.yahoo.sketches.tuple.Sketches; //导入方法依赖的package包/类
@Test
public void accumulatorEmptyInputTuple() throws Exception {
  Accumulator<Tuple> func = new UnionDoubleSummarySketch("32");
  func.accumulate(TupleFactory.getInstance().newTuple());
  Tuple resultTuple = func.getValue();
  Assert.assertNotNull(resultTuple);
  Assert.assertEquals(resultTuple.size(), 1);
  DataByteArray bytes = (DataByteArray) resultTuple.get(0);
  Assert.assertTrue(bytes.size() > 0);
  Sketch<DoubleSummary> sketch = Sketches.heapifySketch(Memory.wrap(bytes.get()));
  Assert.assertEquals(sketch.getEstimate(), 0.0);
}
 
开发者ID:DataSketches,项目名称:sketches-pig,代码行数:13,代码来源:UnionDoubleSummarySketchTest.java

示例14: accumulatorEmptyBag

import com.yahoo.sketches.tuple.Sketches; //导入方法依赖的package包/类
@Test
public void accumulatorEmptyBag() throws Exception {
  Accumulator<Tuple> func = new UnionDoubleSummarySketch("32");
  func.accumulate(PigUtil.objectsToTuple(BagFactory.getInstance().newDefaultBag()));
  Tuple resultTuple = func.getValue();
  Assert.assertNotNull(resultTuple);
  Assert.assertEquals(resultTuple.size(), 1);
  DataByteArray bytes = (DataByteArray) resultTuple.get(0);
  Assert.assertTrue(bytes.size() > 0);
  Sketch<DoubleSummary> sketch = Sketches.heapifySketch(Memory.wrap(bytes.get()));
  Assert.assertEquals(sketch.getEstimate(), 0.0);
}
 
开发者ID:DataSketches,项目名称:sketches-pig,代码行数:13,代码来源:UnionDoubleSummarySketchTest.java

示例15: finalMode

import com.yahoo.sketches.tuple.Sketches; //导入方法依赖的package包/类
@Test
public void finalMode() throws Exception {
  ObjectInspector[] inspectors = new ObjectInspector[] { binaryInspector };
  GenericUDAFParameterInfo info = new SimpleGenericUDAFParameterInfo(inspectors, false, false);
  try (GenericUDAFEvaluator eval = new UnionDoubleSummaryWithModeSketchUDAF().getEvaluator(info)) {
    ObjectInspector resultInspector = eval.init(Mode.FINAL, new ObjectInspector[] {structInspector});
    DataToDoubleSummarySketchUDAFTest.checkFinalResultInspector(resultInspector);

    @SuppressWarnings("unchecked")
    State<DoubleSummary> state = (State<DoubleSummary>) eval.getNewAggregationBuffer();

    UpdatableSketch<Double, DoubleSummary> sketch1 = new UpdatableSketchBuilder<Double, DoubleSummary>(new DoubleSummaryFactory()).build();
    sketch1.update(1, 1.0);
    sketch1.update(2, 2.0);
    eval.merge(state, Arrays.asList(
      new IntWritable(DEFAULT_NOMINAL_ENTRIES),
      new Text("Min"),
      new BytesWritable(sketch1.compact().toByteArray()))
    );

    UpdatableSketch<Double, DoubleSummary> sketch2 = new UpdatableSketchBuilder<Double, DoubleSummary>(new DoubleSummaryFactory()).build();
    sketch2.update(1, 2.0);
    sketch2.update(2, 1.0);
    eval.merge(state, Arrays.asList(
      new IntWritable(DEFAULT_NOMINAL_ENTRIES),
      new Text("Min"),
      new BytesWritable(sketch2.compact().toByteArray()))
    );

    Object result = eval.terminate(state);
    Assert.assertNotNull(result);
    Assert.assertTrue(result instanceof BytesWritable);
    Sketch<DoubleSummary> resultSketch = Sketches.heapifySketch(Memory.wrap(((BytesWritable) result).getBytes()));
    Assert.assertEquals(resultSketch.getEstimate(), 2.0);
    SketchIterator<DoubleSummary> it = resultSketch.iterator();
    while (it.next()) {
      Assert.assertEquals(it.getSummary().getValue(), 1.0);
    }
  }
}
 
开发者ID:DataSketches,项目名称:sketches-hive,代码行数:41,代码来源:UnionDoubleSummaryWithModeSketchUDAFTest.java


注:本文中的com.yahoo.sketches.tuple.Sketches.heapifySketch方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。