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


Java Sketches类代码示例

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


Sketches类属于com.yahoo.sketches.tuple包,在下文中一共展示了Sketches类的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: partial1ModeStringKeysExplicitParams

import com.yahoo.sketches.tuple.Sketches; //导入依赖的package包/类
@Test
public void partial1ModeStringKeysExplicitParams() throws Exception {
  ObjectInspector[] inspectors = new ObjectInspector[] { stringInspector, doubleInspector, intInspector, floatInspector };
  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 Text("a"), new DoubleWritable(1), new IntWritable(32), new FloatWritable(0.99f)});
    eval.iterate(state, new Object[] {new Text("b"), new DoubleWritable(1), new IntWritable(32), new FloatWritable(0.99f)});

    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(), 32);
    Sketch<DoubleSummary> resultSketch = Sketches.heapifySketch(Memory.wrap(((BytesWritable) r.get(1)).getBytes()));
    // because of sampling probability < 1
    Assert.assertTrue(resultSketch.isEstimationMode());
    Assert.assertEquals(resultSketch.getEstimate(), 2.0, 0.05);
  }
}
 
开发者ID:DataSketches,项目名称:sketches-hive,代码行数:26,代码来源:DataToDoubleSummarySketchUDAFTest.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: completeModeDoubleKeysExplicitParams

import com.yahoo.sketches.tuple.Sketches; //导入依赖的package包/类
@Test
public void completeModeDoubleKeysExplicitParams() throws Exception {
  ObjectInspector[] inspectors = new ObjectInspector[] { doubleInspector, doubleInspector, intInspector, floatInspector };
  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 DoubleWritable(1), new DoubleWritable(1), new IntWritable(32), new FloatWritable(0.99f)});
    eval.iterate(state, new Object[] {new DoubleWritable(2), new DoubleWritable(1), new IntWritable(32), new FloatWritable(0.99f)});

    Object result = eval.terminate(state);
    Assert.assertNotNull(result);
    Assert.assertTrue(result instanceof BytesWritable);
    Sketch<DoubleSummary> resultSketch = Sketches.heapifySketch(Memory.wrap(((BytesWritable) result).getBytes()));
    // because of sampling probability < 1
    Assert.assertTrue(resultSketch.isEstimationMode());
    Assert.assertEquals(resultSketch.getEstimate(), 2.0, 0.05);

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

示例5: completeModeCheckTrimmingToNominal

import com.yahoo.sketches.tuple.Sketches; //导入依赖的package包/类
@Test
public void completeModeCheckTrimmingToNominal() 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();
    for (int i = 0; i < 10000; i++) {
      eval.iterate(state, new Object[] {new IntWritable(i), 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(), 10000.0, 10000 * 0.03);
    Assert.assertTrue(resultSketch.getRetainedEntries() <= 4096, "retained entries: " + resultSketch.getRetainedEntries());

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

示例6: completeModeCheckTrimmingToNominal

import com.yahoo.sketches.tuple.Sketches; //导入依赖的package包/类
@Test
public void completeModeCheckTrimmingToNominal() 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.COMPLETE, inspectors);
    checkFinalResultInspector(resultInspector);

    @SuppressWarnings("unchecked")
    State<DoubleSummary> state = (State<DoubleSummary>) eval.getNewAggregationBuffer();
    for (int i = 0; i < 10000; i++) {
      eval.iterate(state, new Object[] {new IntWritable(i), 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(), 10000.0, 10000 * 0.03);
    Assert.assertTrue(resultSketch.getRetainedEntries() <= 4096, "retained entries: " + resultSketch.getRetainedEntries());

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

示例7: 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

示例8: 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

示例9: execMinMode

import com.yahoo.sketches.tuple.Sketches; //导入依赖的package包/类
@Test
public void execMinMode() throws Exception {
  EvalFunc<Tuple> func = new DataToDoubleSummarySketch("32", "Min");
  DataBag bag = BagFactory.getInstance().newDefaultBag();
  bag.add(PigUtil.objectsToTuple("a", 1.0));
  bag.add(PigUtil.objectsToTuple("b", 2.0));
  bag.add(PigUtil.objectsToTuple("a", 2.0));
  bag.add(PigUtil.objectsToTuple("b", 1.0));

  Tuple inputTuple = PigUtil.objectsToTuple(bag);
  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(), 1.0);
  }
}
 
开发者ID:DataSketches,项目名称:sketches-pig,代码行数:23,代码来源:DataToDoubleSummarySketchTest.java

示例10: 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

示例11: iterate

import com.yahoo.sketches.tuple.Sketches; //导入依赖的package包/类
@Override
public void iterate(final @SuppressWarnings("deprecation") AggregationBuffer buf, final Object[] data)
    throws HiveException {
  if (data[0] == null) { return; }
  @SuppressWarnings("unchecked")
  final UnionState<S> state = (UnionState<S>) buf;
  if (!state.isInitialized()) {
    initializeState(state, data);
  }
  final byte[] serializedSketch = (byte[]) sketchInspector_.getPrimitiveJavaObject(data[0]);
  if (serializedSketch == null) { return; }
  state.update(Sketches.heapifySketch(Memory.wrap(serializedSketch)));
}
 
开发者ID:DataSketches,项目名称:sketches-hive,代码行数:14,代码来源:UnionSketchUDAF.java

示例12: 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

示例13: merge

import com.yahoo.sketches.tuple.Sketches; //导入依赖的package包/类
@Override
public void merge(final @SuppressWarnings("deprecation") AggregationBuffer buf, final Object data)
    throws HiveException {
  if (data == null) { return; }
  @SuppressWarnings("unchecked")
  final UnionState<S> state = (UnionState<S>) buf;
  if (!state.isInitialized()) {
    initializeState(state, data);
  }
  final BytesWritable serializedSketch =
      (BytesWritable) intermediateInspector_.getStructFieldData(
          data, intermediateInspector_.getStructFieldRef(SKETCH_FIELD));
  state.update(Sketches.heapifySketch(Memory.wrap(serializedSketch.getBytes())));
}
 
开发者ID:DataSketches,项目名称:sketches-hive,代码行数:15,代码来源:SketchEvaluator.java

示例14: evaluate

import com.yahoo.sketches.tuple.Sketches; //导入依赖的package包/类
/**
 * Get estimates from a given Sketch&lt;DoubleSummary&gt;
 * @param serializedSketch DoubleSummarySketch in a serialized binary form
 * @return list of estimates
 */
public List<Double> evaluate(final BytesWritable serializedSketch) {
  if (serializedSketch == null) { return null; }
  final Sketch<DoubleSummary> sketch =
      Sketches.heapifySketch(Memory.wrap(serializedSketch.getBytes()));
  double sum = 0;
  final SketchIterator<DoubleSummary> it = sketch.iterator();
  while (it.next()) {
    sum += it.getSummary().getValue();
  }
  return Arrays.asList(
    sketch.getEstimate(),
    sum / sketch.getTheta()
  );
}
 
开发者ID:DataSketches,项目名称:sketches-hive,代码行数:20,代码来源:DoubleSummarySketchToEstimatesUDF.java

示例15: partial2Mode

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


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