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


Java Union類代碼示例

本文整理匯總了Java中com.yahoo.sketches.hll.Union的典型用法代碼示例。如果您正苦於以下問題:Java Union類的具體用法?Java Union怎麽用?Java Union使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


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

示例1: registerClasses

import com.yahoo.sketches.hll.Union; //導入依賴的package包/類
@Override
public void registerClasses(final Kryo kryo) {
    kryo.register(Entity.class, new EntityKryoSerializer());
    kryo.register(Edge.class, new EdgeKryoSerializer());
    kryo.register(Properties.class);
    kryo.register(FreqMap.class, new FreqMapKryoSerializer());
    kryo.register(HyperLogLogPlus.class, new HyperLogLogPlusKryoSerializer());
    kryo.register(HllSketch.class, new HllSketchKryoSerializer());
    kryo.register(Union.class, new HllUnionKryoSerializer());
    kryo.register(LongsSketch.class, new LongsSketchKryoSerializer());
    kryo.register(ItemsSketch.class, new StringsSketchKryoSerializer());
    kryo.register(com.yahoo.sketches.quantiles.ItemsSketch.class, new uk.gov.gchq.gaffer.spark.serialisation.kryo.impl.datasketches.quantiles.StringsSketchKryoSerializer());
    kryo.register(ItemsUnion.class, new StringsUnionKryoSerializer());
    kryo.register(ReservoirLongsSketch.class, new ReservoirLongsSketchKryoSerializer());
    kryo.register(ReservoirLongsUnion.class, new ReservoirLongsUnionKryoSerializer());
    kryo.register(TypeValue.class, new TypeValueKryoSerializer());
    kryo.register(TypeSubTypeValue.class, new TypeSubTypeValueKryoSerializer());
}
 
開發者ID:gchq,項目名稱:Gaffer,代碼行數:19,代碼來源:Registrator.java

示例2: evaluate

import com.yahoo.sketches.hll.Union; //導入依賴的package包/類
/**
 * Union two sketches given explicit lgK and target HLL type
 *
 * @param firstSketch
 *   first sketch to be unioned.
 * @param secondSketch
 *          second sketch to be unioned.
 * @param lgK
 *   final output lgK
 *   This must be between 4 and 21.
 * @param type
 *   final output HLL type
 * @return resulting sketch of union.
 */
public BytesWritable evaluate(final BytesWritable firstSketch, final BytesWritable secondSketch,
    final int lgK, final String type) {

  final TgtHllType hllType = TgtHllType.valueOf(type);
  final Union union = new Union(lgK);

  if (firstSketch != null) {
    union.update(HllSketch.wrap(Memory.wrap(firstSketch.getBytes())));
  }

  if (secondSketch != null) {
    union.update(HllSketch.wrap(Memory.wrap(secondSketch.getBytes())));
  }

  return new BytesWritable(union.getResult(hllType).toCompactByteArray());
}
 
開發者ID:DataSketches,項目名稱:sketches-hive,代碼行數:31,代碼來源:UnionSketchUDF.java

示例3: updateUnion

import com.yahoo.sketches.hll.Union; //導入依賴的package包/類
static void updateUnion(final DataBag bag, final Union union) throws ExecException {
  // Bag is not empty. process each innerTuple in the bag
  for (final Tuple innerTuple : bag) {
    final Object f0 = innerTuple.get(0); // consider only field 0
    if (f0 == null) {
      continue;
    }
    final byte type = innerTuple.getType(0);
    if (type == DataType.BYTEARRAY) {
      final DataByteArray dba = (DataByteArray) f0;
      union.update(HllSketch.wrap(Memory.wrap(dba.get())));
    } else {
      throw new IllegalArgumentException("Field type was not DataType.BYTEARRAY: " + type);
    }
  }
}
 
開發者ID:DataSketches,項目名稱:sketches-pig,代碼行數:17,代碼來源:UnionSketch.java

示例4: getTestObject

import com.yahoo.sketches.hll.Union; //導入依賴的package包/類
@Override
public Union getTestObject() {
    final Union union = new Union(15);
    union.update("A");
    union.update("B");
    union.update("C");
    return union;
}
 
