org.apache.flink.table.factories.BatchTableSinkFactory Java Examples
The following examples show how to use
org.apache.flink.table.factories.BatchTableSinkFactory.
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: FlinkTableITCase.java From flink-connectors with Apache License 2.0 | 5 votes |
@Test public void testBatchTableSinkUsingDescriptor() throws Exception { // create a Pravega stream for test purposes Stream stream = Stream.of(setupUtils.getScope(), "testBatchTableSinkUsingDescriptor"); this.setupUtils.createTestStream(stream.getStreamName(), 1); // create a Flink Table environment ExecutionEnvironment env = ExecutionEnvironment.createLocalEnvironment(); env.setParallelism(1); BatchTableEnvironment tableEnv = BatchTableEnvironment.create(env); Table table = tableEnv.fromDataSet(env.fromCollection(SAMPLES)); Pravega pravega = new Pravega(); pravega.tableSinkWriterBuilder() .withRoutingKeyField("category") .forStream(stream) .withPravegaConfig(setupUtils.getPravegaConfig()); ConnectTableDescriptor desc = tableEnv.connect(pravega) .withFormat(new Json().failOnMissingField(true)) .withSchema(new Schema().field("category", DataTypes.STRING()). field("value", DataTypes.INT())); desc.createTemporaryTable("test"); final Map<String, String> propertiesMap = desc.toProperties(); final TableSink<?> sink = TableFactoryService.find(BatchTableSinkFactory.class, propertiesMap) .createBatchTableSink(propertiesMap); String tableSinkPath = tableEnv.getCurrentDatabase() + "." + "PravegaSink"; ConnectorCatalogTable<?, ?> connectorCatalogSinkTable = ConnectorCatalogTable.sink(sink, true); tableEnv.getCatalog(tableEnv.getCurrentCatalog()).get().createTable( ObjectPath.fromString(tableSinkPath), connectorCatalogSinkTable, false); table.insertInto("PravegaSink"); env.execute(); }
Example #2
Source File: FlinkTableITCase.java From flink-connectors with Apache License 2.0 | 4 votes |
/** * Validates the use of Pravega Table Descriptor to generate the source/sink Table factory to * write and read from Pravega stream using {@link BatchTableEnvironment} * @throws Exception */ @Test public void testBatchTableUsingDescriptor() throws Exception { final String scope = setupUtils.getScope(); final String streamName = "stream"; Stream stream = Stream.of(scope, streamName); this.setupUtils.createTestStream(stream.getStreamName(), 1); ExecutionEnvironment env = ExecutionEnvironment.createLocalEnvironment(); env.setParallelism(1); BatchTableEnvironment tableEnv = BatchTableEnvironment.create(env); PravegaConfig pravegaConfig = setupUtils.getPravegaConfig(); Pravega pravega = new Pravega(); pravega.tableSinkWriterBuilder() .withRoutingKeyField("category") .forStream(stream) .withPravegaConfig(pravegaConfig); pravega.tableSourceReaderBuilder() .withReaderGroupScope(stream.getScope()) .forStream(stream) .withPravegaConfig(pravegaConfig); ConnectTableDescriptor desc = tableEnv.connect(pravega) .withFormat(new Json().failOnMissingField(false)) .withSchema(new Schema(). field("category", DataTypes.STRING()). field("value", DataTypes.INT())); desc.createTemporaryTable("test"); final Map<String, String> propertiesMap = desc.toProperties(); final TableSink<?> sink = TableFactoryService.find(BatchTableSinkFactory.class, propertiesMap) .createBatchTableSink(propertiesMap); final TableSource<?> source = TableFactoryService.find(BatchTableSourceFactory.class, propertiesMap) .createBatchTableSource(propertiesMap); Table table = tableEnv.fromDataSet(env.fromCollection(SAMPLES)); String tableSinkPath = tableEnv.getCurrentDatabase() + "." + "PravegaSink"; ConnectorCatalogTable<?, ?> connectorCatalogTableSink = ConnectorCatalogTable.sink(sink, true); tableEnv.getCatalog(tableEnv.getCurrentCatalog()).get().createTable( ObjectPath.fromString(tableSinkPath), connectorCatalogTableSink, false); table.insertInto("PravegaSink"); env.execute(); String tableSourcePath = tableEnv.getCurrentDatabase() + "." + "samples"; ConnectorCatalogTable<?, ?> connectorCatalogTableSource = ConnectorCatalogTable.source(source, true); tableEnv.getCatalog(tableEnv.getCurrentCatalog()).get().createTable( ObjectPath.fromString(tableSourcePath), connectorCatalogTableSource, false); // select some sample data from the Pravega-backed table, as a view Table view = tableEnv.sqlQuery("SELECT * FROM samples WHERE category IN ('A','B')"); // convert the view to a dataset and collect the results for comparison purposes List<SampleRecord> results = tableEnv.toDataSet(view, SampleRecord.class).collect(); Assert.assertEquals(new HashSet<>(SAMPLES), new HashSet<>(results)); }