[英]Read CSV file with 3 columns into Datastream. JAVA Apache Flink
我一直在努力设置一个从 Z628CB5675FF524F3E719B7AA2E88FE3 文件创建Datastream<Tuple3<Integer, java.sql.Time, Double>>
的 flink 应用程序。 此文件中的列(列ID, dateTime and Result
)都是 String,但它们应转换为 Integer、java.sql.Time 和 Double。 我想要的另一件事是使用每天的数据创建翻滚 windows 并平均该 window 中result
列的值。 问题是我不知道它的确切语法。 请参阅我尝试过的代码。 最后一部分我有 sum(2),但我想计算 windows 的平均值。 我在文档中没有看到 function 中的这个。 我需要为此自己编写一个方法吗?
DataStream<Tuple3<String, java.sql.Time>> dataStream = env
.readfile(path)
.map()
.keyBy(0)
.timeWindow(Time.days(1));
您可以使用自己的逻辑来读取 csv 或使用像 univocity_parsers 这样的库。 而不是使用 env。 readfile你可以使用 env. 从集合(列表)。
这是图书馆的链接如果你想要: https://www.univocity.com/pages/univocity_parsers_tutorial#using-annotations-to-map-your-java-beans
您可以使用 anotaion @Convert (conversionClass = YourDataTimeCoverter .class) 提供自己的转换器
对于平均值,请参阅以下 flink 文档并附有示例:。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.