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


Java UpdatableSketchBuilder类代码示例

本文整理汇总了Java中com.yahoo.sketches.tuple.UpdatableSketchBuilder的典型用法代码示例。如果您正苦于以下问题:Java UpdatableSketchBuilder类的具体用法?Java UpdatableSketchBuilder怎么用?Java UpdatableSketchBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: TupleSketch

import com.yahoo.sketches.tuple.UpdatableSketchBuilder; //导入依赖的package包/类
/**
 * Initialize a tuple sketch for summarizing group data.
 *
 * @param resizeFactor The {@link ResizeFactor} to use for the sketch.
 * @param samplingProbability The sampling probability to use.
 * @param nominalEntries The nominal entries for the sketch.
 * @param maxSize The maximum size of groups to return.
 */
@SuppressWarnings("unchecked")
public TupleSketch(ResizeFactor resizeFactor, float samplingProbability, int nominalEntries, int maxSize) {
    GroupDataSummaryFactory factory = new GroupDataSummaryFactory();
    UpdatableSketchBuilder<CachingGroupData, GroupDataSummary> builder = new UpdatableSketchBuilder(factory);

    updateSketch = builder.setResizeFactor(resizeFactor).setNominalEntries(nominalEntries)
                          .setSamplingProbability(samplingProbability).build();
    unionSketch = new Union<>(nominalEntries, factory);

    this.maxSize = maxSize;
}
 
开发者ID:yahoo,项目名称:bullet-core,代码行数:20,代码来源:TupleSketch.java

示例2: partial2Mode

import com.yahoo.sketches.tuple.UpdatableSketchBuilder; //导入依赖的package包/类
@Test
public void partial2Mode() 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.PARTIAL2, new ObjectInspector[] {structInspector});
    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,代码来源:DataToDoubleSummarySketchUDAFTest.java

示例3: finalMode

import com.yahoo.sketches.tuple.UpdatableSketchBuilder; //导入依赖的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

示例4: emptySketch

import com.yahoo.sketches.tuple.UpdatableSketchBuilder; //导入依赖的package包/类
@Test
public void emptySketch() {
  UpdatableSketch<Double, DoubleSummary> sketch = new UpdatableSketchBuilder<Double, DoubleSummary>(new DoubleSummaryFactory()).build();
  Double result = new DoubleSummarySketchToPercentileUDF().evaluate(new BytesWritable(sketch.compact().toByteArray()), 0.0);
  Assert.assertNotNull(result);
  Assert.assertEquals(result, Double.POSITIVE_INFINITY);
}
 
开发者ID:DataSketches,项目名称:sketches-hive,代码行数:8,代码来源:DoubleSummarySketchToPercentileUDFTest.java

示例5: normalCase

import com.yahoo.sketches.tuple.UpdatableSketchBuilder; //导入依赖的package包/类
@Test
public void normalCase() {
  UpdatableSketch<Double, DoubleSummary> sketch = new UpdatableSketchBuilder<Double, DoubleSummary>(new DoubleSummaryFactory()).build();
  int iterations = 100000;
  for (int i = 0; i < iterations; i++) sketch.update(i, (double) i);
  for (int i = 0; i < iterations; i++) sketch.update(i, (double) i);
  Double result = new DoubleSummarySketchToPercentileUDF().evaluate(new BytesWritable(sketch.compact().toByteArray()), 50.0);
  Assert.assertNotNull(result);
  Assert.assertEquals(result, iterations, iterations * 0.02);
}
 
开发者ID:DataSketches,项目名称:sketches-hive,代码行数:11,代码来源:DoubleSummarySketchToPercentileUDFTest.java

示例6: emptySketch

import com.yahoo.sketches.tuple.UpdatableSketchBuilder; //导入依赖的package包/类
@Test
public void emptySketch() {
  UpdatableSketch<Double, DoubleSummary> sketch = new UpdatableSketchBuilder<Double, DoubleSummary>(new DoubleSummaryFactory()).build();
  List<Double> result = new DoubleSummarySketchToEstimatesUDF().evaluate(new BytesWritable(sketch.compact().toByteArray()));
  Assert.assertNotNull(result);
  Assert.assertEquals(result.size(), 2);
  Assert.assertEquals(result.get(0), 0.0);
  Assert.assertEquals(result.get(1), 0.0);
}
 
开发者ID:DataSketches,项目名称:sketches-hive,代码行数:10,代码来源:DoubleSummarySketchToEstimatesUDFTest.java

示例7: normalCase

