如何在 Flink 中读取 .bsq 文件?

How to read a .bsq file in Flink?

正确设置我的项目后,我需要 read/import 几个 .bsq 文件到我的环境中。我尝试像这样使用 env.readFile() 方法:

DataSet<T> data = env.readFile(*insertFileInputFormatHere*, filePath);

但是我无法得到合适的FileInputFormat。因为它是抽象的,所以我不能有自己的实例。我应该扩展 abstract class FileInputFormat 并使用我自己的扩展来实例化 FileInputFormat 吗?还是有别的方法我没认出来?

.bsq 文件似乎是二进制格式,不存在 Flink 或 Hadoop InputFormat(我包括 Hadoop InputFormats,因为 Flink 也支持 Hadoop IF)

因此您必须实现自己的 InputFormat 来读取文件。我建议从 Flink 的 org.apache.flink.api.common.io.FileInputFormat.

扩展你自己的 InputFormat

要使用您自己的输入格式,您必须像

那样称呼它
final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
env.createInput(new MyInputFormat());