Skip to content

Instantly share code, notes, and snippets.

@cb372
Created January 17, 2013 10:01
Show Gist options
  • Save cb372/4554987 to your computer and use it in GitHub Desktop.
Save cb372/4554987 to your computer and use it in GitHub Desktop.
Example of using Flume HDFS sink with a custom SeqFileFormatter.
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