Created
November 2, 2012 06:06
-
-
Save baunz/3998986 to your computer and use it in GitHub Desktop.
Avro Input Job
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Licensed to the Apache Software Foundation (ASF) under one | |
* or more contributor license agreements. See the NOTICE file | |
* distributed with this work for additional information | |
* regarding copyright ownership. The ASF licenses this file | |
* to you under the Apache License, Version 2.0 (the | |
* "License"); you may not use this file except in compliance | |
* with the License. You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* Unless required by applicable law or agreed to in writing, software | |
* distributed under the License is distributed on an "AS IS" BASIS, | |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
* See the License for the specific language governing permissions and | |
* limitations under the License. | |
*/ | |
package org.apache.avro.mapred; | |
import java.io.IOException; | |
import org.apache.hadoop.io.NullWritable; | |
import org.apache.hadoop.mapred.JobConf; | |
import org.apache.hadoop.mapred.FileSplit; | |
import org.apache.hadoop.mapred.RecordReader; | |
import org.apache.avro.file.FileReader; | |
import org.apache.avro.file.DataFileReader; | |
import org.apache.avro.specific.SpecificDatumReader; | |
import org.apache.avro.reflect.ReflectDatumReader; | |
/** An {@link RecordReader} for Avro data files. */ | |
public class AvroRecordReader<T> | |
implements RecordReader<AvroWrapper<T>, NullWritable> { | |
private FileReader<T> reader; | |
private long start; | |
private long end; | |
public AvroRecordReader(JobConf job, FileSplit split) | |
throws IOException { | |
this(DataFileReader.openReader | |
(new FsInput(split.getPath(), job), | |
job.getBoolean(AvroJob.INPUT_IS_REFLECT, false) | |
? new ReflectDatumReader<T>(AvroJob.getInputSchema(job)) | |
: new SpecificDatumReader<T>(AvroJob.getInputSchema(job))), | |
split); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package de.xplosion.ds.xpredict.avro; | |
import java.io.IOException; | |
import org.apache.avro.generic.GenericRecord; | |
import org.apache.avro.mapred.AvroInputFormat; | |
import org.apache.avro.mapred.AvroWrapper; | |
import org.apache.hadoop.io.NullWritable; | |
import org.apache.hadoop.mapred.FileSplit; | |
import org.apache.hadoop.mapred.InputSplit; | |
import org.apache.hadoop.mapred.JobConf; | |
import org.apache.hadoop.mapred.RecordReader; | |
import org.apache.hadoop.mapred.Reporter; | |
public class FlexibleAvroInputFormat extends AvroInputFormat<GenericRecord> { | |
@Override | |
public RecordReader<AvroWrapper<GenericRecord>, NullWritable> getRecordReader(InputSplit split, | |
JobConf job, Reporter reporter) throws IOException { | |
reporter.setStatus(split.toString()); | |
return new GenericAvroRecordReader(job, (FileSplit) split); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package de.xplosion.ds.xpredict.avro; | |
import java.io.IOException; | |
import org.apache.avro.file.DataFileReader; | |
import org.apache.avro.generic.GenericDatumReader; | |
import org.apache.avro.generic.GenericRecord; | |
import org.apache.avro.mapred.AvroRecordReader; | |
import org.apache.avro.mapred.FsInput; | |
import org.apache.hadoop.mapred.FileSplit; | |
import org.apache.hadoop.mapred.JobConf; | |
public class GenericAvroRecordReader extends AvroRecordReader<GenericRecord> { | |
public GenericAvroRecordReader(JobConf job, FileSplit split) throws IOException { | |
super(DataFileReader.openReader( | |
new FsInput(split.getPath(), job), | |
new GenericDatumReader<GenericRecord>()), | |
split); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment