Search in sources :

Example 36 with DynamicTableSource

use of org.apache.flink.table.connector.source.DynamicTableSource in project flink by apache.

the class DebeziumAvroFormatFactoryTest method createDeserializationSchema.

private static DeserializationSchema<RowData> createDeserializationSchema(Map<String, String> options) {
    final DynamicTableSource actualSource = createTableSource(SCHEMA, options);
    assertThat(actualSource, instanceOf(TestDynamicTableFactory.DynamicTableSourceMock.class));
    TestDynamicTableFactory.DynamicTableSourceMock scanSourceMock = (TestDynamicTableFactory.DynamicTableSourceMock) actualSource;
    return scanSourceMock.valueFormat.createRuntimeDecoder(ScanRuntimeProviderContext.INSTANCE, SCHEMA.toPhysicalRowDataType());
}
Also used : TestDynamicTableFactory(org.apache.flink.table.factories.TestDynamicTableFactory) DynamicTableSource(org.apache.flink.table.connector.source.DynamicTableSource)

Example 37 with DynamicTableSource

use of org.apache.flink.table.connector.source.DynamicTableSource in project flink by apache.

the class JdbcDynamicTableFactoryTest method testJdbcReadProperties.

@Test
public void testJdbcReadProperties() {
    Map<String, String> properties = getAllOptions();
    properties.put("scan.partition.column", "aaa");
    properties.put("scan.partition.lower-bound", "-10");
    properties.put("scan.partition.upper-bound", "100");
    properties.put("scan.partition.num", "10");
    properties.put("scan.fetch-size", "20");
    properties.put("scan.auto-commit", "false");
    DynamicTableSource actual = createTableSource(SCHEMA, properties);
    JdbcConnectorOptions options = JdbcConnectorOptions.builder().setDBUrl("jdbc:derby:memory:mydb").setTableName("mytable").build();
    JdbcReadOptions readOptions = JdbcReadOptions.builder().setPartitionColumnName("aaa").setPartitionLowerBound(-10).setPartitionUpperBound(100).setNumPartitions(10).setFetchSize(20).setAutoCommit(false).build();
    JdbcLookupOptions lookupOptions = JdbcLookupOptions.builder().setCacheMaxSize(-1).setCacheExpireMs(10_000).setMaxRetryTimes(3).build();
    JdbcDynamicTableSource expected = new JdbcDynamicTableSource(options, readOptions, lookupOptions, SCHEMA.toPhysicalRowDataType());
    assertEquals(expected, actual);
}
Also used : JdbcLookupOptions(org.apache.flink.connector.jdbc.internal.options.JdbcLookupOptions) JdbcConnectorOptions(org.apache.flink.connector.jdbc.internal.options.JdbcConnectorOptions) JdbcReadOptions(org.apache.flink.connector.jdbc.internal.options.JdbcReadOptions) DynamicTableSource(org.apache.flink.table.connector.source.DynamicTableSource) Test(org.junit.Test)

Example 38 with DynamicTableSource

use of org.apache.flink.table.connector.source.DynamicTableSource in project flink by apache.

the class DebeziumJsonFormatFactoryTest method testSeDeSchema.