開發者ID:gchq,項目名稱:Gaffer,代碼行數:9,代碼來源:HllUnionKryoSerializerTest.java

示例5: _apply

import com.yahoo.sketches.hll.Union; //導入依賴的package包/類
@Override
protected HllSketch _apply(final HllSketch a, final HllSketch b) {
    final Union union = new Union(a.getLgConfigK());
    union.update(a);
    union.update(b);
    return union.getResult();
}
 
開發者ID:gchq,項目名稱:Gaffer,代碼行數:8,代碼來源:HllSketchAggregator.java

示例6: setup

import com.yahoo.sketches.hll.Union; //導入依賴的package包/類
@Before
public void setup() {
    sketch1 = new Union(15);
    sketch1.update("A");
    sketch1.update("B");

    sketch2 = new Union(15);
    sketch2.update("C");
    sketch2.update("D");
}
 
開發者ID:gchq,項目名稱:Gaffer,代碼行數:11,代碼來源:HllUnionAggregatorTest.java

示例7: testAggregate

import com.yahoo.sketches.hll.Union; //導入依賴的package包/類
@Test
public void testAggregate() {
    final HllUnionAggregator sketchAggregator = new HllUnionAggregator();

    Union currentState = sketch1;
    assertEquals(2.0D, currentState.getEstimate(), DELTA);

    currentState = sketchAggregator.apply(currentState, sketch2);
    assertEquals(4.0D, currentState.getEstimate(), DELTA);
}
 
開發者ID:gchq,項目名稱:Gaffer,代碼行數:11,代碼來源:HllUnionAggregatorTest.java

示例8: testSerialiseAndDeserialise

import com.yahoo.sketches.hll.Union; //導入依賴的package包/類
@Test
public void testSerialiseAndDeserialise() {
    final Union sketch = new Union(15);
    sketch.update("A");
    sketch.update("B");
    sketch.update("C");
    testSerialiser(sketch);

    final Union emptySketch = new Union(15);
    testSerialiser(emptySketch);
}
 
開發者ID:gchq,項目名稱:Gaffer,代碼行數:12,代碼來源:HllUnionSerialiserTest.java

示例9: exec

import com.yahoo.sketches.hll.Union; //導入依賴的package包/類
@Override
public DataByteArray exec(final Tuple inputTuple) throws IOException {
  if (isFirstCall_) {
    Logger.getLogger(getClass()).info("Algebraic was used");
    isFirstCall_ = false;
  }
  if (inputTuple == null || inputTuple.size() == 0) {
    return getEmptySketch();
  }
  final Union union = new Union(lgK_);
  final DataBag outerBag = (DataBag) inputTuple.get(0);
  if (outerBag == null) {
    return getEmptySketch();
  }
  for (final Tuple dataTuple: outerBag) {
    final Object f0 = dataTuple.get(0); // inputTuple.bag0.dataTupleN.f0
    if (f0 == null) {
      continue;
    }
    if (f0 instanceof DataBag) {
      final DataBag innerBag = (DataBag) f0; // inputTuple.bag0.dataTupleN.f0:bag
      if (innerBag.size() == 0) { continue; }
      // If field 0 of a dataTuple is a Bag, all innerTuples of this inner bag
      // will be passed into the union.
      // It is due to system bagged outputs from multiple mapper Initial functions.
      // The Intermediate stage was bypassed.
      updateUnion(innerBag, union);
    } else if (f0 instanceof DataByteArray) { // inputTuple.bag0.dataTupleN.f0:DBA
      // If field 0 of a dataTuple is a DataByteArray, we assume it is a sketch
      // due to system bagged outputs from multiple mapper Intermediate functions.
      // Each dataTuple.DBA:sketch will merged into the union.
      final DataByteArray dba = (DataByteArray) f0;
      union.update(HllSketch.wrap(Memory.wrap(dba.get())));
    } else { // we should never get here
      throw new IllegalArgumentException("dataTuple.Field0 is not a DataBag or DataByteArray: "
          + f0.getClass().getName());
    }
  }
  return new DataByteArray(union.getResult(tgtHllType_).toCompactByteArray());
}
 
