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


Java OutputCollector.collect方法代碼示例

本文整理匯總了Java中org.apache.hadoop.mapred.OutputCollector.collect方法的典型用法代碼示例。如果您正苦於以下問題:Java OutputCollector.collect方法的具體用法?Java OutputCollector.collect怎麽用?Java OutputCollector.collect使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.hadoop.mapred.OutputCollector的用法示例。


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

示例1: reduce

import org.apache.hadoop.mapred.OutputCollector; //導入方法依賴的package包/類
/** Combines values for a given key.  
 * @param key the key is expected to be a Text object, whose prefix indicates
 * the type of aggregation to aggregate the values. 
 * @param values the values to combine
 * @param output to collect combined values
 */
public void reduce(Text key, Iterator<Text> values,
                   OutputCollector<Text, Text> output, Reporter reporter) throws IOException {
  String keyStr = key.toString();
  int pos = keyStr.indexOf(ValueAggregatorDescriptor.TYPE_SEPARATOR);
  String type = keyStr.substring(0, pos);
  ValueAggregator aggregator = ValueAggregatorBaseDescriptor
    .generateValueAggregator(type);
  while (values.hasNext()) {
    aggregator.addNextValue(values.next());
  }
  Iterator outputs = aggregator.getCombinerOutput().iterator();

  while (outputs.hasNext()) {
    Object v = outputs.next();
    if (v instanceof Text) {
      output.collect(key, (Text)v);
    } else {
      output.collect(key, new Text(v.toString()));
    }
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:28,代碼來源:ValueAggregatorCombiner.java

示例2: map

import org.apache.hadoop.mapred.OutputCollector; //導入方法依賴的package包/類
/** Run a FileOperation */
public void map(Text key, FileOperation value,
    OutputCollector<WritableComparable<?>, Text> out, Reporter reporter
    ) throws IOException {
  try {
    value.run(jobconf);
    ++succeedcount;
    reporter.incrCounter(Counter.SUCCEED, 1);
  } catch (IOException e) {
    ++failcount;
    reporter.incrCounter(Counter.FAIL, 1);

    String s = "FAIL: " + value + ", " + StringUtils.stringifyException(e);
    out.collect(null, new Text(s));
    LOG.info(s);
  } finally {
    reporter.setStatus(getCountString());
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:20,代碼來源:DistCh.java

示例3: map

import org.apache.hadoop.mapred.OutputCollector; //導入方法依賴的package包/類
@Override
public void map(ImmutableBytesWritable row, Result result,
    OutputCollector<ImmutableBytesWritable, Put> outCollector,
    Reporter reporter) throws IOException {
  String rowKey = Bytes.toString(result.getRow());
  final ImmutableBytesWritable pKey = new ImmutableBytesWritable(
      Bytes.toBytes(PRESIDENT_PATTERN));
  final ImmutableBytesWritable aKey = new ImmutableBytesWritable(
      Bytes.toBytes(ACTOR_PATTERN));
  ImmutableBytesWritable outKey = null;

  if (rowKey.startsWith(PRESIDENT_PATTERN)) {
    outKey = pKey;
  } else if (rowKey.startsWith(ACTOR_PATTERN)) {
    outKey = aKey;
  } else {
    throw new AssertionError("unexpected rowKey");
  }

  String name = Bytes.toString(result.getValue(COLUMN_FAMILY,
      COLUMN_QUALIFIER));
  outCollector.collect(outKey, new Put(Bytes.toBytes("rowKey2")).add(
      COLUMN_FAMILY, COLUMN_QUALIFIER, Bytes.toBytes(name)));
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:25,代碼來源:TestTableMapReduceUtil.java

示例4: reduce

import org.apache.hadoop.mapred.OutputCollector; //導入方法依賴的package包/類
@Override
public void reduce(Text token, Iterator<StringIntPair> values,
    OutputCollector<Key, BusyAirportModel> output, Reporter reporter)
    throws IOException {
  String topAirport = null;
  int max = 0;

  while (values.hasNext()) {
    StringIntPair v = values.next();
    if (v.getSecond() > max) {
      max = v.getSecond();
      topAirport = v.getFirst();
    }
  }
  BusyAirportModel busy = new BusyAirportModel(topAirport, max);
  output.collect(new Key(), busy);
}
 
開發者ID:gemxd,項目名稱:gemfirexd-oss,代碼行數:18,代碼來源:TopBusyAirportGemfirexd.java

示例5: map

import org.apache.hadoop.mapred.OutputCollector; //導入方法依賴的package包/類
@Override
public void map(Object key, ResultSet rs,
    OutputCollector<Text, IntWritable> output,
    Reporter reporter) throws IOException {

  String origAirport;
  String destAirport;
  String combo;

  try {
    origAirport = rs.getString("ORIG_AIRPORT");
    destAirport = rs.getString("DEST_AIRPORT");
    combo = origAirport.compareTo(
        destAirport) < 0 ? origAirport + destAirport : destAirport + origAirport;
    reusableText.set(combo);
    output.collect(reusableText, countOne);
  } catch (SQLException e) {
    e.printStackTrace();
  }
}
 
開發者ID:gemxd,項目名稱:gemfirexd-oss,代碼行數:21,代碼來源:BusyLegs.java

示例6: map

import org.apache.hadoop.mapred.OutputCollector; //導入方法依賴的package包/類
public void map(Object key, Object value,
                OutputCollector output, Reporter reporter) throws IOException {
  if (this.reporter == null) {
    this.reporter = reporter;
  }
  addLongValue("totalCount", 1);
  TaggedMapOutput aRecord = generateTaggedMapOutput(value);
  if (aRecord == null) {
    addLongValue("discardedCount", 1);
    return;
  }
  Text groupKey = generateGroupKey(aRecord);
  if (groupKey == null) {
    addLongValue("nullGroupKeyCount", 1);
    return;
  }
  output.collect(groupKey, aRecord);
  addLongValue("collectedCount", 1);
}
 
開發者ID:aliyun-beta,項目名稱:aliyun-oss-hadoop-fs,代碼行數:20,代碼來源:DataJoinMapperBase.java

示例7: reduce

import org.apache.hadoop.mapred.OutputCollector; //導入方法依賴的package包/類
/**
 * Counts the number of inlinks and outlinks for each url and sets a default
 * score of 0.0 for each url (node) in the webgraph.
 */
public void reduce(Text key, Iterator<LinkDatum> values,
    OutputCollector<Text, Node> output, Reporter reporter)
    throws IOException {

  Node node = new Node();
  int numInlinks = 0;
  int numOutlinks = 0;

  // loop through counting number of in and out links
  while (values.hasNext()) {
    LinkDatum next = values.next();
    if (next.getLinkType() == LinkDatum.INLINK) {
      numInlinks++;
    } else if (next.getLinkType() == LinkDatum.OUTLINK) {
      numOutlinks++;
    }
  }

  // set the in and outlinks and a default score of 0
  node.setNumInlinks(numInlinks);
  node.setNumOutlinks(numOutlinks);
  node.setInlinkScore(0.0f);
  output.collect(key, node);
}
 
開發者ID:jorcox,項目名稱:GeoCrawler,代碼行數:29,代碼來源:WebGraph.java

示例8: map

import org.apache.hadoop.mapred.OutputCollector; //導入方法依賴的package包/類
public void map(LongWritable key, Text val,
    OutputCollector<Text, NullWritable> out, Reporter r) throws IOException {

  LOG.info("Mapper input line: " + val.toString());

  try {
    // Use the user's record class to parse the line back in.
    userRecord.parse(val);
  } catch (RecordParser.ParseError pe) {
    LOG.error("Got parse error: " + pe.toString());
    throw new IOException(pe);
  }

  LOG.info("Mapper output line: " + userRecord.toString());

  out.collect(new Text(userRecord.toString()), NullWritable.get());

  if (!userRecord.toString(false).equals(val.toString())) {
    // Could not format record w/o end-of-record delimiter.
    throw new IOException("Returned string w/o EOR has value ["
        + userRecord.toString(false) + "] when ["
        + val.toString() + "] was expected.");
  }

  if (!userRecord.toString().equals(val.toString() + "\n")) {
    // misparsed.
    throw new IOException("Returned string has value ["
        + userRecord.toString() + "] when ["
        + val.toString() + "\n] was expected.");
  }
}
 
開發者ID:aliyun,項目名稱:aliyun-maxcompute-data-collectors,代碼行數:32,代碼來源:ReparseMapper.java

示例9: reduce

import org.apache.hadoop.mapred.OutputCollector; //導入方法依賴的package包/類
public void reduce(Object arg0, Iterator arg1, OutputCollector arg2, Reporter arg3) throws IOException {
  int count = 0;
  while (arg1.hasNext()) {
    count += 1;
    arg1.next();
  }
  arg2.collect(arg0, new Text("" + count));
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:9,代碼來源:ValueCountReduce.java

示例10: map

import org.apache.hadoop.mapred.OutputCollector; //導入方法依賴的package包/類
public void map(LongWritable key, HarEntry value,
    OutputCollector<IntWritable, Text> out,
    Reporter reporter) throws IOException {
  Path relPath = new Path(value.path);
  int hash = HarFileSystem.getHarHash(relPath);
  String towrite = null;
  Path srcPath = realPath(relPath, rootPath);
  long startPos = partStream.getPos();
  FileSystem srcFs = srcPath.getFileSystem(conf);
  FileStatus srcStatus = srcFs.getFileStatus(srcPath);
  String propStr = encodeProperties(srcStatus);
  if (value.isDir()) { 
    towrite = encodeName(relPath.toString())
              + " dir " + propStr + " 0 0 ";
    StringBuffer sbuff = new StringBuffer();
    sbuff.append(towrite);
    for (String child: value.children) {
      sbuff.append(encodeName(child) + " ");
    }
    towrite = sbuff.toString();
    //reading directories is also progress
    reporter.progress();
  }
  else {
    FSDataInputStream input = srcFs.open(srcStatus.getPath());
    reporter.setStatus("Copying file " + srcStatus.getPath() + 
        " to archive.");
    copyData(srcStatus.getPath(), input, partStream, reporter);
    towrite = encodeName(relPath.toString())
              + " file " + partname + " " + startPos
              + " " + srcStatus.getLen() + " " + propStr + " ";
  }
  out.collect(new IntWritable(hash), new Text(towrite));
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:35,代碼來源:HadoopArchives.java

示例11: runOperation

import org.apache.hadoop.mapred.OutputCollector; //導入方法依賴的package包/類
/**
 * Runs the given operation and reports on its results
 * 
 * @param op
 *          the operation to run
 * @param reporter
 *          the status reporter to notify
 * @param output
 *          the output to write to
 * @throws IOException
 */
private void runOperation(Operation op, Reporter reporter,
    OutputCollector<Text, Text> output, long opNum) throws IOException {
  if (op == null) {
    return;
  }
  logAndSetStatus(reporter, "Running operation #" + opNum + " (" + op + ")");
  List<OperationOutput> opOut = op.run(filesystem);
  logAndSetStatus(reporter, "Finished operation #" + opNum + " (" + op + ")");
  if (opOut != null && !opOut.isEmpty()) {
    for (OperationOutput outData : opOut) {
      output.collect(outData.getKey(), outData.getOutputValue());
    }
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:26,代碼來源:SliveMapper.java

示例12: map

import org.apache.hadoop.mapred.OutputCollector; //導入方法依賴的package包/類
public void map(K key, Text value,
                OutputCollector<Text, LongWritable> output,
                Reporter reporter)
  throws IOException {
  String text = value.toString();
  Matcher matcher = pattern.matcher(text);
  while (matcher.find()) {
    output.collect(new Text(matcher.group(group)), new LongWritable(1));
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:11,代碼來源:RegexMapper.java

示例13: reduce

import org.apache.hadoop.mapred.OutputCollector; //導入方法依賴的package包/類
@Override
public void reduce(Text key, Iterator<IntWritable> values,
    OutputCollector<Text, IntWritable> output, Reporter reporter)
    throws IOException {
  int sum = 0;
  while (values.hasNext()) {
    sum += values.next().get();
  }
  if (key.equals(OPEN_EXECTIME)){
    executionTime[OPEN] = sum;
  } else if (key.equals(NUMOPS_OPEN)){
    numOfOps[OPEN] = sum;
  } else if (key.equals(LIST_EXECTIME)){
    executionTime[LIST] = sum;
  } else if (key.equals(NUMOPS_LIST)){
    numOfOps[LIST] = sum;
  } else if (key.equals(DELETE_EXECTIME)){
    executionTime[DELETE] = sum;
  } else if (key.equals(NUMOPS_DELETE)){
    numOfOps[DELETE] = sum;
  } else if (key.equals(CREATE_EXECTIME)){
    executionTime[CREATE] = sum;
  } else if (key.equals(NUMOPS_CREATE)){
    numOfOps[CREATE] = sum;
  } else if (key.equals(WRITE_CLOSE_EXECTIME)){
    System.out.println(WRITE_CLOSE_EXECTIME + " = " + sum);
    executionTime[WRITE_CLOSE]= sum;
  } else if (key.equals(NUMOPS_WRITE_CLOSE)){
    numOfOps[WRITE_CLOSE] = sum;
  } else if (key.equals(TOTALOPS)){
    totalOps = sum;
  } else if (key.equals(ELAPSED_TIME)){
    totalTime = sum;
  }
  result.set(sum);
  output.collect(key, result);
  // System.out.println("Key = " + key + " Sum is =" + sum);
  // printResults(System.out);
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:40,代碼來源:LoadGeneratorMR.java

示例14: map

import org.apache.hadoop.mapred.OutputCollector; //導入方法依賴的package包/類
public void map(LongWritable key, Text value, 
                OutputCollector<Text, IntWritable> output, 
                Reporter reporter) throws IOException {
  String line = value.toString();
  StringTokenizer itr = new StringTokenizer(line);
  while (itr.hasMoreTokens()) {
    word.set(itr.nextToken());
    output.collect(word, one);
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:11,代碼來源:WordCount.java

示例15: reduce

import org.apache.hadoop.mapred.OutputCollector; //導入方法依賴的package包/類
public void reduce(Text key, Iterator<IntWritable> values,
                   OutputCollector<Text, IntWritable> output, 
                   Reporter reporter) throws IOException {
  int sum = 0;
  while (values.hasNext()) {
    sum += values.next().get();
  }
  output.collect(key, new IntWritable(sum));
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:10,代碼來源:WordCount.java


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