import com.yahoo.sketches.tuple.UpdatableSketchBuilder; //导入依赖的package包/类
@Test
public void normalCase() {
  UpdatableSketch<Double, DoubleSummary> sketch = new UpdatableSketchBuilder<Double, DoubleSummary>(new DoubleSummaryFactory()).build();
  sketch.update(1, 1.0);
  sketch.update(2, 1.0);
  List<Double> result = new DoubleSummarySketchToEstimatesUDF().evaluate(new BytesWritable(sketch.compact().toByteArray()));
  Assert.assertNotNull(result);
  Assert.assertEquals(result.size(), 2);
  Assert.assertEquals(result.get(0), 2.0);
  Assert.assertEquals(result.get(1), 2.0);
}
 
开发者ID:DataSketches,项目名称:sketches-hive,代码行数:12,代码来源:DoubleSummarySketchToEstimatesUDFTest.java

示例8: finalMode

import com.yahoo.sketches.tuple.UpdatableSketchBuilder; //导入依赖的package包/类
@Test
public void finalMode() 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.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);
    sketch1.update(2, 2.0);
    eval.merge(state, Arrays.asList(
      new IntWritable(DEFAULT_NOMINAL_ENTRIES),
      new Text("Sum"),
      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("Sum"),
      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(), 3.0);
    }
  }
}
 
开发者ID:DataSketches,项目名称:sketches-hive,代码行数:41,代码来源:DataToDoubleSummaryWithModeSketchUDAFTest.java

示例9: partial1ModeDefaultParams

import com.yahoo.sketches.tuple.UpdatableSketchBuilder; //导入依赖的package包/类
@Test
public void partial1ModeDefaultParams() 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.PARTIAL1, inspectors);
    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);
    sketch1.update(2, 2.0);
    eval.iterate(state, new Object[] {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.iterate(state, new Object[] {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(), 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.assertEquals(resultSketch.getEstimate(), 2.0);
    SketchIterator<DoubleSummary> it = resultSketch.iterator();
    while (it.next()) {
      Assert.assertEquals(it.getSummary().getValue(), 3.0);
    }
  }
}
 
开发者ID:DataSketches,项目名称:sketches-hive,代码行数:37,代码来源:UnionDoubleSummaryWithModeSketchUDAFTest.java

示例10: finalMode

import com.yahoo.sketches.tuple.UpdatableSketchBuilder; //导入依赖的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

示例11: completeModeDefaultParams

import com.yahoo.sketches.tuple.UpdatableSketchBuilder; //导入依赖的package包/类
@Test
public void completeModeDefaultParams() 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.COMPLETE, inspectors);
    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.iterate(state, new Object[] {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.iterate(state, new Object[] {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(), 3.0);
    }

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

示例12: partial1ModeDefaultParams

import com.yahoo.sketches.tuple.UpdatableSketchBuilder; //导入依赖的package包/类
@Test
public void partial1ModeDefaultParams() 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.PARTIAL1, inspectors);
    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.iterate(state, new Object[] {new BytesWritable(sketch1.compact().toByteArray())});

    UpdatableSketch<Double, DoubleSummary> sketch2 = new UpdatableSketchBuilder<Double, DoubleSummary>(new DoubleSummaryFactory()).build();
    sketch2.update(2, 1.0);
    eval.iterate(state, new Object[] {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);
  }
}
 
开发者ID:DataSketches,项目名称:sketches-hive,代码行数:30,代码来源:UnionDoubleSummarySketchUDAFTest.java

示例13: partial1ModeExplicitParams

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

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

    UpdatableSketch<Double, DoubleSummary> sketch1 =
        new UpdatableSketchBuilder<Double, DoubleSummary>(new DoubleSummaryFactory()).setNominalEntries(nomNumEntries).build();
    sketch1.update(1, 1.0);
    eval.iterate(state, new Object[] {new BytesWritable(sketch1.compact().toByteArray()),
        new IntWritable(nomNumEntries)});

    UpdatableSketch<Double, DoubleSummary> sketch2 =
        new UpdatableSketchBuilder<Double, DoubleSummary>(new DoubleSummaryFactory()).setNominalEntries(nomNumEntries).build();
    sketch2.update(2, 1.0);
    eval.iterate(state, new Object[] {new BytesWritable(sketch2.compact().toByteArray()),
        new IntWritable(nomNumEntries)});

    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(), nomNumEntries);
    Sketch<DoubleSummary> resultSketch = Sketches.heapifySketch(Memory.wrap(((BytesWritable) (r.get(1))).getBytes()));
    Assert.assertEquals(resultSketch.getEstimate(), 2.0);
  }
}
 
开发者ID:DataSketches,项目名称:sketches-hive,代码行数:35,代码来源:UnionDoubleSummarySketchUDAFTest.java

示例14: partial2Mode

import com.yahoo.sketches.tuple.UpdatableSketchBuilder; //导入依赖的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

示例15: finalMode

import com.yahoo.sketches.tuple.UpdatableSketchBuilder; //导入依赖的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


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