Search in sources :

Example 1 with HadoopPathBasedBulkFormatBuilder

use of org.apache.flink.streaming.api.functions.sink.filesystem.HadoopPathBasedBulkFormatBuilder in project flink by apache.

the class HadoopPathBasedPartFileWriterTest method testWriteFile.

@Test
public void testWriteFile() throws Exception {
    File file = TEMPORARY_FOLDER.newFolder();
    Path basePath = new Path(file.toURI());
    List<String> data = Arrays.asList("first line", "second line", "third line");
    StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
    env.setParallelism(1);
    env.enableCheckpointing(100);
    DataStream<String> stream = env.addSource(new FiniteTestSource<>(data), TypeInformation.of(String.class));
    Configuration configuration = new Configuration();
    HadoopPathBasedBulkFormatBuilder<String, String, ?> builder = new HadoopPathBasedBulkFormatBuilder<>(basePath, new TestHadoopPathBasedBulkWriterFactory(), configuration, new DateTimeBucketAssigner<>());
    TestStreamingFileSinkFactory<String> streamingFileSinkFactory = new TestStreamingFileSinkFactory<>();
    stream.addSink(streamingFileSinkFactory.createSink(builder, 1000));
    env.execute();
    validateResult(data, configuration, basePath);
}
Also used : Path(org.apache.hadoop.fs.Path) Configuration(org.apache.hadoop.conf.Configuration) HadoopPathBasedBulkFormatBuilder(org.apache.flink.streaming.api.functions.sink.filesystem.HadoopPathBasedBulkFormatBuilder) TestStreamingFileSinkFactory(org.apache.flink.streaming.api.functions.sink.filesystem.TestStreamingFileSinkFactory) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) File(java.io.File) Test(org.junit.Test)

Aggregations

File (java.io.File)1 StreamExecutionEnvironment (org.apache.flink.streaming.api.environment.StreamExecutionEnvironment)1 HadoopPathBasedBulkFormatBuilder (org.apache.flink.streaming.api.functions.sink.filesystem.HadoopPathBasedBulkFormatBuilder)1 TestStreamingFileSinkFactory (org.apache.flink.streaming.api.functions.sink.filesystem.TestStreamingFileSinkFactory)1 Configuration (org.apache.hadoop.conf.Configuration)1 Path (org.apache.hadoop.fs.Path)1 Test (org.junit.Test)1