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


Java Tuple.size方法代码示例

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


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

示例1: exec

import org.apache.pig.data.Tuple; //导入方法依赖的package包/类
@Override
public String exec(final Tuple tuple) throws IOException {
    if (tuple == null || tuple.size() == 0) {
        return null;
    }
    Object dateString = tuple.get(0);
    if (dateString == null) {
        return null;
    }
    try {
        Date date = DateUtils.parseDate(dateString.toString(), new String[]{"yyyy-MM-dd HH:mm:ss"});
        return DateFormatUtils.format(date, formatPattern);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return null;
}
 
开发者ID:mumuhadoop,项目名称:mumu-pig,代码行数:18,代码来源:DateFormatEval.java

示例2: exec

import org.apache.pig.data.Tuple; //导入方法依赖的package包/类
@Override
public Boolean exec(final Tuple tuple) throws IOException {
    if (tuple == null || tuple.size() == 0) {
        return false;
    }
    try {
        Object object = tuple.get(0);
        if (object == null) {
            return false;
        }
        int i = (Integer) object;
        return i == 0 || i == 1 || i == 4 || i == 5 || i == 9;
    } catch (ExecException e) {
        throw new IOException(e);
    }
}
 
开发者ID:mumuhadoop,项目名称:mumu-pig,代码行数:17,代码来源:ISGoodQuarityFilter.java

示例3: exec

import org.apache.pig.data.Tuple; //导入方法依赖的package包/类
@Override
public String exec( Tuple input ) throws IOException {
    if( input == null ) {
        throw new IOException( "No arguments: Usage NormalizeText(String, ASCII)" );
    }
    if( input.size() != 2 ) {
        throw new IOException( "Wrong arguments: Usage NormalizeText(String, ASCII)" );
    }
    for( int i = 0; i < input.size(); i++ ) {
        if( input.get( i ) == null ) {
            return null;
        }
    }

    if( Boolean.parseBoolean( ( String ) input.get( 1 ) ) ) {
        String norm = normalizeToASCII( ( String ) input.get( 0 ) );
        return normalize( norm );

    } else {
        return normalize( ( String ) input.get( 0 ) );
    }
}
 
开发者ID:yahoo,项目名称:FEL,代码行数:23,代码来源:NormalizeText.java

示例4: putNext

import org.apache.pig.data.Tuple; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void putNext(Tuple tuple) throws IOException {
    if (tuple == null || tuple.size() == 0) {
        return;
    }

    String data = null;
    if (createDocOp) {
        data = createDocumentOperation(tuple);
    } else if (!tuple.isNull(0)) {
        data = tuple.get(0).toString(); // assume single field with correctly formatted doc op.
    }

    if (data == null || data.length() == 0) {
        return;
    }

    try {
        recordWriter.write(0, data);
    } catch (InterruptedException e) {
        throw new IOException(e);
    }
}
 
开发者ID:vespa-engine,项目名称:vespa,代码行数:25,代码来源:VespaStorage.java

示例5: shouldWriteTupleStart

import org.apache.pig.data.Tuple; //导入方法依赖的package包/类
private static boolean shouldWriteTupleStart(Tuple tuple, String name, Properties properties) {
    if (tuple.size() > 1 || properties == null) {
        return true;
    }
    String simpleArrayFields = properties.getProperty(SIMPLE_ARRAY_FIELDS);
    if (simpleArrayFields == null) {
        return true;
    }
    if (simpleArrayFields.equals("*")) {
        return false;
    }
    String[] fields = simpleArrayFields.split(",");
    for (String field : fields) {
        if (field.trim().equalsIgnoreCase(name)) {
            return false;
        }
    }
    return true;
}
 
开发者ID:vespa-engine,项目名称:vespa,代码行数:20,代码来源:VespaDocumentOperation.java

示例6: exec

import org.apache.pig.data.Tuple; //导入方法依赖的package包/类
@Override
public Double exec(final Tuple input) throws IOException {
  if (input.size() != 2) {
    throw new IllegalArgumentException("expected two inputs: sketch and fraction");
  }

  if (!(input.get(0) instanceof DataByteArray)) {
    throw new IllegalArgumentException("expected a DataByteArray as a sketch, got "
        + input.get(0).getClass().getSimpleName());
  }
  final DataByteArray dba = (DataByteArray) input.get(0);
  final DoublesSketch sketch = DoublesSketch.wrap(Memory.wrap(dba.get()));

  if (!(input.get(1) instanceof Double)) {
    throw new IllegalArgumentException("expected a double value as a fraction, got "
        + input.get(1).getClass().getSimpleName());
  }
  final double fraction = (double) input.get(1);
  return sketch.getQuantile(fraction);
}
 
开发者ID:DataSketches,项目名称:sketches-pig,代码行数:21,代码来源:GetQuantileFromDoublesSketch.java

示例7: exec

import org.apache.pig.data.Tuple; //导入方法依赖的package包/类
@Override
public Long exec(Tuple tuple) throws IOException {
  if (tuple == null || tuple.size() < 2) {
    throw new IOException("Not enough values");
  }
  Tuple timeTuple = (Tuple) tuple.get(0);
  if (tuple.size() - 1 > timeTuple.size()) {
    throw new IOException("Not enough tuple values to convert. Specified " + (tuple.size() - 1)
            + " calendar fields, but time tuple only has " + timeTuple.size());
  }
  Calendar cal = getZeroedCalendar();
  for (int i = 0; i < tuple.size() - 1; i++) {
    String key = (String) tuple.get(i + 1);
    Integer calKey = calMap.get(key);
    if (calKey == null) {
      throw new IOException("Unknown Calendar field: " + key);
    }
    cal.set(calKey, (Integer) timeTuple.get(i));
  }
  return cal.getTimeInMillis();
}
 
开发者ID:lucidworks,项目名称:pig-solr,代码行数:22,代码来源:CalendarToEpoch.java

示例8: exec

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

示例9: accumulate

import org.apache.pig.data.Tuple; //导入方法依赖的package包/类
@Override
public void accumulate(final Tuple inputTuple) throws IOException {
  if (isFirstCall_) {
    // this is to see in the log which way was used by Pig
    Logger.getLogger(getClass()).info("accumulate is used");
    isFirstCall_ = false;
  }
  if (accumSketch_ == null) {
    accumSketch_ = sketchBuilder_.build();
  }
  if (inputTuple.size() != 1) {
    throw new IllegalArgumentException("Input tuple must have 1 bag");
  }
  final DataBag bag = (DataBag) inputTuple.get(0);
  updateSketch(bag, accumSketch_);
}
 
开发者ID:DataSketches,项目名称:sketches-pig,代码行数:17,代码来源:DataToSketch.java

示例10: exec

import org.apache.pig.data.Tuple; //导入方法依赖的package包/类
@Override
public Integer exec(final Tuple input) throws IOException {
  if (input.size() != 1) {
    throw new IllegalArgumentException("expected one input");
  }

  if (!(input.get(0) instanceof DataByteArray)) {
    throw new IllegalArgumentException("expected a DataByteArray as a sketch, got "
        + input.get(0).getClass().getSimpleName());
  }
  final DataByteArray dba = (DataByteArray) input.get(0);
  final ItemsSketch<String> sketch =
      ItemsSketch.getInstance(Memory.wrap(dba.get()), Comparator.naturalOrder(),
          new ArrayOfStringsSerDe());

  return sketch.getK();
}
 
开发者ID:DataSketches,项目名称:sketches-pig,代码行数:18,代码来源:GetKFromStringsSketch.java

示例11: createDocumentOperation

import org.apache.pig.data.Tuple; //导入方法依赖的package包/类
private String createDocumentOperation(Tuple tuple) throws IOException {
    if (tuple == null || tuple.size() == 0) {
        return null;
    }
    if (resourceSchema == null) {
        return null;
    }

    Map<String, Object> fields = TupleTools.tupleMap(resourceSchema, tuple);
    String docId = TupleTools.toString(fields, template);

    return VespaDocumentOperation.create(operation, docId, fields, properties);
}
 
开发者ID:vespa-engine,项目名称:vespa,代码行数:14,代码来源:VespaStorage.java

示例12: exec

import org.apache.pig.data.Tuple; //导入方法依赖的package包/类
@Override // IntermediateFinal exec
public Tuple exec(final Tuple inputTuple) throws IOException { //throws is in API
  if (inputTuple != null && inputTuple.size() > 0) {
    final DoublesUnion union = unionBuilder_.build();
    final DataBag outerBag = (DataBag) inputTuple.get(0);
    for (final Tuple dataTuple: outerBag) {
      final Object f0 = dataTuple.get(0);
      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.
        for (final Tuple innerTuple: innerBag) {
          union.update((Double) innerTuple.get(0));
        }
      } 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(Memory.wrap(dba.get()));
      } else {
        throw new IllegalArgumentException("dataTuple.Field0: Is not a DataByteArray: "
            + f0.getClass().getName());
      }
    }
    final DoublesSketch resultSketch = union.getResultAndReset();
    if (resultSketch != null) {
      return tupleFactory_.newTuple(new DataByteArray(resultSketch.toByteArray(true)));
    }
  }
  // return empty sketch
  return tupleFactory_.newTuple(new DataByteArray(unionBuilder_.build().getResult().toByteArray(true)));
}
 
