cascading helloworld 案例

来源:互联网 发布:游戏原画 培训 知乎 编辑:程序博客网 时间:2024/06/10 17:17

Cascading是一个数据处理的API和查询处理计划,用于定义,共享数据处理工作流,还能在单一计算节点或分布式计算集群上执行数据处理工作流。在单一计算节点,Cascading的本地模式(local mode)可以在部署到集群之前,用于测试代码和处理本地文件。在一个部署了Apache Hadoop的分布式计算集群上,Cascading在hadoop API上增加了一个抽象层,大大简化了Hadoop 应用程序的开发,job的创建和调度。

话不多说直接上代码:

package cascading.project;import java.util.Properties;import cascading.flow.FlowDef;import cascading.flow.hadoop2.Hadoop2MR1FlowConnector;import cascading.pipe.Pipe;import cascading.property.AppProps;import cascading.scheme.hadoop.TextDelimited;import cascading.tap.Tap;import cascading.tap.hadoop.Hfs;/** * A Hello World example app that copies data from one location to another. * <p/> * It assumes the input files are TSV with headers on the first line. */public class MainHadoop  {  public static void main( String[] args )    {    String inPath = args[ 0 ];//输入路径    String outPath = args[ 1 ];//输出路径    Properties properties = new Properties();//设置运行过程中需要的参数 比如reduce的个数等    AppProps.setApplicationJarClass( properties, MainHadoop.class );//main函数    Hadoop2MR1FlowConnector flowConnector = new Hadoop2MR1FlowConnector( properties );//调用mapreduce包装接口    // create the source tap 使用tap包装输入路径    Tap inTap = new Hfs( new TextDelimited( true, "\t" ), inPath );    // create the sink tap使用tap包装输出路径    Tap outTap = new Hfs( new TextDelimited( true, "\t" ), outPath );    // specify a pipe to connect the taps 在输入tap和输出tap之间建立管道    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 运行mapreduce流    flowConnector.connect( flowDef ).complete();    }  }

代码的GitHub地址:https://github.com/Cascading/ProjectTemplate

原创粉丝点击