在本地模式下运行简单的级联应用程序

时间:2012-09-25 18:30:28

标签: java hadoop cascading

我是Cascading / Hadoop的新手,我试图在本地模式(即内存)中运行一个简单的例子。该示例只复制文件:

    import java.util.Properties;

    import cascading.flow.Flow;
    import cascading.flow.FlowConnector;
    import cascading.flow.FlowDef;
    import cascading.flow.local.LocalFlowConnector;
    import cascading.pipe.Pipe;
    import cascading.property.AppProps;
    import cascading.scheme.hadoop.TextLine;
    import cascading.tap.Tap;
    import cascading.tap.hadoop.Hfs;

    public class CascadingTest {

            public static void main(String[] args) {
                Properties properties = new Properties();


                AppProps.setApplicationJarClass( properties, CascadingTest.class );
                FlowConnector flowConnector = new LocalFlowConnector();

                // create the source tap
                Tap inTap = new Hfs( new TextLine(), "D:\\git_workspace\\Impatient\\part1\\data\\rain.txt" );

            // create the sink tap
            Tap outTap = new Hfs( new TextLine(), "D:\\git_workspace\\Impatient\\part1\\data\\out.txt" );

            // specify a pipe to connect the taps
            Pipe copyPipe = new Pipe( "copy" );

            // connect the taps, pipes, etc., into a flow
            FlowDef flowDef = FlowDef.flowDef()
                .addSource( copyPipe, inTap )
                .addTailSink( copyPipe, outTap );

                // run the flow
            Flow flow = flowConnector.connect( flowDef );
            flow.complete();
        }
    }

这是我得到的错误:

09-25-12 11:30:38,114 INFO  - AppProps                     - using app.id: 9C82C76AC667FDAA2F6969A0DF3949C6
Exception in thread "main" cascading.flow.planner.PlannerException: could not build flow from assembly: [java.util.Properties cannot be cast to org.apache.hadoop.mapred.JobConf]
    at cascading.flow.planner.FlowPlanner.handleExceptionDuringPlanning(FlowPlanner.java:515)
    at cascading.flow.local.planner.LocalPlanner.buildFlow(LocalPlanner.java:84)
    at cascading.flow.FlowConnector.connect(FlowConnector.java:454)
    at com.x.y.CascadingTest.main(CascadingTest.java:37)
Caused by: java.lang.ClassCastException: java.util.Properties cannot be cast to org.apache.hadoop.mapred.JobConf
    at cascading.tap.hadoop.Hfs.sourceConfInit(Hfs.java:78)
    at cascading.flow.local.LocalFlowStep.initTaps(LocalFlowStep.java:77)
    at cascading.flow.local.LocalFlowStep.getInitializedConfig(LocalFlowStep.java:56)
    at cascading.flow.local.LocalFlowStep.createFlowStepJob(LocalFlowStep.java:135)
    at cascading.flow.local.LocalFlowStep.createFlowStepJob(LocalFlowStep.java:38)
    at cascading.flow.planner.BaseFlowStep.getFlowStepJob(BaseFlowStep.java:588)
    at cascading.flow.BaseFlow.initializeNewJobsMap(BaseFlow.java:1162)
    at cascading.flow.BaseFlow.initialize(BaseFlow.java:184)
    at cascading.flow.local.planner.LocalPlanner.buildFlow(LocalPlanner.java:78)
    ... 2 more

3 个答案:

答案 0 :(得分:4)

只是提供更多细节:您不能在Cascading中混合local和hadoop类,因为它们假设不同且不兼容的环境。在您的情况下发生的是您尝试使用hadoop点击创建本地流,后者期望使用hadoop JobConf而不是用于配置本地点击的Properties对象。

如果您使用cascading.tap.local.FileTap代替cascading.tap.hadoop.Hfs,则您的代码将有效。

答案 1 :(得分:1)

欢迎来到Cascading -

我刚刚回答了级联用户列表,但简而言之,问题是本地和Hadoop模式类的混合。这段代码有LocalFlowConnector,但后来使用了Hfs水龙头。

当我恢复到“不耐烦”教程中使用的类时,它会正确运行:  https://gist.github.com/3784194

答案 2 :(得分:0)

是的,您需要使用LFS(本地文件系统)点击而不是HFS(Hadoop文件系统)。

此外,您可以使用Junit测试用例(使用cascading-unittest jar)在本地模式下/来自eclipse来测试您的代码。

http://www.cascading.org/2012/08/07/cascading-for-the-impatient-part-6/