开发者ID:DataSketches,项目名称:sketches-pig,代码行数:38,代码来源:DataToDoublesSketch.java

示例13: exec

import org.apache.pig.data.Tuple; //导入方法依赖的package包/类
@Override
public String exec(Tuple input) throws IOException {

    // validate input
    if (input == null || input.size() == 0 || input.get(0) == null) {
        return null;
    }

    // get the value of input
    String strAddress = (String) input.get(0);

    // Get geoip information
    try {
        String result = this.geo.getCountryName(strAddress);

        // replace "--" and "N/A" to null, better for pig
        if (result == null || result.equals("--") || result.equals("N/A")) {
            return null;
        } else {
            return result;
        }

    } catch (Exception e) {
        // e.printStackTrace();
        return null;
    }
}
 
开发者ID:christiangda,项目名称:pigiptools,代码行数:28,代码来源:GetCountryName.java

示例14: accumulate

import org.apache.pig.data.Tuple; //导入方法依赖的package包/类
@Override
public void accumulate(final Tuple inputTuple) throws IOException {
  if (isFirstCall_) {
    // this is to see in the log which way was used by Pig
    Logger.getLogger(getClass()).info("accumulator is used");
    isFirstCall_ = false;
  }
  if ((inputTuple == null) || (inputTuple.size() != 1)) {
    return;
  }
  final Object obj = inputTuple.get(0);
  if (!(obj instanceof DataBag)) {
    return;
  }
  final DataBag bag = (DataBag) inputTuple.get(0);
  if (bag.size() == 0) {
    return;
  }

  if (sketch_ == null) {
    sketch_ = new ItemsSketch<T>(sketchSize_);
  }
  for (final Tuple innerTuple: bag) {
    final int sz = innerTuple.size();
    if ((sz != 1) || (innerTuple.get(0) == null)) {
      continue;
    }
    final ItemsSketch<T> incomingSketch = Util.deserializeSketchFromTuple(innerTuple, serDe_);
    sketch_.merge(incomingSketch);
  }
}
 
