use of org.apache.flink.table.connector.sink.DynamicTableSink 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);
}
use of org.apache.flink.table.connector.sink.DynamicTableSink 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);
}
use of org.apache.flink.table.connector.sink.DynamicTableSink 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);
}
use of org.apache.flink.table.connector.sink.DynamicTableSink in project flink by apache.
the class TestValuesTableFactory method createDynamicTableSink.
@Override
public DynamicTableSink createDynamicTableSink(Context context) {
FactoryUtil.TableFactoryHelper helper = FactoryUtil.createTableFactoryHelper(this, context);
helper.validate();
String sinkClass = helper.getOptions().get(TABLE_SINK_CLASS);
boolean isInsertOnly = helper.getOptions().get(SINK_INSERT_ONLY);
String runtimeSink = helper.getOptions().get(RUNTIME_SINK);
int expectedNum = helper.getOptions().get(SINK_EXPECTED_MESSAGES_NUM);
Integer parallelism = helper.getOptions().get(SINK_PARALLELISM);
boolean dropLateEvent = helper.getOptions().get(SINK_DROP_LATE_EVENT);
final Map<String, DataType> writableMetadata = convertToMetadataMap(helper.getOptions().get(WRITABLE_METADATA), context.getClassLoader());
final ChangelogMode changelogMode = Optional.ofNullable(helper.getOptions().get(SINK_CHANGELOG_MODE_ENFORCED)).map(m -> parseChangelogMode(m)).orElse(null);
final DataType consumedType = context.getCatalogTable().getSchema().toPhysicalRowDataType();
final int[] primaryKeyIndices = TableSchemaUtils.getPrimaryKeyIndices(context.getCatalogTable().getSchema());
if (sinkClass.equals("DEFAULT")) {
int rowTimeIndex = validateAndExtractRowtimeIndex(context.getCatalogTable(), dropLateEvent, isInsertOnly);
return new TestValuesTableSink(consumedType, primaryKeyIndices, context.getObjectIdentifier().getObjectName(), isInsertOnly, runtimeSink, expectedNum, writableMetadata, parallelism, changelogMode, rowTimeIndex);
} else {
try {
return InstantiationUtil.instantiate(sinkClass, DynamicTableSink.class, Thread.currentThread().getContextClassLoader());
} catch (FlinkException e) {
throw new TableException("Can't instantiate class " + sinkClass, e);
}
}
}
Aggregations