Search in sources :

Example 6 with DecodingFormatMock

use of org.apache.flink.table.factories.TestFormatFactory.DecodingFormatMock in project flink by apache.

the class FactoryUtilTest method testFactoryHelperWithEnrichmentOptionsAndFormat.

@Test
public void testFactoryHelperWithEnrichmentOptionsAndFormat() {
    String keyFormatPrefix = FactoryUtil.getFormatPrefix(TestDynamicTableFactory.KEY_FORMAT, TestFormatFactory.IDENTIFIER);
    String valueFormatPrefix = FactoryUtil.getFormatPrefix(TestDynamicTableFactory.VALUE_FORMAT, TestFormatFactory.IDENTIFIER);
    final Map<String, String> options = new HashMap<>();
    options.put(TestDynamicTableFactory.TARGET.key(), "abc");
    options.put(TestDynamicTableFactory.BUFFER_SIZE.key(), "1000");
    options.put(TestDynamicTableFactory.KEY_FORMAT.key(), TestFormatFactory.IDENTIFIER);
    options.put(keyFormatPrefix + TestFormatFactory.DELIMITER.key(), "|");
    options.put(keyFormatPrefix + TestFormatFactory.FAIL_ON_MISSING.key(), "true");
    options.put(TestDynamicTableFactory.VALUE_FORMAT.key(), TestFormatFactory.IDENTIFIER);
    options.put(valueFormatPrefix + TestFormatFactory.DELIMITER.key(), "|");
    options.put(valueFormatPrefix + TestFormatFactory.FAIL_ON_MISSING.key(), "true");
    final Map<String, String> enrichment = new HashMap<>();
    enrichment.put(TestDynamicTableFactory.TARGET.key(), "xyz");
    enrichment.put(TestDynamicTableFactory.BUFFER_SIZE.key(), "2000");
    enrichment.put(TestDynamicTableFactory.KEY_FORMAT.key(), TestFormatFactory.IDENTIFIER);
    enrichment.put(keyFormatPrefix + TestFormatFactory.DELIMITER.key(), ",");
    enrichment.put(keyFormatPrefix + TestFormatFactory.FAIL_ON_MISSING.key(), "true");
    enrichment.put(TestDynamicTableFactory.VALUE_FORMAT.key(), TestFormatFactory.IDENTIFIER);
    enrichment.put(valueFormatPrefix + TestFormatFactory.DELIMITER.key(), "|");
    final FactoryUtil.TableFactoryHelper helper = FactoryUtil.createTableFactoryHelper(new TestDynamicTableFactory(), FactoryMocks.createTableContext(SCHEMA, options, enrichment));
    // Get resulting format mocks from key and value
    // Note: the only forwardable option for the test format is the delimiter
    DecodingFormatMock keyDecodingFormatMock = (DecodingFormatMock) helper.discoverDecodingFormat(DeserializationFormatFactory.class, TestDynamicTableFactory.KEY_FORMAT);
    DecodingFormatMock valueDecodingFormatMock = (DecodingFormatMock) helper.discoverDecodingFormat(DeserializationFormatFactory.class, TestDynamicTableFactory.VALUE_FORMAT);
    helper.validate();
    // Check table options
    assertThat(helper.getOptions().get(TestDynamicTableFactory.TARGET)).isEqualTo("abc");
    assertThat(helper.getOptions().get(TestDynamicTableFactory.BUFFER_SIZE)).isEqualTo(2000);
    // Check format options
    assertThat(keyDecodingFormatMock.delimiter).isEqualTo(",");
    assertThat(keyDecodingFormatMock.failOnMissing).isTrue();
    assertThat(valueDecodingFormatMock.delimiter).isEqualTo("|");
    assertThat(valueDecodingFormatMock.failOnMissing).isTrue();
}
Also used : HashMap(java.util.HashMap) DecodingFormatMock(org.apache.flink.table.factories.TestFormatFactory.DecodingFormatMock) Test(org.junit.jupiter.api.Test)

Example 7 with DecodingFormatMock

use of org.apache.flink.table.factories.TestFormatFactory.DecodingFormatMock in project flink by apache.

the class FactoryUtilTest method testDiscoveryForSeparateSourceSinkFactory.

@Test
public void testDiscoveryForSeparateSourceSinkFactory() {
    final Map<String, String> options = createAllOptions();
    // the "test" source and sink factory is not in one factory class
    // see TestDynamicTableSinkFactory and TestDynamicTableSourceFactory
    options.put("connector", "test");
    final DynamicTableSource actualSource = createTableSource(SCHEMA, options);
    final DynamicTableSource expectedSource = new DynamicTableSourceMock("MyTarget", null, new DecodingFormatMock(",", false), new DecodingFormatMock("|", true));
    assertThat(actualSource).isEqualTo(expectedSource);
    final DynamicTableSink actualSink = createTableSink(SCHEMA, options);
    final DynamicTableSink expectedSink = new DynamicTableSinkMock("MyTarget", 1000L, new EncodingFormatMock(","), new EncodingFormatMock("|"));
    assertThat(actualSink).isEqualTo(expectedSink);
}
Also used : EncodingFormatMock(org.apache.flink.table.factories.TestFormatFactory.EncodingFormatMock) DecodingFormatMock(org.apache.flink.table.factories.TestFormatFactory.DecodingFormatMock) DynamicTableSink(org.apache.flink.table.connector.sink.DynamicTableSink) DynamicTableSourceMock(org.apache.flink.table.factories.TestDynamicTableFactory.DynamicTableSourceMock) DynamicTableSource(org.apache.flink.table.connector.source.DynamicTableSource) DynamicTableSinkMock(org.apache.flink.table.factories.TestDynamicTableFactory.DynamicTableSinkMock) Test(org.junit.jupiter.api.Test)

