//继承RichFunction 为了获取RuntimeContextclassMyMapperextendsRichMapFunction[String, Int] { override def open(config: Configuration): Unit={//通过RuntimeContext 和 DistributedCache访问缓存文件val myFile: File = getRuntimeContext.getDistributedCache.getFile("hdfsFile")//读取文件(或者本地目录)... }...
Flink分布式缓存Distributed Cache 1 分布式缓存 Flink提供了一个分布式缓存,类似于hadoop,可以使用户在并行函数中很方便的读取本地文件,并把它放在taskmanager节点中,防止task重复拉取。 此缓存的工作机制如下:程序注册一个文件或者目录(本地或者远程文件系统,例如hdfs或者s3),通过ExecutionEnvironment注册缓存文件并为它起...
下面从ExecutionEnvironment的registerCachedFile方法开始分析Distributed Cache的执行流程。 publicvoidregisterCachedFile(StringfilePath,Stringname){registerCachedFile(filePath,name,false);}publicvoidregisterCachedFile(StringfilePath,Stringname,booleanexecutable){this.cacheFile.add(newTuple2<>(name,newDistributedCache...
StreamOperator面向用户调用的就是UserFunction,如果我们的自定义Function中有一些比较通用的包,有很多Flink任务都会使用到,那么我们就可以使用-C 来指定包的路径,前提是集群的每个node都可以访问到(file://),通过这种方式程序在打包的时候就不需要将这些通用的包打进去。 DistributedCache DistributedCache正如其含义分布式...
将分布式文件地址及注册名称写入StreamExecutionEnvironment的cacheFile中。 protectedfinalList<Tuple2<String,DistributedCache.DistributedCacheEntry>>cacheFile=newArrayList<>();publicvoidregisterCachedFile(StringfilePath,Stringname,booleanexecutable){this.cacheFile.add(newTuple2<>(name,newDistributedCache.DistributedCa...
官网对 distributed cache 的定义: Flink offers a distributed cache, similar to Apache Hadoop, to make files locally accessible to parallel instances of user functions. This functionality can be used to share files that contain static external data such as dictionaries or machine-learned regression mod...
二、分布式缓存(Distributed Cache)示例 1、介绍 2、maven依赖 3、实现 4、验证 1)、验证步骤 2)、验证 本文介绍了flink关于分布式缓存的使用示例,比较简单。 本文除了maven依赖外,没有其他依赖。 本示例需要hadoop环境可用。 一、maven依赖 为避免篇幅过长,所有基础依赖均在第一篇文章中列出,具体依赖参考文章 ...
2. 使用它, 在算子内部调用getRuntimeContext.getDistributedCache.getFile(File)来获取分布式缓存的文件 */ // 1. 注册分布式缓存 env.registerCachedFile("data/input/distributed_student.txt", "student"); // 通过map方法来组合数据和获取分布式缓存文件内容 ...
File myFile = getRuntimeContext().getDistributedCache().getFile("a.txt"); List<String> lines = FileUtils.readLines(myFile); for (String line : lines) { this.dataList.add(line); System.err.println("分布式缓存为:" + line); }
File myFile = getRuntimeContext().getDistributedCache().getFile("a.txt"); Listlines = FileUtils.readLines(myFile); for (String line : lines) { this.dataList.add(line); System.err.println("分布式缓存为:" + line); } } @Override ...