Skip to content

Instantly share code, notes, and snippets.

@jaysoo
Created February 10, 2012 15:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaysoo/1790173 to your computer and use it in GitHub Desktop.
Save jaysoo/1790173 to your computer and use it in GitHub Desktop.
A text-delimited scheme for Cascading that will include the header (field names) in the output.
// imports
public class TextDelimitedWithHeader extends TextDelimited {
// ...
@SuppressWarnings("unchecked")
public void sinkPrepare(HadoopFlowProcess flowProcess, SinkCall<Object[], OutputCollector> sinkCall) {
super.sinkPrepare(flowProcess, sinkCall);
Fields fields = this.getSinkFields();
Tuple tuple = new Tuple();
for(int i = 0; i < fields.size(); i++)
tuple.add(fields.get(i));
try {
sinkCall.getOutput().collect(null, tuple);
} catch(IOException e) {
throw new IllegalStateException("failed to write header");
}
}
@SuppressWarnings("unchecked")
public void sinkPrepare(HadoopFlowProcess flowProcess, SinkCall<Object[], OutputCollector> sinkCall) {
super.sinkPrepare(flowProcess, sinkCall);
Fields fields = this.getSinkFields();
Tuple tuple = new Tuple();
for(int i = 0; i < fields.size(); i++)
tuple.add(fields.get(i));
try {
sinkCall.getOutput().collect(null, tuple);
} catch(IOException e) {
throw new IllegalStateException("failed to write header");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment