Java Code Examples for org.apache.flink.api.common.serialization.BulkWriter#flush()
The following examples show how to use
org.apache.flink.api.common.serialization.BulkWriter#flush() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FileSystemTableSink.java From flink with Apache License 2.0 | 6 votes |
@Override public BulkWriter<RowData> create(FSDataOutputStream out) throws IOException { BulkWriter<RowData> writer = factory.create(out); return new BulkWriter<RowData>() { @Override public void addElement(RowData element) throws IOException { writer.addElement(computer.projectColumnsToWrite(element)); } @Override public void flush() throws IOException { writer.flush(); } @Override public void finish() throws IOException { writer.finish(); } }; }
Example 2
Source File: AvroFileSystemFormatFactory.java From flink with Apache License 2.0 | 6 votes |
@Override public BulkWriter<RowData> create(FSDataOutputStream out) throws IOException { BulkWriter<GenericRecord> writer = factory.create(out); AvroRowDataSerializationSchema.SerializationRuntimeConverter converter = AvroRowDataSerializationSchema.createRowConverter(rowType); Schema schema = AvroSchemaConverter.convertToSchema(rowType); return new BulkWriter<RowData>() { @Override public void addElement(RowData element) throws IOException { GenericRecord record = (GenericRecord) converter.convert(schema, element); writer.addElement(record); } @Override public void flush() throws IOException { writer.flush(); } @Override public void finish() throws IOException { writer.finish(); } }; }
Example 3
Source File: ParquetRowDataWriterTest.java From flink with Apache License 2.0 | 4 votes |
private void innerTest( Configuration conf, boolean utcTimestamp) throws IOException { Path path = new Path(TEMPORARY_FOLDER.newFolder().getPath(), UUID.randomUUID().toString()); int number = 1000; List<Row> rows = new ArrayList<>(number); for (int i = 0; i < number; i++) { Integer v = i; rows.add(Row.of( String.valueOf(v), String.valueOf(v).getBytes(StandardCharsets.UTF_8), v % 2 == 0, v.byteValue(), v.shortValue(), v, v.longValue(), v.floatValue(), v.doubleValue(), toDateTime(v), BigDecimal.valueOf(v), BigDecimal.valueOf(v), BigDecimal.valueOf(v))); } ParquetWriterFactory<RowData> factory = ParquetRowDataBuilder.createWriterFactory( ROW_TYPE, conf, utcTimestamp); BulkWriter<RowData> writer = factory.create(path.getFileSystem().create( path, FileSystem.WriteMode.OVERWRITE)); for (int i = 0; i < number; i++) { writer.addElement(CONVERTER.toInternal(rows.get(i))); } writer.flush(); writer.finish(); // verify ParquetColumnarRowSplitReader reader = ParquetSplitReaderUtil.genPartColumnarRowReader( utcTimestamp, true, conf, ROW_TYPE.getFieldNames().toArray(new String[0]), ROW_TYPE.getChildren().stream() .map(TypeConversions::fromLogicalToDataType) .toArray(DataType[]::new), new HashMap<>(), IntStream.range(0, ROW_TYPE.getFieldCount()).toArray(), 50, path, 0, Long.MAX_VALUE); int cnt = 0; while (!reader.reachedEnd()) { Row row = CONVERTER.toExternal(reader.nextRecord()); Assert.assertEquals(rows.get(cnt), row); cnt++; } Assert.assertEquals(number, cnt); }