您好,您这种情况我试了一下,确实不可读,具体原因可能还要看hdfs的支持(flink的Gzip压缩出去的文件hdfs是否认可,这个待确认),不过我这边使用lzo压缩,hdfs是可读的,可参考以下内容
// create the stream with kafka source, test_topic must return Student!
val kafkaStream: DataStream[Student] = env
.addSource(kafkaConsumer)
// 构建StreamingFileSink,指定BasePath和序列化Encoder
val sink: StreamingFileSink[Student] = StreamingFileSink
.forBulkFormat(outputBasePath,
ParquetAvroCompressionWriters.forReflectRecord(classOf[Student],
CompressionCodecName.LZO))
.withBucketAssigner(new EventDateTimeBucketAssigner("yyyyMMdd"))
.build()
// 添加Sink到InputDataSteam即可
kafkaStream.addSink(sink)
// execute program
env.execute("Kafka to Parquet")
在 2022-08-04 10:48:02,"Wenhao Xiao" <[email protected]> 写道:
>大佬们好,有用过1.15 FileSink DataStream api的合并小文件功能吗,我这里写文件用gz格式压缩,发现合并后的文件读不了。
>Format
>Type使用的是FileSink.forBulkFormat;BulkWriter.Factory使用的是CompressWriterFactory,使用gz压缩;合并文件的Compactor使用的是原生的ConcatFileCompactor。
>
>
>以下是使用FileSink的相关代码:
>CompressWriterFactory writer =
> CompressWriters.forExtractor(new DefaultExtractor())
> .withHadoopCompression("Gzip", new Configuration());
>
>FileSink hdfsSink = FileSink.forBulkFormat(new Path("hdfs://xxxx"), writer)
> .withBucketCheckInterval(60000)
> .enableCompact(
> FileCompactStrategy.Builder.newBuilder()
> .setNumCompactThreads(1024)
> .enableCompactionOnCheckpoint(3)
> .build(),
> new ConcatFileCompactor())
> .build();
>
>
>当压缩的小文件被合并后,发现这个被合并的文件不可读:
>使用hdfs dfs -text
>/xxxx/2022-08-03--13/compacted-part-00857a94-bf23-4ae7-a55b-d39c2fdca565-0.gz后
>报错:text: invalid block type
>
>
>请问是1.15 FileSink DataStream api目前是还不支持压缩文件的合并吗?还是我有什么地方用错了或者没注意到的?
>
>
>感谢各位大佬抽空解答!