org.apache.flink.table.factories.TableFactoryService Java Examples
The following examples show how to use
org.apache.flink.table.factories.TableFactoryService.
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: JDBCTableSourceSinkFactoryTest.java From flink with Apache License 2.0 | 6 votes |
@Test public void testJDBCWithFilter() { Map<String, String> properties = getBasicProperties(); properties.put("connector.driver", "org.apache.derby.jdbc.EmbeddedDriver"); properties.put("connector.username", "user"); properties.put("connector.password", "pass"); final TableSource<?> actual = ((JDBCTableSource) TableFactoryService .find(StreamTableSourceFactory.class, properties) .createStreamTableSource(properties)) .projectFields(new int[] {0, 2}); Map<String, DataType> projectedFields = ((FieldsDataType) actual.getProducedDataType()).getFieldDataTypes(); assertEquals(projectedFields.get("aaa"), DataTypes.INT()); assertNull(projectedFields.get("bbb")); assertEquals(projectedFields.get("ccc"), DataTypes.DOUBLE()); }
Example #2
Source File: CsvRowFormatFactoryTest.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@Test public void testSchemaDerivation() { final Map<String, String> properties = new HashMap<>(); properties.putAll(new Schema().schema(TableSchema.fromTypeInfo(SCHEMA)).toProperties()); properties.putAll(new Csv().deriveSchema().toProperties()); final CsvRowSerializationSchema expectedSer = new CsvRowSerializationSchema.Builder(SCHEMA).build(); final CsvRowDeserializationSchema expectedDeser = new CsvRowDeserializationSchema.Builder(SCHEMA).build(); final SerializationSchema<?> actualSer = TableFactoryService .find(SerializationSchemaFactory.class, properties) .createSerializationSchema(properties); assertEquals(expectedSer, actualSer); final DeserializationSchema<?> actualDeser = TableFactoryService .find(DeserializationSchemaFactory.class, properties) .createDeserializationSchema(properties); assertEquals(expectedDeser, actualDeser); }
Example #3
Source File: ElasticsearchUpsertTableSinkFactoryBase.java From flink with Apache License 2.0 | 6 votes |
private SerializationSchema<Row> getSerializationSchema(Map<String, String> properties) { final String formatType = properties.get(FORMAT_TYPE); // we could have added this check to the table factory context // but this approach allows to throw more helpful error messages // if the supported format has not been added if (formatType == null || !formatType.equals(SUPPORTED_FORMAT_TYPE)) { throw new ValidationException( "The Elasticsearch sink requires a '" + SUPPORTED_FORMAT_TYPE + "' format."); } @SuppressWarnings("unchecked") final SerializationSchemaFactory<Row> formatFactory = TableFactoryService.find( SerializationSchemaFactory.class, properties, this.getClass().getClassLoader()); return formatFactory.createSerializationSchema(properties); }
Example #4
Source File: KafkaTableSourceSinkFactoryTestBase.java From flink with Apache License 2.0 | 6 votes |
@Test public void testTableSourceCommitOnCheckpointsDisabled() { Map<String, String> propertiesMap = new HashMap<>(); createKafkaSourceProperties().forEach((k, v) -> { if (!k.equals("connector.properties.group.id")) { propertiesMap.put(k, v); } }); final TableSource<?> tableSource = TableFactoryService.find(StreamTableSourceFactory.class, propertiesMap) .createStreamTableSource(propertiesMap); final StreamExecutionEnvironmentMock mock = new StreamExecutionEnvironmentMock(); // Test commitOnCheckpoints flag should be false when do not set consumer group. ((KafkaTableSourceBase) tableSource).getDataStream(mock); assertTrue(mock.sourceFunction instanceof FlinkKafkaConsumerBase); assertFalse(((FlinkKafkaConsumerBase) mock.sourceFunction).getEnableCommitOnCheckpoints()); }
Example #5
Source File: ElasticsearchUpsertTableSinkFactoryBase.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
private SerializationSchema<Row> getSerializationSchema(Map<String, String> properties) { final String formatType = properties.get(FORMAT_TYPE); // we could have added this check to the table factory context // but this approach allows to throw more helpful error messages // if the supported format has not been added if (formatType == null || !formatType.equals(SUPPORTED_FORMAT_TYPE)) { throw new ValidationException( "The Elasticsearch sink requires a '" + SUPPORTED_FORMAT_TYPE + "' format."); } @SuppressWarnings("unchecked") final SerializationSchemaFactory<Row> formatFactory = TableFactoryService.find( SerializationSchemaFactory.class, properties, this.getClass().getClassLoader()); return formatFactory.createSerializationSchema(properties); }
Example #6
Source File: JdbcTableSourceSinkFactoryTest.java From flink with Apache License 2.0 | 6 votes |
@Test public void testJdbcFieldsProjection() { Map<String, String> properties = getBasicProperties(); properties.put("connector.driver", "org.apache.derby.jdbc.EmbeddedDriver"); properties.put("connector.username", "user"); properties.put("connector.password", "pass"); final TableSource<?> actual = ((JdbcTableSource) TableFactoryService .find(StreamTableSourceFactory.class, properties) .createStreamTableSource(properties)) .projectFields(new int[] {0, 2}); List<DataType> projectedFields = actual.getProducedDataType().getChildren(); assertEquals(Arrays.asList(DataTypes.INT(), DataTypes.DOUBLE()), projectedFields); // test jdbc table source description List<String> fieldNames = ((RowType) actual.getProducedDataType().getLogicalType()).getFieldNames(); String expectedSourceDescription = actual.getClass().getSimpleName() + "(" + String.join(", ", fieldNames.stream().toArray(String[]::new)) + ")"; assertEquals(expectedSourceDescription, actual.explainSource()); }
Example #7
Source File: JdbcTableSourceSinkFactoryTest.java From flink with Apache License 2.0 | 6 votes |
@Test public void testJdbcCommonProperties() { Map<String, String> properties = getBasicProperties(); properties.put("connector.driver", "org.apache.derby.jdbc.EmbeddedDriver"); properties.put("connector.username", "user"); properties.put("connector.password", "pass"); final StreamTableSource<?> actual = TableFactoryService.find(StreamTableSourceFactory.class, properties) .createStreamTableSource(properties); final JdbcOptions options = JdbcOptions.builder() .setDBUrl("jdbc:derby:memory:mydb") .setTableName("mytable") .setDriverName("org.apache.derby.jdbc.EmbeddedDriver") .setUsername("user") .setPassword("pass") .build(); final JdbcTableSource expected = JdbcTableSource.builder() .setOptions(options) .setSchema(schema) .build(); TableSourceValidation.validateTableSource(expected, schema); TableSourceValidation.validateTableSource(actual, schema); assertEquals(expected, actual); }
Example #8
Source File: FlinkPravegaTableFactoryTest.java From flink-connectors with Apache License 2.0 | 6 votes |
@Test (expected = ValidationException.class) public void testMissingFormatDefinition() { Pravega pravega = new Pravega(); Stream stream = Stream.of(SCOPE, STREAM); pravega.tableSinkWriterBuilder() .withRoutingKeyField("name") .forStream(stream) .withPravegaConfig(PRAVEGA_CONFIG); final TestTableDescriptor testDesc = new TestTableDescriptor(pravega) .withSchema(SCHEMA) .inAppendMode(); final Map<String, String> propertiesMap = testDesc.toProperties(); TableFactoryService.find(StreamTableSinkFactory.class, propertiesMap) .createStreamTableSink(propertiesMap); fail("table factory validation failed"); }
Example #9
Source File: FlinkPravegaTableFactoryTest.java From flink-connectors with Apache License 2.0 | 6 votes |
@Test (expected = ValidationException.class) public void testMissingSchemaDefinition() { Pravega pravega = new Pravega(); Stream stream = Stream.of(SCOPE, STREAM); pravega.tableSinkWriterBuilder() .withRoutingKeyField("name") .forStream(stream) .withPravegaConfig(PRAVEGA_CONFIG); final TestTableDescriptor testDesc = new TestTableDescriptor(pravega) .withFormat(JSON) .inAppendMode(); final Map<String, String> propertiesMap = testDesc.toProperties(); TableFactoryService.find(StreamTableSinkFactory.class, propertiesMap) .createStreamTableSink(propertiesMap); fail("missing schema validation failed"); }
Example #10
Source File: FlinkPravegaTableFactoryTest.java From flink-connectors with Apache License 2.0 | 6 votes |
@Test public void testValidWriterModeExactlyOnce() { Pravega pravega = new Pravega(); Stream stream = Stream.of(SCOPE, STREAM); pravega.tableSinkWriterBuilder() .withRoutingKeyField("name").withWriterMode(PravegaWriterMode.EXACTLY_ONCE) .forStream(stream) .withPravegaConfig(PRAVEGA_CONFIG); final TestTableDescriptor testDesc = new TestTableDescriptor(pravega) .withFormat(JSON) .withSchema(SCHEMA) .inAppendMode(); final Map<String, String> propertiesMap = testDesc.toProperties(); final TableSink<?> sink = TableFactoryService.find(StreamTableSinkFactory.class, propertiesMap) .createStreamTableSink(propertiesMap); assertNotNull(sink); }
Example #11
Source File: FlinkPravegaTableFactoryTest.java From flink-connectors with Apache License 2.0 | 6 votes |
@Test (expected = ValidationException.class) public void testInvalidWriterMode() { Pravega pravega = new Pravega(); Stream stream = Stream.of(SCOPE, STREAM); pravega.tableSinkWriterBuilder() .withRoutingKeyField("name") .forStream(stream) .withPravegaConfig(PRAVEGA_CONFIG); final TestTableDescriptor testDesc = new TestTableDescriptor(pravega) .withFormat(JSON) .withSchema(SCHEMA) .inAppendMode(); final Map<String, String> propertiesMap = testDesc.toProperties(); Map<String, String> test = new HashMap<>(propertiesMap); test.put(CONNECTOR_WRITER_MODE, "foo"); TableFactoryService.find(StreamTableSinkFactory.class, test) .createStreamTableSink(test); fail("writer mode validation failed"); }
Example #12
Source File: FlinkPravegaTableFactoryTest.java From flink-connectors with Apache License 2.0 | 6 votes |
/** * For sink, stream name information is mandatory. */ @Test (expected = IllegalStateException.class) public void testMissingStreamNameForWriter() { Pravega pravega = new Pravega(); pravega.tableSinkWriterBuilder() .withRoutingKeyField("name"); final TestTableDescriptor testDesc = new TestTableDescriptor(pravega) .withFormat(JSON) .withSchema(SCHEMA) .inAppendMode(); final Map<String, String> propertiesMap = testDesc.toProperties(); TableFactoryService.find(StreamTableSinkFactory.class, propertiesMap) .createStreamTableSink(propertiesMap); fail("stream name validation failed"); }
Example #13
Source File: CsvRowFormatFactoryTest.java From flink with Apache License 2.0 | 6 votes |
@Test public void testSchemaDerivation() { final Map<String, String> properties = new HashMap<>(); properties.putAll(new Schema().schema(TableSchema.fromTypeInfo(SCHEMA)).toProperties()); properties.putAll(new Csv().deriveSchema().toProperties()); final CsvRowSerializationSchema expectedSer = new CsvRowSerializationSchema.Builder(SCHEMA).build(); final CsvRowDeserializationSchema expectedDeser = new CsvRowDeserializationSchema.Builder(SCHEMA).build(); final SerializationSchema<?> actualSer = TableFactoryService .find(SerializationSchemaFactory.class, properties) .createSerializationSchema(properties); assertEquals(expectedSer, actualSer); final DeserializationSchema<?> actualDeser = TableFactoryService .find(DeserializationSchemaFactory.class, properties) .createDeserializationSchema(properties); assertEquals(expectedDeser, actualDeser); }
Example #14
Source File: CsvRowFormatFactoryTest.java From flink with Apache License 2.0 | 6 votes |
@Test public void testSchemaDerivation() { final Map<String, String> properties = new HashMap<>(); properties.putAll(new Schema().schema(TableSchema.fromTypeInfo(SCHEMA)).toProperties()); properties.putAll(new Csv().toProperties()); final CsvRowSerializationSchema expectedSer = new CsvRowSerializationSchema.Builder(SCHEMA).build(); final CsvRowDeserializationSchema expectedDeser = new CsvRowDeserializationSchema.Builder(SCHEMA).build(); final SerializationSchema<?> actualSer = TableFactoryService .find(SerializationSchemaFactory.class, properties) .createSerializationSchema(properties); assertEquals(expectedSer, actualSer); final DeserializationSchema<?> actualDeser = TableFactoryService .find(DeserializationSchemaFactory.class, properties) .createDeserializationSchema(properties); assertEquals(expectedDeser, actualDeser); }
Example #15
Source File: FlinkPravegaTableFactoryBase.java From flink-connectors with Apache License 2.0 | 5 votes |
protected SerializationSchema<Row> getSerializationSchema(Map<String, String> properties) { @SuppressWarnings("unchecked") final SerializationSchemaFactory<Row> formatFactory = TableFactoryService.find( SerializationSchemaFactory.class, properties, this.getClass().getClassLoader()); return formatFactory.createSerializationSchema(properties); }
Example #16
Source File: ElasticsearchUpsertTableSinkFactoryTestBase.java From flink with Apache License 2.0 | 5 votes |
@Test public void testTableSinkWithLegacyProperties() { // prepare parameters for Elasticsearch table sink final TableSchema schema = createTestSchema(); final ElasticsearchUpsertTableSinkBase expectedSink = getExpectedTableSink( false, schema, Collections.singletonList(new Host(HOSTNAME, PORT, SCHEMA)), INDEX, DOC_TYPE, KEY_DELIMITER, KEY_NULL_LITERAL, JsonRowSerializationSchema.builder().withTypeInfo(schema.toRowType()).build(), XContentType.JSON, new DummyFailureHandler(), createTestSinkOptions(), IndexGeneratorFactory.createIndexGenerator(INDEX, schema)); // construct table sink using descriptors and table sink factory final Map<String, String> elasticSearchProperties = createElasticSearchProperties(); final Map<String, String> legacyPropertiesMap = new HashMap<>(); legacyPropertiesMap.putAll(elasticSearchProperties); // use legacy properties legacyPropertiesMap.remove("connector.hosts"); legacyPropertiesMap.put("connector.hosts.0.hostname", "host1"); legacyPropertiesMap.put("connector.hosts.0.port", "1234"); legacyPropertiesMap.put("connector.hosts.0.protocol", "https"); final TableSink<?> actualSink = TableFactoryService.find(StreamTableSinkFactory.class, legacyPropertiesMap) .createStreamTableSink(legacyPropertiesMap); assertEquals(expectedSink, actualSink); }
Example #17
Source File: DatahubTableFactoryTest.java From alibaba-flink-connectors with Apache License 2.0 | 5 votes |
@Test public void testSupportedProperties() { Map<String, String> properties = getBasicProperties(); properties.put(CONNECTOR_BATCH_SIZE, "1"); properties.put(CONNECTOR_BUFFER_SIZE, "1"); properties.put(CONNECTOR_RETRY_TIMEOUT_IN_MILLS, "3"); properties.put(CONNECTOR_MAX_RETRY_TIMES, "10"); properties.put(CONNECTOR_BATCH_WRITE_TIMEOUT_IN_MILLS, "5"); final TableSink<?> actual = TableFactoryService.find(TableSinkFactory.class, properties) .createTableSink(properties); assertTrue(actual instanceof DatahubTableSink); }
Example #18
Source File: JsonRowFormatFactoryTest.java From flink with Apache License 2.0 | 5 votes |
private void testSchemaDeserializationSchema(Map<String, String> properties) { final DeserializationSchema<?> actual2 = TableFactoryService .find(DeserializationSchemaFactory.class, properties) .createDeserializationSchema(properties); final JsonRowDeserializationSchema expected2 = new JsonRowDeserializationSchema.Builder(SCHEMA).build(); assertEquals(expected2, actual2); }
Example #19
Source File: AvroRowFormatFactoryTest.java From flink with Apache License 2.0 | 5 votes |
private void testAvroSchemaDeserializationSchema(Map<String, String> properties) { final DeserializationSchema<?> actual2 = TableFactoryService .find(DeserializationSchemaFactory.class, properties) .createDeserializationSchema(properties); final AvroRowDeserializationSchema expected2 = new AvroRowDeserializationSchema(AVRO_SCHEMA); assertEquals(expected2, actual2); }
Example #20
Source File: JdbcTableSourceSinkFactoryTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testJdbcReadProperties() { Map<String, String> properties = getBasicProperties(); properties.put("connector.read.query", "SELECT aaa FROM mytable"); properties.put("connector.read.partition.column", "aaa"); properties.put("connector.read.partition.lower-bound", "-10"); properties.put("connector.read.partition.upper-bound", "100"); properties.put("connector.read.partition.num", "10"); properties.put("connector.read.fetch-size", "20"); final StreamTableSource<?> actual = TableFactoryService.find(StreamTableSourceFactory.class, properties) .createStreamTableSource(properties); final JdbcOptions options = JdbcOptions.builder() .setDBUrl("jdbc:derby:memory:mydb") .setTableName("mytable") .build(); final JdbcReadOptions readOptions = JdbcReadOptions.builder() .setQuery("SELECT aaa FROM mytable") .setPartitionColumnName("aaa") .setPartitionLowerBound(-10) .setPartitionUpperBound(100) .setNumPartitions(10) .setFetchSize(20) .build(); final JdbcTableSource expected = JdbcTableSource.builder() .setOptions(options) .setReadOptions(readOptions) .setSchema(schema) .build(); assertEquals(expected, actual); }
Example #21
Source File: JsonRowFormatFactoryTest.java From flink with Apache License 2.0 | 5 votes |
private void testJsonSchemaDeserializationSchema(Map<String, String> properties) { final DeserializationSchema<?> actual2 = TableFactoryService .find(DeserializationSchemaFactory.class, properties) .createDeserializationSchema(properties); final JsonRowDeserializationSchema expected2 = new JsonRowDeserializationSchema.Builder(JSON_SCHEMA) .failOnMissingField() .build(); assertEquals(expected2, actual2); }
Example #22
Source File: JsonRowFormatFactoryTest.java From flink with Apache License 2.0 | 5 votes |
private void testJsonSchemaDeserializationSchema(Map<String, String> properties) { final DeserializationSchema<?> actual2 = TableFactoryService .find(DeserializationSchemaFactory.class, properties) .createDeserializationSchema(properties); final JsonRowDeserializationSchema expected2 = new JsonRowDeserializationSchema.Builder(JSON_SCHEMA) .failOnMissingField() .build(); assertEquals(expected2, actual2); }
Example #23
Source File: AvroRowFormatFactoryTest.java From flink with Apache License 2.0 | 5 votes |
private void testRecordClassDeserializationSchema(Map<String, String> properties) { final SerializationSchema<?> actual1 = TableFactoryService .find(SerializationSchemaFactory.class, properties) .createSerializationSchema(properties); final SerializationSchema<?> expected1 = new AvroRowSerializationSchema(AVRO_SPECIFIC_RECORD); assertEquals(expected1, actual1); }
Example #24
Source File: CsvRowFormatFactoryTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testDisableQuoteCharacter() { final Map<String, String> properties = new Csv() .schema(SCHEMA) .fieldDelimiter(';') .lineDelimiter("\r\n") .allowComments() .ignoreParseErrors() .arrayElementDelimiter("|") .escapeCharacter('\\') .nullLiteral("n/a") .disableQuoteCharacter() .toProperties(); final CsvRowSerializationSchema expectedSer = new CsvRowSerializationSchema.Builder(SCHEMA) .setFieldDelimiter(';') .setLineDelimiter("\r\n") .setArrayElementDelimiter("|") .setEscapeCharacter('\\') .setNullLiteral("n/a") .disableQuoteCharacter() .build(); final SerializationSchema<?> actualSer = TableFactoryService .find(SerializationSchemaFactory.class, properties) .createSerializationSchema(properties); assertEquals(expectedSer, actualSer); }
Example #25
Source File: AvroRowFormatFactoryTest.java From flink with Apache License 2.0 | 5 votes |
private void testAvroSchemaSerializationSchema(Map<String, String> properties) { final SerializationSchema<?> actual1 = TableFactoryService .find(SerializationSchemaFactory.class, properties) .createSerializationSchema(properties); final SerializationSchema<?> expected1 = new AvroRowSerializationSchema(AVRO_SCHEMA); assertEquals(expected1, actual1); }
Example #26
Source File: AvroRowFormatFactoryTest.java From flink with Apache License 2.0 | 5 votes |
private void testAvroSchemaDeserializationSchema(Map<String, String> properties) { final DeserializationSchema<?> actual2 = TableFactoryService .find(DeserializationSchemaFactory.class, properties) .createDeserializationSchema(properties); final AvroRowDeserializationSchema expected2 = new AvroRowDeserializationSchema(AVRO_SCHEMA); assertEquals(expected2, actual2); }
Example #27
Source File: AvroRowFormatFactoryTest.java From flink with Apache License 2.0 | 5 votes |
private void testRecordClassDeserializationSchema(Map<String, String> properties) { final SerializationSchema<?> actual1 = TableFactoryService .find(SerializationSchemaFactory.class, properties) .createSerializationSchema(properties); final SerializationSchema<?> expected1 = new AvroRowSerializationSchema(AVRO_SPECIFIC_RECORD); assertEquals(expected1, actual1); }
Example #28
Source File: AvroRowFormatFactoryTest.java From flink with Apache License 2.0 | 5 votes |
private void testRecordClassSerializationSchema(Map<String, String> properties) { final DeserializationSchema<?> actual2 = TableFactoryService .find(DeserializationSchemaFactory.class, properties) .createDeserializationSchema(properties); final AvroRowDeserializationSchema expected2 = new AvroRowDeserializationSchema(AVRO_SPECIFIC_RECORD); assertEquals(expected2, actual2); }
Example #29
Source File: HiveCatalogFactoryTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testDisallowEmbedded() { expectedException.expect(IllegalArgumentException.class); final Map<String, String> properties = new HiveCatalogDescriptor().toProperties(); TableFactoryService.find(CatalogFactory.class, properties).createCatalog("my_catalog", properties); }
Example #30
Source File: KafkaTableSourceSinkFactoryBase.java From flink with Apache License 2.0 | 5 votes |
private SerializationSchema<Row> getSerializationSchema(Map<String, String> properties) { @SuppressWarnings("unchecked") final SerializationSchemaFactory<Row> formatFactory = TableFactoryService.find( SerializationSchemaFactory.class, properties, this.getClass().getClassLoader()); return formatFactory.createSerializationSchema(properties); }