Created
January 17, 2013 10:01
-
-
Save cb372/4554987 to your computer and use it in GitHub Desktop.
Example of using Flume HDFS sink with a custom SeqFileFormatter.
This file contains hidden or 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 com.foo; | |
import org.apache.flume.Context; | |
import org.apache.flume.Event; | |
import org.apache.flume.sink.hdfs.SeqFileFormatter; | |
import org.apache.flume.sink.hdfs.SeqFileFormatter.Record; | |
public class MyFormatter implements SeqFileFormatter { | |
@Override | |
public Class<?> getKeyClass() { return Long.class; } | |
@Override | |
public Class<?> getValueClass() { return String.class; } | |
public Iterable<Record> format(Event event) { | |
Long key = extractTweetId(event); // TODO implement this | |
String value = toXml(event); // TODO implement this | |
return Collections.singletonList(new Record(key, value)); | |
} | |
public static class Builder implements SeqFileFormatter.Builder { | |
@Override | |
public SeqFileFormatter build(Context context) { | |
// TODO: If you want, you can extract configuration parameters | |
// from the context and pass them to your formatter. | |
return new MyFormatter(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment