hel*_*lol 4 hadoop flow mapreduce cascading
我正在使用Cascading 2创建Hadoop作业,并尝试创建一个以单一来源开头的流程.后一对夫妇的功能被应用到数据I需要使得该数据被用于创建两个单独的报告(在两个单独的接收器)来分割的流动.
//SOURCE
Scheme sourceScheme = new TextLine( new Fields( "line" ) );
Tap source = new Hfs( sourceScheme, input );
//REPORT1 SINK
Scheme report1SinkScheme = new TextDelimited( Fields.ALL, ",","\"" );
Tap report1Sink = new Hfs( report1SinkScheme, output1, SinkMode.REPLACE );
//REPORT2 SINK
Scheme report2SinkScheme = new TextDelimited( Fields.ALL, ",","\"" );
Tap report2Sink = new Hfs( report2SinkScheme, output2, SinkMode.REPLACE );
//INITIAL FUNCTIONS
Pipe firstPipe = new Pipe("firstPipe");
firstPipe = new Each(firstPipe, new Fields("line"), functionA);
firstPipe = new Each(firstPipe, functionB, Fields.ALL);
//REPORT1 FUNCTION
report1Pipe = new Each(firstPipe, Fields.ALL, function1, Fields.RESULTS);
//REPORT2 FUNCTION
report2Pipe = new Each(firstPipe, Fields.ALL, function2, Fields.RESULTS);
//CONNECT FLOW PARTS
FlowDef flowDef = new FlowDef()
.setName("report-flow")
.addSource(firstPipe, source)
.addSink(report1Pipe, report1Sink)
.addSink(report2Pipe, report2Sink);
new HadoopFlowConnector( properties ).connect( flowDef ).complete();
Run Code Online (Sandbox Code Playgroud)
目前这给了我错误"java.lang.IllegalArgumentException:不能添加重复的sink:firstPipe",但即使在搞乱它一段时间后,我还得到了与流设置有关的各种其他问题.
有人可以解释如何构建这种形式的流(一个源,两个接收器)吗?我需要创建一个Cascade吗?或者在拆分之前是否需要中间接收器来保存数据?
请帮忙!
您可以使用级联文档中提到的拆分模式.这是一个例子:
public static void main(String[] args) {
// source and sink
Scheme sourceScheme = new TextLine(new Fields("line"));
Tap source = new FileTap(sourceScheme, args[0]);
Fields sinkFields = new Fields("word", "count");
Scheme sinkScheme = new TextLine(sinkFields, sinkFields);
Tap sink_one = new FileTap(sinkScheme, "out-one.txt");
Tap sink_two = new FileTap(sinkScheme, "out-two.txt");
// the pipe assembly
Pipe assembly = new Pipe("wordcount");
String regex = "\\w+";
Function function = new RegexGenerator(new Fields("word"), regex);
assembly = new Each(assembly, new Fields("line"), function);
Aggregator count = new Count(new Fields("count"));
// ...split into two pipes
Pipe countOne = new Pipe("count-one", assembly);
countOne = new GroupBy(countOne, new Fields("word"));
countOne = new Every(countOne, count);
Pipe countTwo = new Pipe("count-two", assembly);
countTwo = new GroupBy(countTwo, new Fields("word"));
countTwo = new Every(countTwo, count);
// create the flow
final List<Pipe> pipes = new ArrayList<Pipe>(2);
pipes.add(countOne);
pipes.add(countTwo);
final Map<String, Tap> sinks = new HashMap<String, Tap>();
sinks.put("count-one", sink_one);
sinks.put("count-two", sink_two);
FlowConnector flowConnector = new LocalFlowConnector();
Flow flow = flowConnector.connect(source, sinks, pipes);
flow.complete();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5336 次 |
| 最近记录: |