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


Java Intersection類代碼示例

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


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

示例1: evaluate

import com.yahoo.sketches.theta.Intersection; //導入依賴的package包/類
/**
 * Main logic called by hive if sketchSize is also passed in. Computes the
 * intersection of two sketches of same or different column.
 *
 * @param firstSketchBytes
 *          first sketch to be intersected.
 * @param secondSketchBytes
 *          second sketch to be intersected.
 * @param hashSeed
 *          Only required if input sketches were constructed using an update seed that was not the default.
 * @return resulting sketch of intersection.
 */
public BytesWritable evaluate(final BytesWritable firstSketchBytes,
    final BytesWritable secondSketchBytes, final long hashSeed) {
  Sketch firstSketch = null;
  if (firstSketchBytes != null && firstSketchBytes.getLength() > 0) {
    firstSketch = Sketch.wrap(Memory.wrap(firstSketchBytes.getBytes()), hashSeed);
  }

  Sketch secondSketch = null;
  if (secondSketchBytes != null && secondSketchBytes.getLength() > 0) {
    secondSketch = Sketch.wrap(Memory.wrap(secondSketchBytes.getBytes()), hashSeed);
  }

  final Intersection intersect = SetOperation.builder().setSeed(hashSeed).buildIntersection();
  intersect.update(firstSketch);
  intersect.update(secondSketch);
  return new BytesWritable(intersect.getResult().toByteArray());
}
 
開發者ID:DataSketches,項目名稱:sketches-hive,代碼行數:30,代碼來源:IntersectSketchUDF.java

示例2: updateIntersection

import com.yahoo.sketches.theta.Intersection; //導入依賴的package包/類
/*************************************************************************************************
 * Updates an intersection from a bag of sketches
 *
 * @param bag A bag of sketchTuples.
 * @param intersection The intersection to update
 * @param seed to check against incoming sketches
 */
private static void updateIntersection(final DataBag bag, final Intersection intersection,
    final long seed) {
  //Bag is not empty. process each innerTuple in the bag
  for (Tuple innerTuple : bag) {
    //validate the inner Tuples
    final Object f0 = extractFieldAtIndex(innerTuple, 0);
    if (f0 == null) {
    continue;
  }
    final Byte type = extractTypeAtIndex(innerTuple, 0);
  // add only the first field of the innerTuple to the intersection
  if (type == DataType.BYTEARRAY) {
    final DataByteArray dba = (DataByteArray) f0;
    final Memory srcMem = Memory.wrap(dba.get());
    final Sketch sketch = Sketch.wrap(srcMem, seed);
    intersection.update(sketch);
  }
  else {
    throw new IllegalArgumentException(
        "Field type was not DataType.BYTEARRAY: " + type);
    }
  }
}
 
開發者ID:DataSketches,項目名稱:sketches-pig,代碼行數:31,代碼來源:Intersect.java

示例3: exec

import com.yahoo.sketches.theta.Intersection; //導入依賴的package包/類
/************************************************************************************************
 * Top-level exec function.
 * This method accepts an input Tuple containing a Bag of one or more inner <b>Sketch Tuples</b>
 * and returns a single updated <b>Sketch</b> as a <b>Sketch Tuple</b>.
 *
 * <p>If a large number of calls are anticipated, leveraging either the <i>Algebraic</i> or
 * <i>Accumulator</i> interfaces is recommended. Pig normally handles this automatically.
 *
 * <p>Internally, this method presents the inner <b>Sketch Tuples</b> to a new <b>Intersection</b>.
 * The result is returned as a <b>Sketch Tuple</b>
 *
 * <p><b>Input Tuple</b>
 * <ul>
 *   <li>Tuple: TUPLE (Must contain only one field)
 *     <ul>
 *       <li>index 0: DataBag: BAG (May contain 0 or more Inner Tuples)
 *         <ul>
 *           <li>index 0: Tuple: TUPLE <b>Sketch Tuple</b></li>
 *           <li>...</li>
 *           <li>index n-1: Tuple: TUPLE <b>Sketch Tuple</b></li>
 *         </ul>
 *       </li>
 *     </ul>
 *   </li>
 * </ul>
 *
 * <b>Sketch Tuple</b>
 * <ul>
 *   <li>Tuple: TUPLE (Contains exactly 1 field)
 *     <ul>
 *       <li>index 0: DataByteArray: BYTEARRAY = The serialization of a Sketch object.</li>
 *     </ul>
 *   </li>
 * </ul>
 *
 * @param inputTuple A tuple containing a single bag, containing Sketch Tuples.
 * @return Sketch Tuple. If inputTuple is null or empty, returns empty sketch (8 bytes).
 * @see "org.apache.pig.EvalFunc.exec(org.apache.pig.data.Tuple)"
 */
//@formatter:on

@Override //TOP LEVEL EXEC
public Tuple exec(final Tuple inputTuple) throws IOException { //throws is in API
  //The exec is a stateless function.  It operates on the input and returns a result.
  // It can only call static functions.
  final Intersection intersection = SetOperation.builder().setSeed(seed_).buildIntersection();
  final DataBag bag = extractBag(inputTuple);
  if (bag == null) {
    return emptyCompactOrderedSketchTuple_; //Configured with parent
  }

  updateIntersection(bag, intersection, seed_);
  final CompactSketch compactSketch = intersection.getResult(true, null);
  return compactOrderedSketchToTuple(compactSketch);
}
 
開發者ID:DataSketches,項目名稱:sketches-pig,代碼行數:56,代碼來源:Intersect.java


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