Flink进阶---12常用的Source和Connector

主要介绍Flink中支持得Source和常用的Connector。

Flink 自身实现了多种 Source 和 Connector 方法,并且还提供了多种与第三方系统进行对接的 Connector。

预定义和自定义Source
在基础04中Flink常用的 DataSet 和 DataStream API中提到过几种Flink已经实现的新建DataStream方法。
基于文件:
我们在本地环境进行测试时可以方便地从本地文件读取数据:

ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

// read text file from local files system

DataSet<String> localLines = env.readTextFile("file:///path/to/my/textfile");

// read text file from an HDFS running at nnHost:nnPort

DataSet<String> hdfsLines = env.readTextFile("hdfs://nnHost:nnPort/path/to/my/textfile");

// read a CSV file with three fields

DataSet<Tuple3<Integer, String, Double>> csvInput = env.readCsvFile("hdfs:///the/CSV/file")

	                       .types(Integer.class, String.class, Double.class);

// read a CSV file with five fields, taking only two of them

DataSet<Tuple2<String, Double>> csvInput = env.readCsvFile("hdfs:///the/CSV/file")

                               .includeFields("10010")  // take the first and the fourth field

	                       .types(String.class, Double.class);

// read a CSV file with three fields into a POJO (Person.class) with corresponding fields

DataSet<Person>> csvInput = env.readCsvFile("hdfs:///the/CSV/file")

                         .pojoType(Person.class, "name", "age", 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值