org.apache.hadoop.mapreduce.OutputFormat.getRecordWriter()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(8.7k)|赞(0)|评价(0)|浏览(95)

本文整理了Java中org.apache.hadoop.mapreduce.OutputFormat.getRecordWriter()方法的一些代码示例,展示了OutputFormat.getRecordWriter()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。OutputFormat.getRecordWriter()方法的具体详情如下:
包路径:org.apache.hadoop.mapreduce.OutputFormat
类名称:OutputFormat
方法名:getRecordWriter

OutputFormat.getRecordWriter介绍

[英]Get the RecordWriter for the given task.
[中]获取给定任务的RecordWriter。

代码示例

代码示例来源:origin: apache/hive

/**
 * Get the record writer for the job. This uses the StorageHandler's default 
 * OutputFormat to get the record writer.
 * @param context the information about the current task
 * @return a RecordWriter to write the output for the job
 * @throws IOException
 * @throws InterruptedException
 */
@Override
public RecordWriter<WritableComparable<?>, HCatRecord>
getRecordWriter(TaskAttemptContext context)
 throws IOException, InterruptedException {
 return getOutputFormat(context).getRecordWriter(context);
}

代码示例来源:origin: apache/hive

public MultiRecordWriter(TaskAttemptContext context) throws IOException,
  InterruptedException {
 baseRecordWriters = new LinkedHashMap<String, BaseRecordWriterContainer>();
 String[] aliases = getOutputFormatAliases(context);
 for (String alias : aliases) {
  LOGGER.info("Creating record writer for alias: " + alias);
  TaskAttemptContext aliasContext = getTaskAttemptContext(alias, context);
  Configuration aliasConf = aliasContext.getConfiguration();
  // Create output directory if not already created.
  String outDir = aliasConf.get("mapred.output.dir");
  if (outDir != null) {
   Path outputDir = new Path(outDir);
   FileSystem fs = outputDir.getFileSystem(aliasConf);
   if (!fs.exists(outputDir)) {
    fs.mkdirs(outputDir);
   }
  }
  OutputFormat<?, ?> outputFormat = getOutputFormatInstance(aliasContext);
  baseRecordWriters.put(alias,
    new BaseRecordWriterContainer(outputFormat.getRecordWriter(aliasContext),
      aliasContext));
 }
}

代码示例来源:origin: apache/avro

@SuppressWarnings("unchecked")
private synchronized RecordWriter getRecordWriter(
  TaskAttemptContext taskContext, String baseFileName)
  throws IOException, InterruptedException {
 // look for record-writer in the cache
 RecordWriter writer = recordWriters.get(baseFileName);
 // If not in cache, create a new one
 if (writer == null) {
  // get the record writer from context output format
  //FileOutputFormat.setOutputName(taskContext, baseFileName);
  taskContext.getConfiguration().set("avro.mo.config.namedOutput",baseFileName);
  try {
   writer = ((OutputFormat) ReflectionUtils.newInstance(
    taskContext.getOutputFormatClass(), taskContext.getConfiguration()))
    .getRecordWriter(taskContext);
  } catch (ClassNotFoundException e) {
   throw new IOException(e);
  }
  // if counters are enabled, wrap the writer with context
  // to increment counters
  if (countersEnabled) {
   writer = new RecordWriterWithCounter(writer, baseFileName, context);
  }
  // add the record-writer to the cache
  recordWriters.put(baseFileName, writer);
 }
 return writer;
}

代码示例来源:origin: elastic/elasticsearch-hadoop

@Override
public RecordWriter getRecordWriter(TaskAttemptContext context) throws IOException, InterruptedException {
  List<OutputFormat> formats = getNewApiFormats(CompatHandler.taskAttemptContext(context).getConfiguration());
  List<RecordWriter> writers = new ArrayList<RecordWriter>();
  for (OutputFormat format : formats) {
    writers.add(format.getRecordWriter(context));
  }
  return new MultiNewRecordWriter(writers);
}

代码示例来源:origin: apache/flink