@Test
public void testSeDeSchema() {
    final DebeziumJsonDeserializationSchema expectedDeser = new DebeziumJsonDeserializationSchema(PHYSICAL_DATA_TYPE, Collections.emptyList(), InternalTypeInfo.of(PHYSICAL_TYPE), false, true, TimestampFormat.ISO_8601);
    final Map<String, String> options = getAllOptions();
    final DynamicTableSource actualSource = createTableSource(SCHEMA, options);
    assert actualSource instanceof TestDynamicTableFactory.DynamicTableSourceMock;
    TestDynamicTableFactory.DynamicTableSourceMock scanSourceMock = (TestDynamicTableFactory.DynamicTableSourceMock) actualSource;
    DeserializationSchema<RowData> actualDeser = scanSourceMock.valueFormat.createRuntimeDecoder(ScanRuntimeProviderContext.INSTANCE, PHYSICAL_DATA_TYPE);
    assertEquals(expectedDeser, actualDeser);
    final DebeziumJsonSerializationSchema expectedSer = new DebeziumJsonSerializationSchema((RowType) PHYSICAL_DATA_TYPE.getLogicalType(), TimestampFormat.ISO_8601, JsonFormatOptions.MapNullKeyMode.LITERAL, "null", true);
    final DynamicTableSink actualSink = createTableSink(SCHEMA, options);
    assert actualSink instanceof TestDynamicTableFactory.DynamicTableSinkMock;
    TestDynamicTableFactory.DynamicTableSinkMock sinkMock = (TestDynamicTableFactory.DynamicTableSinkMock) actualSink;
    SerializationSchema<RowData> actualSer = sinkMock.valueFormat.createRuntimeEncoder(new SinkRuntimeProviderContext(false), PHYSICAL_DATA_TYPE);
    assertEquals(expectedSer, actualSer);
}
Also used : SinkRuntimeProviderContext(org.apache.flink.table.runtime.connector.sink.SinkRuntimeProviderContext) DynamicTableSink(org.apache.flink.table.connector.sink.DynamicTableSink) TestDynamicTableFactory(org.apache.flink.table.factories.TestDynamicTableFactory) RowData(org.apache.flink.table.data.RowData) DynamicTableSource(org.apache.flink.table.connector.source.DynamicTableSource) Test(org.junit.Test)

Example 39 with DynamicTableSource

use of org.apache.flink.table.connector.source.DynamicTableSource in project flink by apache.

the class DebeziumJsonFormatFactoryTest method testSchemaIncludeOption.

@Test
public void testSchemaIncludeOption() {
    Map<String, String> options = getAllOptions();
    options.put("debezium-json.schema-include", "true");
    final DebeziumJsonDeserializationSchema expectedDeser = new DebeziumJsonDeserializationSchema(PHYSICAL_DATA_TYPE, Collections.emptyList(), InternalTypeInfo.of(PHYSICAL_DATA_TYPE.getLogicalType()), true, true, TimestampFormat.ISO_8601);
    final DynamicTableSource actualSource = createTableSource(SCHEMA, options);
    TestDynamicTableFactory.DynamicTableSourceMock scanSourceMock = (TestDynamicTableFactory.DynamicTableSourceMock) actualSource;
    DeserializationSchema<RowData> actualDeser = scanSourceMock.valueFormat.createRuntimeDecoder(ScanRuntimeProviderContext.INSTANCE, PHYSICAL_DATA_TYPE);
    assertEquals(expectedDeser, actualDeser);
    try {
        final DynamicTableSink actualSink = createTableSink(SCHEMA, options);
        TestDynamicTableFactory.DynamicTableSinkMock sinkMock = (TestDynamicTableFactory.DynamicTableSinkMock) actualSink;
        // should fail
        sinkMock.valueFormat.createRuntimeEncoder(new SinkRuntimeProviderContext(false), PHYSICAL_DATA_TYPE);
        fail();
    } catch (Exception e) {
        assertEquals(e.getCause().getCause().getMessage(), "Debezium JSON serialization doesn't support " + "'debezium-json.schema-include' option been set to true.");
    }
}
Also used : SinkRuntimeProviderContext(org.apache.flink.table.runtime.connector.sink.SinkRuntimeProviderContext) DynamicTableSink(org.apache.flink.table.connector.sink.DynamicTableSink) TestDynamicTableFactory(org.apache.flink.table.factories.TestDynamicTableFactory) ExpectedException(org.junit.rules.ExpectedException) ValidationException(org.apache.flink.table.api.ValidationException) RowData(org.apache.flink.table.data.RowData) DynamicTableSource(org.apache.flink.table.connector.source.DynamicTableSource) Test(org.junit.Test)