開發者ID:DataSketches,項目名稱:sketches-pig,代碼行數:41,代碼來源:AlgebraicFinal.java

示例10: exec

import com.yahoo.sketches.hll.Union; //導入依賴的package包/類
@Override
public Tuple exec(final Tuple inputTuple) throws IOException {
  if (isFirstCall_) {
    Logger.getLogger(getClass()).info("Algebraic was used");
    isFirstCall_ = false;
  }
  if (inputTuple == null || inputTuple.size() == 0) {
    return getEmptySketchTuple();
  }
  final DataBag outerBag = (DataBag) inputTuple.get(0);
  if (outerBag == null) {
    return getEmptySketchTuple();
  }
  final Union union = new Union(lgK_);
  for (final Tuple dataTuple: outerBag) {
    final Object f0 = dataTuple.get(0); // inputTuple.bag0.dataTupleN.f0
    if (f0 == null) { continue; }
    if (f0 instanceof DataBag) {
      final DataBag innerBag = (DataBag) f0; // inputTuple.bag0.dataTupleN.f0:bag
      if (innerBag.size() == 0) { continue; }
      // If field 0 of a dataTuple is a Bag, all innerTuples of this inner bag
      // will be passed into the union.
      // It is due to system bagged outputs from multiple mapper Initial functions.
      // The Intermediate stage was bypassed.
      updateUnion(innerBag, union);
    } else if (f0 instanceof DataByteArray) { // inputTuple.bag0.dataTupleN.f0:DBA
      // If field 0 of a dataTuple is a DataByteArray, we assume it is a sketch
      // due to system bagged outputs from multiple mapper Intermediate functions.
      // Each dataTuple.DBA:sketch will merged into the union.
      final DataByteArray dba = (DataByteArray) f0;
      union.update(HllSketch.wrap(Memory.wrap(dba.get())));
    } else { // we should never get here
      throw new IllegalArgumentException("dataTuple.Field0 is not a DataBag or DataByteArray: "
          + f0.getClass().getName());
    }
  }
  return tupleFactory_.newTuple(new DataByteArray(union.getResult(tgtHllType_).toCompactByteArray()));
}
 
開發者ID:DataSketches,項目名稱:sketches-pig,代碼行數:39,代碼來源:AlgebraicIntermediate.java

示例11: shouldCompareSerialisedAndDeserialisedObjects

import com.yahoo.sketches.hll.Union; //導入依賴的package包/類
@Override
protected void shouldCompareSerialisedAndDeserialisedObjects(final Union obj, final Union deserialised) {
    assertEquals(obj.getEstimate(), deserialised.getEstimate(), DELTA);
}
 
開發者ID:gchq,項目名稱:Gaffer,代碼行數:5,代碼來源:HllUnionKryoSerializerTest.java

示例12: getTestClass

import com.yahoo.sketches.hll.Union; //導入依賴的package包/類
@Override
public Class<Union> getTestClass() {
    return Union.class;
}
 
開發者ID:gchq,項目名稱:Gaffer,代碼行數:5,代碼來源:HllUnionKryoSerializerTest.java

示例13: _apply

import com.yahoo.sketches.hll.Union; //導入依賴的package包/類
@Override
protected Union _apply(final Union a, final Union b) {
    a.update(b.getResult());
    return a;
}
 
開發者ID:gchq,項目名稱:Gaffer,代碼行數:6,代碼來源:HllUnionAggregator.java

示例14: canHandle

import com.yahoo.sketches.hll.Union; //導入依賴的package包/類
@Override
public boolean canHandle(final Class clazz) {
    return Union.class.equals(clazz);
}
 
開發者ID:gchq,項目名稱:Gaffer,代碼行數:5,代碼來源:HllUnionSerialiser.java

示例15: serialise

import com.yahoo.sketches.hll.Union; //導入依賴的package包/類
@Override
public byte[] serialise(final Union sketch) throws SerialisationException {
    return sketch.toCompactByteArray();
}
 
開發者ID:gchq,項目名稱:Gaffer,代碼行數:5,代碼來源:HllUnionSerialiser.java


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