开发者ID:DataSketches,项目名称:sketches-pig,代码行数:32,代码来源:UnionFrequentItemsSketch.java

示例15: exec

import org.apache.pig.data.Tuple; //导入方法依赖的package包/类
@Override
public String exec(Tuple input) throws IOException {

    //
    if (input == null || input.size() == 0 || input.get(0) == null) {
        return null;
    }

    //
    if (input.get(0) == "") {
        return input.get(0).toString();
    }

    if (input.size() > 1)
        throw new ExecException("Wrong number of arguments > 1", PigException.ERROR);

    //
    String url;

    //Validating arguments
    Object arg0 = input.get(0);
    if (arg0 instanceof String)
        url = (String) arg0;
    else {
        String msg = "Invalid data type for argument 0 " + DataType.findTypeName(arg0);
        throw new ExecException(msg, PigException.ERROR);
    }

    //
    try {
        return URLDecoder.decode(url, this.encoding);
    } catch (UnsupportedEncodingException e) {
        // We overflowed. Give a warning, but do not throw an
        // exception.
        warn(e.toString(), PigWarning.UDF_WARNING_1);
        // Returning null will indicate to Pig that we failed but
        // we want to continue execution.
        return null;
    }
}
 
开发者ID:christiangda,项目名称:pigiptools,代码行数:41,代码来源:Decode.java


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