當前位置: 首頁>>代碼示例>>Java>>正文


Java UpdatableSketch.update方法代碼示例

本文整理匯總了Java中com.yahoo.sketches.tuple.UpdatableSketch.update方法的典型用法代碼示例。如果您正苦於以下問題:Java UpdatableSketch.update方法的具體用法?Java UpdatableSketch.update怎麽用?Java UpdatableSketch.update使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.yahoo.sketches.tuple.UpdatableSketch的用法示例。


在下文中一共展示了UpdatableSketch.update方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: partial2Mode

import com.yahoo.sketches.tuple.UpdatableSketch; //導入方法依賴的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

示例2: finalMode

import com.yahoo.sketches.tuple.UpdatableSketch; //導入方法依賴的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

示例3: algebraicIntermediateFinal

import com.yahoo.sketches.tuple.UpdatableSketch; //導入方法依賴的package包/類
@Test
public void algebraicIntermediateFinal() throws Exception {
  EvalFunc<Tuple> func = new DataToDoubleSummarySketch.IntermediateFinal("32");
  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))));

  // this is to simulate the output from a prior call of IntermediateFinal
  UpdatableSketch<Double, DoubleSummary> ts = new UpdatableSketchBuilder<Double, DoubleSummary>(new DoubleSummaryFactory()).build();
  ts.update("b", 1.0);
  ts.update("a", 2.0);
  ts.update("b", 2.0);
  Sketch<DoubleSummary> cs = ts.compact();
  bag.add(PigUtil.objectsToTuple(new DataByteArray(cs.toByteArray())));

  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(), 3.0);
  }
}
 
開發者ID:DataSketches,項目名稱:sketches-pig,代碼行數:31,代碼來源:DataToDoubleSummarySketchTest.java

示例4: normalCase

import com.yahoo.sketches.tuple.UpdatableSketch; //導入方法依賴的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

示例5: normalCase

import com.yahoo.sketches.tuple.UpdatableSketch; //導入方法依賴的package包/類
@Test
public void normalCase() throws Exception {
  EvalFunc<Double> func = new DoubleSummarySketchToPercentile();
  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);
  Tuple inputTuple = PigUtil.objectsToTuple(new DataByteArray(sketch.compact().toByteArray()), 50.0);
  double result = func.exec(inputTuple);
  Assert.assertEquals(result, iterations, iterations * 0.02);
}
 
開發者ID:DataSketches,項目名稱:sketches-pig,代碼行數:12,代碼來源:DoubleSummarySketchToPercentileTest.java

示例6: partial1ModeDefaultParams

import com.yahoo.sketches.tuple.UpdatableSketch; //導入方法依賴的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

示例7: finalMode

import com.yahoo.sketches.tuple.UpdatableSketch; //導入方法依賴的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

示例8: completeModeDefaultParams

import com.yahoo.sketches.tuple.UpdatableSketch; //導入方法依賴的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

示例9: normalCase

import com.yahoo.sketches.tuple.UpdatableSketch; //導入方法依賴的package包/類
@Test
public void normalCase() throws Exception {
  EvalFunc<Tuple> func = new DoubleSummarySketchToEstimates();
  UpdatableSketch<Double, DoubleSummary> sketch = new UpdatableSketchBuilder<Double, DoubleSummary>(new DoubleSummaryFactory()).build();
  int iterations = 100000;
  for (int i = 0; i < iterations; i++) sketch.update(i, 1.0);
  for (int i = 0; i < iterations; i++) sketch.update(i, 1.0);
  Tuple inputTuple = PigUtil.objectsToTuple(new DataByteArray(sketch.compact().toByteArray()));
  Tuple resultTuple = func.exec(inputTuple);
  Assert.assertNotNull(resultTuple);
  Assert.assertEquals(resultTuple.size(), 2);
  Assert.assertEquals((double) resultTuple.get(0), iterations, iterations * 0.03);
  Assert.assertEquals((double) resultTuple.get(1), 2 * iterations, 2 * iterations * 0.03);
}
 
開發者ID:DataSketches,項目名稱:sketches-pig,代碼行數:15,代碼來源:DoubleSummarySketchToEstimatesTest.java

示例10: partial1ModeDefaultParams

import com.yahoo.sketches.tuple.UpdatableSketch; //導入方法依賴的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

示例11: partial1ModeExplicitParams

import com.yahoo.sketches.tuple.UpdatableSketch; //導入方法依賴的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

示例12: partial2Mode

import com.yahoo.sketches.tuple.UpdatableSketch; //導入方法依賴的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: finalMode

import com.yahoo.sketches.tuple.UpdatableSketch; //導入方法依賴的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

示例14: completeModeDefaultParams

import com.yahoo.sketches.tuple.UpdatableSketch; //導入方法依賴的package包/類
@Test
public void completeModeDefaultParams() 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.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);
    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.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,代碼行數:31,代碼來源:UnionDoubleSummarySketchUDAFTest.java

示例15: completeModeExplicitParams

import com.yahoo.sketches.tuple.UpdatableSketch; //導入方法依賴的package包/類
@Test
public void completeModeExplicitParams() 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.COMPLETE, inspectors);
    DataToDoubleSummarySketchUDAFTest.checkFinalResultInspector(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.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, 0.05);

    eval.reset(state);
    result = eval.terminate(state);
    Assert.assertNull(result);
  }
}
 
開發者ID:DataSketches,項目名稱:sketches-hive,代碼行數:36,代碼來源:UnionDoubleSummarySketchUDAFTest.java


注:本文中的com.yahoo.sketches.tuple.UpdatableSketch.update方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。