forked from LinkedInAttic/camus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request LinkedInAttic#15 from smeder/camus-kafka-0.8
Add support for other serialization formats. You'll have to implement th...
- Loading branch information
Showing
10 changed files
with
230 additions
and
182 deletions.
There are no files selected for viewing
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
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
20 changes: 20 additions & 0 deletions
20
camus-api/src/main/java/com/linkedin/camus/etl/RecordWriterProvider.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.linkedin.camus.etl; | ||
|
||
import com.linkedin.camus.coders.CamusWrapper; | ||
import java.io.IOException; | ||
import org.apache.hadoop.mapreduce.RecordWriter; | ||
import org.apache.hadoop.mapreduce.TaskAttemptContext; | ||
import org.apache.hadoop.mapreduce.lib.output.FileOutputCommitter; | ||
|
||
/** | ||
* | ||
* | ||
*/ | ||
public interface RecordWriterProvider { | ||
|
||
String getFilenameExtension(); | ||
|
||
RecordWriter<IEtlKey, CamusWrapper> getDataRecordWriter( | ||
TaskAttemptContext context, String fileName, CamusWrapper data, FileOutputCommitter committer) throws IOException, | ||
InterruptedException; | ||
} |
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
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
67 changes: 67 additions & 0 deletions
67
...etl-kafka/src/main/java/com/linkedin/camus/etl/kafka/common/AvroRecordWriterProvider.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package com.linkedin.camus.etl.kafka.common; | ||
|
||
import com.linkedin.camus.coders.CamusWrapper; | ||
import com.linkedin.camus.etl.IEtlKey; | ||
import com.linkedin.camus.etl.RecordWriterProvider; | ||
import com.linkedin.camus.etl.kafka.mapred.EtlMultiOutputFormat; | ||
import java.io.IOException; | ||
import org.apache.avro.file.CodecFactory; | ||
import org.apache.avro.file.DataFileWriter; | ||
import org.apache.avro.generic.GenericRecord; | ||
import org.apache.avro.specific.SpecificDatumWriter; | ||
import org.apache.hadoop.fs.Path; | ||
import org.apache.hadoop.mapreduce.RecordWriter; | ||
import org.apache.hadoop.mapreduce.TaskAttemptContext; | ||
import org.apache.hadoop.mapreduce.lib.output.FileOutputCommitter; | ||
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat; | ||
|
||
/** | ||
* | ||
* | ||
*/ | ||
public class AvroRecordWriterProvider implements RecordWriterProvider { | ||
public final static String EXT = ".avro"; | ||
|
||
@Override | ||
public String getFilenameExtension() { | ||
return EXT; | ||
} | ||
|
||
@Override | ||
public RecordWriter<IEtlKey, CamusWrapper> getDataRecordWriter( | ||
TaskAttemptContext context, | ||
String fileName, | ||
CamusWrapper data, | ||
FileOutputCommitter committer) throws IOException, InterruptedException { | ||
final DataFileWriter<Object> writer = new DataFileWriter<Object>( | ||
new SpecificDatumWriter<Object>()); | ||
|
||
if (FileOutputFormat.getCompressOutput(context)) { | ||
if ("snappy".equals(EtlMultiOutputFormat.getEtlOutputCodec(context))) { | ||
writer.setCodec(CodecFactory.snappyCodec()); | ||
} else { | ||
int level = EtlMultiOutputFormat.getEtlDeflateLevel(context); | ||
writer.setCodec(CodecFactory.deflateCodec(level)); | ||
} | ||
} | ||
|
||
Path path = committer.getWorkPath(); | ||
path = new Path(path, EtlMultiOutputFormat.getUniqueFile(context, fileName, EXT)); | ||
writer.create(((GenericRecord) data.getRecord()).getSchema(), | ||
path.getFileSystem(context.getConfiguration()).create(path)); | ||
|
||
writer.setSyncInterval(EtlMultiOutputFormat.getEtlAvroWriterSyncInterval(context)); | ||
|
||
return new RecordWriter<IEtlKey, CamusWrapper>() { | ||
@Override | ||
public void write(IEtlKey ignore, CamusWrapper data) throws IOException { | ||
writer.append(data.getRecord()); | ||
} | ||
|
||
@Override | ||
public void close(TaskAttemptContext arg0) throws IOException, InterruptedException { | ||
writer.close(); | ||
} | ||
}; | ||
} | ||
} |
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
Oops, something went wrong.