org.apache.avro.mapreduce.AvroKeyRecordReader Java Examples

The following examples show how to use org.apache.avro.mapreduce.AvroKeyRecordReader. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DelegatingAvroKeyInputFormat.java    From incubator-pinot with Apache License 2.0 6 votes vote down vote up
public org.apache.hadoop.mapreduce.RecordReader<org.apache.avro.mapred.AvroKey<T>, NullWritable> createRecordReader(
    InputSplit split, TaskAttemptContext context) throws IOException, InterruptedException {
  LOGGER.info("DelegatingAvroKeyInputFormat.createRecordReader()  for split:{}", split);
  FileSplit fileSplit = (FileSplit) split;
  Configuration configuration = context.getConfiguration();
  String sourceName = getSourceNameFromPath(fileSplit, configuration);
  LOGGER.info("Source Name for path {} : {}", fileSplit.getPath(), sourceName);
  Map<String, String> schemaJSONMapping = new ObjectMapper()
      .readValue(configuration.get("schema.json.mapping"), MAP_STRING_STRING_TYPE);

  LOGGER.info("Schema JSON Mapping: {}", schemaJSONMapping);

  String sourceSchemaJSON = schemaJSONMapping.get(sourceName);

  Schema schema = new Schema.Parser().parse(sourceSchemaJSON);
  return new AvroKeyRecordReader<T>(schema);
}
 
Example #2
Source File: DelegatingAvroKeyInputFormat.java    From incubator-pinot with Apache License 2.0 6 votes vote down vote up
public org.apache.hadoop.mapreduce.RecordReader<org.apache.avro.mapred.AvroKey<T>, NullWritable> createRecordReader(
    InputSplit split, TaskAttemptContext context) throws IOException, InterruptedException {
  LOGGER.info("DelegatingAvroKeyInputFormat.createRecordReader()  for split:{}", split);
  FileSplit fileSplit = (FileSplit) split;
  Configuration configuration = context.getConfiguration();
  String sourceName = getSourceNameFromPath(fileSplit, configuration);
  LOGGER.info("Source Name for path {} : {}", fileSplit.getPath(), sourceName);
  Map<String, String> schemaJSONMapping = new ObjectMapper()
      .readValue(configuration.get("schema.json.mapping"), MAP_STRING_STRING_TYPE);

  LOGGER.info("Schema JSON Mapping: {}", schemaJSONMapping);

  String sourceSchemaJSON = schemaJSONMapping.get(sourceName);

  Schema schema = new Schema.Parser().parse(sourceSchemaJSON);
  return new AvroKeyRecordReader<T>(schema);
}
 
Example #3
Source File: AvroMultipleInputsKeyInputFormat.java    From datafu with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public RecordReader<AvroKey<T>, NullWritable> createRecordReader(
    InputSplit split, TaskAttemptContext context) throws IOException, InterruptedException 
{    
  Schema readerSchema = AvroMultipleInputsUtil.getInputKeySchemaForSplit(context.getConfiguration(), split);
  if (readerSchema == null)
  {
    throw new RuntimeException("Could not determine input schema");
  }
  return new AvroKeyRecordReader<T>(readerSchema);
}