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


Java Union.update方法代码示例

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


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

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

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

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

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

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

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

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

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

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

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

    switch (type) {
      case DataType.NULL:
        break;
      case DataType.BYTE:
        union.update((byte) f0);
        break;
      case DataType.INTEGER:
        union.update((int) f0);
        break;
      case DataType.LONG:
        union.update((long) f0);
        break;
      case DataType.FLOAT:
        union.update((float) f0);
        break;
      case DataType.DOUBLE:
        union.update((double) f0);
        break;
      case DataType.BYTEARRAY: {
        final DataByteArray dba = (DataByteArray) f0;
        union.update(dba.get());
        break;
      }
      case DataType.CHARARRAY: {
        final String str = (String) f0;
        // conversion to char[] avoids costly UTF-8 encoding
        union.update(str.toCharArray());
        break;
      }
      default:
        throw new IllegalArgumentException("Field 0 of innerTuple must be one of "
            + "NULL, BYTE, INTEGER, LONG, FLOAT, DOUBLE, BYTEARRAY or CHARARRAY. "
            + "Given Type = " + DataType.findTypeName(type)
            + ", Object = " + f0.toString());
    }
  }
}
 
开发者ID:DataSketches,项目名称:sketches-pig,代码行数:47,代码来源:DataToSketch.java


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