I've been trying to upgrade to Cascading 2 and have been hitting some issues. My canary-in-a-coal-mine is the Word Count example in the cascading documentation.
Here's the org.cascading.example.WordCount.java file that's pretty much a copy of the example in the documentation:
package org.cascading.example;
import cascading.flow.Flow;
import cascading.flow.FlowConnector;
import cascading.flow.hadoop.HadoopFlowConnector;
import cascading.operation.Aggregator;
import cascading.operation.Debug;
import cascading.operation.Function;
import cascading.operation.aggregator.Count;
import cascading.operation.regex.RegexGenerator;
import cascading.pipe.Each;
import cascading.pipe.Every;
import cascading.pipe.GroupBy;
import cascading.pipe.Pipe;
import cascading.property.AppProps;
import cascading.scheme.Scheme;
import cascading.scheme.hadoop.TextLine;
import cascading.tap.SinkMode;
import cascading.tap.Tap;
import cascading.tap.hadoop.Hfs;
import cascading.tuple.Fields;
import java.util.Properties;
public class WordCount {
protected static Flow createWorkflow(Tap source, Tap sink) {
Pipe assembly = new Pipe( "wordcount" );
String regex = "(?<!\\pL)(?=\\pL)[^ ]*(?<=\\pL)(?!\\pL)";
Function function = new RegexGenerator( new Fields( "word" ), regex );
assembly = new Each( assembly, new Fields( "line" ), function );
assembly = new Each( assembly, new Debug(Debug.Output.STDOUT) );
assembly = new GroupBy( assembly, new Fields( "word" ) );
Aggregator count = new Count( new Fields( "count" ) );
assembly = new Every( assembly, count );
Properties properties = new Properties();
AppProps.setApplicationJarClass(properties, WordCount.class);
FlowConnector flowConnector = new HadoopFlowConnector(properties);
Flow flow = flowConnector.connect( "word-count", source, sink, assembly );
return flow;
}
public static void main(String[] args) {
String inputPath = args[0];
String outputPath = args[1];
Scheme sourceScheme = new TextLine( new Fields( "line" ) );
Tap source = new Hfs( sourceScheme, inputPath );
Scheme sinkScheme = new TextLine( new Fields( "word", "count" ) );
Tap sink = new Hfs( sinkScheme, outputPath, SinkMode.REPLACE );
Flow flow = createWorkflow(source, sink);
flow.complete();
//flow.writeDOT("build/flow.dot");
}
}
package org.cascading.example
import cascading.CascadingTestCase
import cascading.tap.Tap
import cascading.flow.Flow
import cascading.tuple.TupleEntryIterator
import cascading.tap.hadoop.Lfs
import cascading.scheme.local.TextLine
class WordCountTests extends CascadingTestCase {
String outputPath = "build/test/output/wordcount/";
public WordCountTests() {
super( "word count tests" );
}
public void testWordCountTinyDoc() throws IOException {
String contents = """
The Lazy Dog Jumped
Over The Lazy Dog
"""
Tap source = new Lfs( new TextLine(), createTempFile(contents))
Tap sink = new Lfs( new TextLine(), outputPath + "tinyDoc", true )
Flow flow = WordCount.createWorkflow(source, sink) // THIS IS THE LINE THATS FAILING IN THE TEST
flow.complete();
//flow.writeDOT("build/wordCountFlow.dot")
validateLength(flow, 5)
Map results = flowResultsMap(flow)
results.The == ["2"]
results.Lazy == ["2"]
results.Dog == ["2"]
results.Jumped == ["1"]
results.Over == ["1"]
}
String createTempFile(String contents, String name = "tempfile", String extension = ".txt") {
File file = File.createTempFile(name, extension)
file.deleteOnExit()
file << contents
return file.absolutePath
}
Map flowResultsMap(flow) {
TupleEntryIterator iterator = flow.openSink()
return iterator.inject([:]) { map, result ->
def fields = result.get(1).split("\t")
map[fields[0]] = fields[1..-1]
return map
}
}
}