Example 8 with DecodingFormatMock

use of org.apache.flink.table.factories.TestFormatFactory.DecodingFormatMock in project flink by apache.

the class FactoryUtilTest method testAlternativeValueFormat.

@Test
public void testAlternativeValueFormat() {
    final Map<String, String> options = createAllOptions();
    options.remove("value.format");
    options.remove("value.test-format.delimiter");
    options.remove("value.test-format.fail-on-missing");
    options.put("format", "test-format");
    options.put("test-format.delimiter", ";");
    options.put("test-format.fail-on-missing", "true");
    final DynamicTableSource actualSource = createTableSource(SCHEMA, options);
    final DynamicTableSource expectedSource = new DynamicTableSourceMock("MyTarget", null, new DecodingFormatMock(",", false), new DecodingFormatMock(";", true));
    assertThat(actualSource).isEqualTo(expectedSource);
    final DynamicTableSink actualSink = createTableSink(SCHEMA, options);
    final DynamicTableSink expectedSink = new DynamicTableSinkMock("MyTarget", 1000L, new EncodingFormatMock(","), new EncodingFormatMock(";"));
    assertThat(actualSink).isEqualTo(expectedSink);
}
Also used : EncodingFormatMock(org.apache.flink.table.factories.TestFormatFactory.EncodingFormatMock) DecodingFormatMock(org.apache.flink.table.factories.TestFormatFactory.DecodingFormatMock) DynamicTableSink(org.apache.flink.table.connector.sink.DynamicTableSink) DynamicTableSourceMock(org.apache.flink.table.factories.TestDynamicTableFactory.DynamicTableSourceMock) DynamicTableSource(org.apache.flink.table.connector.source.DynamicTableSource) DynamicTableSinkMock(org.apache.flink.table.factories.TestDynamicTableFactory.DynamicTableSinkMock) Test(org.junit.jupiter.api.Test)

Example 9 with DecodingFormatMock

use of org.apache.flink.table.factories.TestFormatFactory.DecodingFormatMock in project flink by apache.

the class FactoryUtilTest method testOptionalFormat.

@Test
public void testOptionalFormat() {
    final Map<String, String> options = createAllOptions();
    options.remove("key.format");
    options.remove("key.test-format.delimiter");
    final DynamicTableSource actualSource = createTableSource(SCHEMA, options);
    final DynamicTableSource expectedSource = new DynamicTableSourceMock("MyTarget", null, null, new DecodingFormatMock("|", true));
    assertThat(actualSource).isEqualTo(expectedSource);
    final DynamicTableSink actualSink = createTableSink(SCHEMA, options);
    final DynamicTableSink expectedSink = new DynamicTableSinkMock("MyTarget", 1000L, null, new EncodingFormatMock("|"));
    assertThat(actualSink).isEqualTo(expectedSink);
}
Also used : EncodingFormatMock(org.apache.flink.table.factories.TestFormatFactory.EncodingFormatMock) DecodingFormatMock(org.apache.flink.table.factories.TestFormatFactory.DecodingFormatMock) DynamicTableSink(org.apache.flink.table.connector.sink.DynamicTableSink) DynamicTableSourceMock(org.apache.flink.table.factories.TestDynamicTableFactory.DynamicTableSourceMock) DynamicTableSource(org.apache.flink.table.connector.source.DynamicTableSource) DynamicTableSinkMock(org.apache.flink.table.factories.TestDynamicTableFactory.DynamicTableSinkMock) Test(org.junit.jupiter.api.Test)

Aggregations

DecodingFormatMock (org.apache.flink.table.factories.TestFormatFactory.DecodingFormatMock)9 Test (org.junit.jupiter.api.Test)9 DynamicTableSource (org.apache.flink.table.connector.source.DynamicTableSource)8 HashMap (java.util.HashMap)4 DynamicTableSink (org.apache.flink.table.connector.sink.DynamicTableSink)4 DynamicTableSinkMock (org.apache.flink.table.factories.TestDynamicTableFactory.DynamicTableSinkMock)4 DynamicTableSourceMock (org.apache.flink.table.factories.TestDynamicTableFactory.DynamicTableSourceMock)4 EncodingFormatMock (org.apache.flink.table.factories.TestFormatFactory.EncodingFormatMock)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 DeserializationSchema (org.apache.flink.api.common.serialization.DeserializationSchema)2 KafkaTopicPartition (org.apache.flink.streaming.connectors.kafka.internals.KafkaTopicPartition)2 ScanTableSource (org.apache.flink.table.connector.source.ScanTableSource)2 DataType (org.apache.flink.table.types.DataType)1