this.recordWriter = this.mapreduceOutputFormat.getRecordWriter(this.context);
} catch (InterruptedException e) {
  throw new IOException("Could not create RecordWriter.", e);

代码示例来源:origin: apache/flink

@Test
public void testOpen() throws Exception {
  OutputFormat<String, Long> dummyOutputFormat = mock(DummyOutputFormat.class);
  OutputCommitter outputCommitter = setupOutputCommitter(true);
  when(dummyOutputFormat.getOutputCommitter(any(TaskAttemptContext.class))).thenReturn(outputCommitter);
  HadoopOutputFormat<String, Long> hadoopOutputFormat = setupHadoopOutputFormat(dummyOutputFormat,
    Job.getInstance(), new DummyRecordWriter(), setupOutputCommitter(true), new Configuration());
  hadoopOutputFormat.open(1, 4);
  verify(hadoopOutputFormat.outputCommitter, times(1)).setupJob(any(JobContext.class));
  verify(hadoopOutputFormat.mapreduceOutputFormat, times(1)).getRecordWriter(any(TaskAttemptContext.class));
}

代码示例来源:origin: apache/ignite

/**
 * Put write into Hadoop context and return associated output format instance.
 *
 * @param jobCtx Job context.
 * @return Output format.
 * @throws IgniteCheckedException In case of Grid exception.
 * @throws InterruptedException In case of interrupt.
 */
protected OutputFormat prepareWriter(JobContext jobCtx)
  throws IgniteCheckedException, InterruptedException {
  try {
    OutputFormat outputFormat = getOutputFormat(jobCtx);
    assert outputFormat != null;
    OutputCommitter outCommitter = outputFormat.getOutputCommitter(hadoopCtx);
    if (outCommitter != null)
      outCommitter.setupTask(hadoopCtx);
    RecordWriter writer = outputFormat.getRecordWriter(hadoopCtx);
    hadoopCtx.writer(writer);
    return outputFormat;
  }
  catch (IOException | ClassNotFoundException e) {
    throw new IgniteCheckedException(e);
  }
}

代码示例来源:origin: io.hops/hadoop-mapreduce-client-core

@Override
public void write(K key, V value) throws IOException, InterruptedException {
 if (rawWriter == null) {
  rawWriter = outputFormat.getRecordWriter(taskContext);
 }
 rawWriter.write(key, value);
}

代码示例来源:origin: org.apache.hadoop/hadoop-mapred

@Override
public RecordWriter<K, V> getRecordWriter(TaskAttemptContext context) 
throws IOException, InterruptedException {
 return getBaseOut().getRecordWriter(context);
}

代码示例来源:origin: io.hops/hadoop-mapreduce-client-core

@Override
public RecordWriter<K, V> getRecordWriter(TaskAttemptContext context) 
throws IOException, InterruptedException {
 return getBaseOut().getRecordWriter(context);
}

代码示例来源:origin: com.github.jiayuhan-it/hadoop-mapreduce-client-core

@Override
public void write(K key, V value) throws IOException, InterruptedException {
 if (rawWriter == null) {
  rawWriter = outputFormat.getRecordWriter(taskContext);
 }
 rawWriter.write(key, value);
}

代码示例来源:origin: org.apache.hadoop/hadoop-mapred

@Override
public void write(K key, V value) throws IOException, InterruptedException {
 if (rawWriter == null) {
  rawWriter = outputFormat.getRecordWriter(taskContext);
 }
 rawWriter.write(key, value);
}

代码示例来源:origin: ch.cern.hadoop/hadoop-mapreduce-client-core

@Override
public RecordWriter<K, V> getRecordWriter(TaskAttemptContext context) 
throws IOException, InterruptedException {
 return getBaseOut().getRecordWriter(context);
}

代码示例来源:origin: org.apache.hadoop/hadoop-mapred

@SuppressWarnings("unchecked")
NewDirectOutputCollector(MRJobConfig jobContext,
  JobConf job, TaskUmbilicalProtocol umbilical, TaskReporter reporter) 
throws IOException, ClassNotFoundException, InterruptedException {
 this.reporter = reporter;
 out = outputFormat.getRecordWriter(taskContext);
 mapOutputRecordCounter = 
  reporter.getCounter(TaskCounter.MAP_OUTPUT_RECORDS);
}

代码示例来源:origin: io.prestosql.hadoop/hadoop-apache

@Override
public void write(K key, V value) throws IOException, InterruptedException {
 if (rawWriter == null) {
  rawWriter = outputFormat.getRecordWriter(taskContext);
 }
 rawWriter.write(key, value);
}

代码示例来源:origin: datasalt/pangool

@Override
public RecordWriter getRecordWriter(TaskAttemptContext context) throws IOException,
  InterruptedException {
  instantiateWhenNeeded();
  return instance.getRecordWriter(context);
}

代码示例来源:origin: org.elasticsearch/elasticsearch-spark-13

@Override
public RecordWriter getRecordWriter(TaskAttemptContext context) throws IOException, InterruptedException {
  List<OutputFormat> formats = getNewApiFormats(CompatHandler.taskAttemptContext(context).getConfiguration());
  List<RecordWriter> writers = new ArrayList<RecordWriter>();
  for (OutputFormat format : formats) {
    writers.add(format.getRecordWriter(context));
  }
  return new MultiNewRecordWriter(writers);
}

代码示例来源:origin: org.elasticsearch/elasticsearch-spark

@Override
public RecordWriter getRecordWriter(TaskAttemptContext context) throws IOException, InterruptedException {
  List<OutputFormat> formats = getNewApiFormats(CompatHandler.taskAttemptContext(context).getConfiguration());
  List<RecordWriter> writers = new ArrayList<RecordWriter>();
  for (OutputFormat format : formats) {
    writers.add(format.getRecordWriter(context));
  }
  return new MultiNewRecordWriter(writers);
}

代码示例来源:origin: org.elasticsearch/elasticsearch-hadoop-mr

@Override
public RecordWriter getRecordWriter(TaskAttemptContext context) throws IOException, InterruptedException {
  List<OutputFormat> formats = getNewApiFormats(CompatHandler.taskAttemptContext(context).getConfiguration());
  List<RecordWriter> writers = new ArrayList<RecordWriter>();
  for (OutputFormat format : formats) {
    writers.add(format.getRecordWriter(context));
  }
  return new MultiNewRecordWriter(writers);
}

代码示例来源:origin: co.cask.hydrator/format-common

@Override
public RecordWriter<NullWritable, StructuredRecord> getRecordWriter(TaskAttemptContext context)
 throws IOException, InterruptedException {
 RecordWriter<K, V> delegateWriter = getDelegate().getRecordWriter(context);
 return new DelegatingRecordWriter<>(delegateWriter, getConversion(context));
}

相关文章