Example 40 with DynamicTableSource

use of org.apache.flink.table.connector.source.DynamicTableSource in project flink by apache.

the class MaxwellJsonFormatFactoryTest method testSeDeSchema.

@Test
public void testSeDeSchema() {
    final MaxwellJsonDeserializationSchema expectedDeser = new MaxwellJsonDeserializationSchema(PHYSICAL_DATA_TYPE, Collections.emptyList(), ROW_TYPE_INFO, true, TimestampFormat.ISO_8601);
    final MaxwellJsonSerializationSchema expectedSer = new MaxwellJsonSerializationSchema(PHYSICAL_TYPE, TimestampFormat.ISO_8601, JsonFormatOptions.MapNullKeyMode.LITERAL, "null", true);
    final Map<String, String> options = getAllOptions();
    final DynamicTableSource actualSource = createTableSource(SCHEMA, options);
    assert actualSource instanceof TestDynamicTableFactory.DynamicTableSourceMock;
    TestDynamicTableFactory.DynamicTableSourceMock scanSourceMock = (TestDynamicTableFactory.DynamicTableSourceMock) actualSource;
    DeserializationSchema<RowData> actualDeser = scanSourceMock.valueFormat.createRuntimeDecoder(ScanRuntimeProviderContext.INSTANCE, SCHEMA.toPhysicalRowDataType());
    assertEquals(expectedDeser, actualDeser);
    final DynamicTableSink actualSink = createTableSink(SCHEMA, options);
    assert actualSink instanceof TestDynamicTableFactory.DynamicTableSinkMock;
    TestDynamicTableFactory.DynamicTableSinkMock sinkMock = (TestDynamicTableFactory.DynamicTableSinkMock) actualSink;
    SerializationSchema<RowData> actualSer = sinkMock.valueFormat.createRuntimeEncoder(new SinkRuntimeProviderContext(false), SCHEMA.toPhysicalRowDataType());
    assertEquals(expectedSer, actualSer);
}
Also used : SinkRuntimeProviderContext(org.apache.flink.table.runtime.connector.sink.SinkRuntimeProviderContext) DynamicTableSink(org.apache.flink.table.connector.sink.DynamicTableSink) TestDynamicTableFactory(org.apache.flink.table.factories.TestDynamicTableFactory) RowData(org.apache.flink.table.data.RowData) DynamicTableSource(org.apache.flink.table.connector.source.DynamicTableSource) Test(org.junit.Test)

Aggregations

DynamicTableSource (org.apache.flink.table.connector.source.DynamicTableSource)55 Test (org.junit.Test)24 DynamicTableSink (org.apache.flink.table.connector.sink.DynamicTableSink)12 TestDynamicTableFactory (org.apache.flink.table.factories.TestDynamicTableFactory)12 Test (org.junit.jupiter.api.Test)10 RowData (org.apache.flink.table.data.RowData)9 DecodingFormatMock (org.apache.flink.table.factories.TestFormatFactory.DecodingFormatMock)8 TableSourceTable (org.apache.flink.table.planner.plan.schema.TableSourceTable)8 ResolvedSchema (org.apache.flink.table.catalog.ResolvedSchema)7 HashMap (java.util.HashMap)5 Configuration (org.apache.flink.configuration.Configuration)5 ScanTableSource (org.apache.flink.table.connector.source.ScanTableSource)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 ArrayList (java.util.ArrayList)4 JdbcConnectorOptions (org.apache.flink.connector.jdbc.internal.options.JdbcConnectorOptions)4 JdbcLookupOptions (org.apache.flink.connector.jdbc.internal.options.JdbcLookupOptions)4 CatalogTable (org.apache.flink.table.catalog.CatalogTable)4 SourceAbilitySpec (org.apache.flink.table.planner.plan.abilities.source.SourceAbilitySpec)4 List (java.util.List)3 LogicalTableScan (org.apache.calcite.rel.logical.LogicalTableScan)3