Search in sources :

Example 1 with BasePathBucketAssigner

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

the class DataStreamCsvITCase method testCustomBulkWriter.

@Test
public void testCustomBulkWriter() throws Exception {
    final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
    env.setParallelism(PARALLELISM);
    // fromCollection is not bounded, using fromSequence instead
    // needs to be Serializable
    final List<CityPojo> pojosList = Arrays.asList(POJOS);
    final DataStream<Integer> sequence = env.fromSequence(0, POJOS.length - 1).map(Long::intValue);
    final DataStream<CityPojo> stream = sequence.map(pojosList::get).returns(CityPojo.class);
    FileSink<CityPojo> sink = FileSink.forBulkFormat(new Path(outDir.toURI()), factoryForPojo(CityPojo.class)).withBucketAssigner(new BasePathBucketAssigner<>()).build();
    stream.sinkTo(sink);
    env.execute();
    String[] result = getResultsFromSinkFiles(outDir);
    assertThat(result).containsExactlyInAnyOrder(CSV_LINES);
}
Also used : Path(org.apache.flink.core.fs.Path) BasePathBucketAssigner(org.apache.flink.streaming.api.functions.sink.filesystem.bucketassigners.BasePathBucketAssigner) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) Test(org.junit.jupiter.api.Test)

Aggregations

Path (org.apache.flink.core.fs.Path)1 StreamExecutionEnvironment (org.apache.flink.streaming.api.environment.StreamExecutionEnvironment)1 BasePathBucketAssigner (org.apache.flink.streaming.api.functions.sink.filesystem.bucketassigners.BasePathBucketAssigner)1 Test (org.junit.jupiter.api.Test)1