我用flink(hadoop的1.7.1)做了一些数据处理。最后,我想把由两个元组组成的数据集写到一个文件中。目前,我是这样做的:
<Tuple2<Integer, Point>> pointsClustered = points.getClusteredPoints(...);
pointsClustered.writeAsCsv(params.get("output"), "\n", ",");
但是,我想有csv头写入第一行。flink的javadocapi没有为此声明任何选项。而且,我在谷歌上找不到任何解决方案。
你能就如何做到这一点提出建议吗。谢谢!
2条答案
按热度按时间bvuwiixz1#
我可以通过使用union向数据集添加一个标题行来绕过这个限制。这样,第一行将始终是导出的标题行。
kxxlusnw2#
Flink自己的
CsvOutputFormat
不支持此功能。你能做的就是延长CsvOutputFormat
并覆盖open
打开格式时写入头的方法。那你就用DataSet#output
指定新创建的输出格式: