cascading helloworld 案例

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值