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


Java Tuple.getType方法代码示例

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


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

示例1: updateUnion

import org.apache.pig.data.Tuple; //导入方法依赖的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

示例2: updateUnion

import org.apache.pig.data.Tuple; //导入方法依赖的package包/类
/**
 * Updates a union given a bag of sketches
 *
 * @param bag A bag of sketchTuples.
 * @param union The union to update
 */
private static <T> void updateUnion(final DataBag bag, final ItemsUnion<T> union,
      final Comparator<T> comparator, final ArrayOfItemsSerDe<T> serDe) throws ExecException {
  for (Tuple innerTuple: bag) {
    final Object f0 = innerTuple.get(0);
    if (f0 == null) { continue; }
    if (f0 instanceof DataByteArray) {
      final DataByteArray dba = (DataByteArray) f0;
      if (dba.size() > 0) {
        union.update(ItemsSketch.getInstance(Memory.wrap(dba.get()), comparator, serDe));
      }
    } else {
      throw new IllegalArgumentException("Field type was not DataType.BYTEARRAY: " + innerTuple.getType(0));
    }
  }
}
 
开发者ID:DataSketches,项目名称:sketches-pig,代码行数:22,代码来源:UnionItemsSketch.java

示例3: updateUnion

import org.apache.pig.data.Tuple; //导入方法依赖的package包/类
/**
 * Updates a union from a bag of sketches
 *
 * @param bag A bag of sketchTuples.
 * @param union The union to update
 */
private static void updateUnion(final DataBag bag, final DoublesUnion union) throws ExecException {
  for (Tuple innerTuple: bag) {
    final Object f0 = innerTuple.get(0);
    if (f0 == null) { continue; }
    if (f0 instanceof DataByteArray) {
      final DataByteArray dba = (DataByteArray) f0;
      if (dba.size() > 0) {
        union.update(Memory.wrap(dba.get()));
      }
    } else {
      throw new IllegalArgumentException("Field type was not DataType.BYTEARRAY: " + innerTuple.getType(0));
    }
  }
}
 
开发者ID:DataSketches,项目名称:sketches-pig,代码行数:21,代码来源:UnionDoublesSketch.java

示例4: extractTypeAtIndex

import org.apache.pig.data.Tuple; //导入方法依赖的package包/类
/**
 * Extract a non-null Byte from getType(index) of the given tuple.  Caught exceptions include
 * IOException, NullPointerException and IndexOutOfBoundsException.
 * If an exception is caught a null is returned to the caller as a signal.
 * @param tuple the given tuple.
 * @param index the 0-based index of the desired field
 * @return a Byte of Pig DataType or null.
 */
static final Byte extractTypeAtIndex(final Tuple tuple, final int index) {
  Byte type = null;
  try {
    type = tuple.getType(index);
  }
  catch (final IOException | NullPointerException | IndexOutOfBoundsException e) {
    return null;
  }
  return type;
}
 
开发者ID:DataSketches,项目名称:sketches-pig,代码行数:19,代码来源:PigUtil.java

示例5: updateUnion

import org.apache.pig.data.Tuple; //导入方法依赖的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

示例6: updateSketch

import org.apache.pig.data.Tuple; //导入方法依赖的package包/类
static void updateSketch(
    final DataBag bag, final ArrayOfDoublesUpdatableSketch sketch, final int numValues)
        throws ExecException {
  if (bag == null) {
    throw new IllegalArgumentException("InputTuple.Field0: Bag may not be null");
  }
  final double[] values = new double[numValues];
  for (final Tuple tuple: bag) {
    if (tuple.size() != numValues + 1) {
      throw new IllegalArgumentException("Inner tuple of input bag must have " + (numValues + 1)
          + " fields.");
    }

    final Object key = tuple.get(0);
    if (key == null) { continue; }
    for (int i = 0; i < numValues; i++) {
      values[i] = (Double) tuple.get(i + 1);
    }

    switch (tuple.getType(0)) {
    case DataType.BYTE:
      sketch.update(((Byte) key).longValue(), values);
      break;
    case DataType.INTEGER:
      sketch.update(((Integer) key).longValue(), values);
      break;
    case DataType.LONG:
      sketch.update((Long) key, values);
      break;
    case DataType.FLOAT:
      sketch.update((Float) key, values);
      break;
    case DataType.DOUBLE:
      sketch.update((Double) key, values);
      break;
    case DataType.BYTEARRAY:
      final DataByteArray dba = (DataByteArray) key;
      if (dba.size() != 0) {
        sketch.update(dba.get(), values);
      }
      break;
    case DataType.CHARARRAY:
      final String s = key.toString();
      if (!s.isEmpty()) {
        sketch.update(s, values);
      }
      break;
    default:
      throw new IllegalArgumentException("Field 0 must be one of "
          + "NULL, BYTE, INTEGER, LONG, FLOAT, DOUBLE, BYTEARRAY or CHARARRAY. " + "Type = "
          + DataType.findTypeName(tuple.getType(0)) + ", Object = " + key.toString());
    }
  }
}
 
开发者ID:DataSketches,项目名称:sketches-pig,代码行数:55,代码来源:DataToArrayOfDoublesSketchBase.java

示例7: updateSketch

import org.apache.pig.data.Tuple; //导入方法依赖的package包/类
static <U, S extends UpdatableSummary<U>> void updateSketch(final DataBag bag,
      final UpdatableSketch<U, S> sketch) throws ExecException {
  if (bag == null) {
    throw new IllegalArgumentException("InputTuple.Field0: Bag may not be null");
  }
  for (final Tuple tuple: bag) {
    if (tuple.size() != 2) {
      throw new IllegalArgumentException("Inner tuple of input bag must have 2 fields.");
    }

    final Object key = tuple.get(0);
    if (key == null) { continue; }
    @SuppressWarnings("unchecked")
    final U value = (U) tuple.get(1);

    switch (tuple.getType(0)) {
    case DataType.BYTE:
      sketch.update(((Byte) key).longValue(), value);
      break;
    case DataType.INTEGER:
      sketch.update(((Integer) key).longValue(), value);
      break;
    case DataType.LONG:
      sketch.update((Long) key, value);
      break;
    case DataType.FLOAT:
      sketch.update((Float) key, value);
      break;
    case DataType.DOUBLE:
      sketch.update((Double) key, value);
      break;
    case DataType.BYTEARRAY:
      final DataByteArray dba = (DataByteArray) key;
      if (dba.size() != 0) {
        sketch.update(dba.get(), value);
      }
      break;
    case DataType.CHARARRAY:
      final String s = key.toString();
      if (!s.isEmpty()) {
        sketch.update(s, value);
      }
      break;
    default:
      throw new IllegalArgumentException("Field 0 must be one of "
          + "NULL, BYTE, INTEGER, LONG, FLOAT, DOUBLE, BYTEARRAY or CHARARRAY. " + "Type = "
          + DataType.findTypeName(tuple.getType(0)) + ", Object = " + key.toString());
    }
  }
}
 
开发者ID:DataSketches,项目名称:sketches-pig,代码行数:51,代码来源:DataToSketch.java


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