use of org.apache.flink.table.connector.ChangelogMode in project flink by apache.
the class ElasticsearchDynamicSinkFactoryBaseTest method validateDynamicIndexOnChangelogStream.
@Test
public void validateDynamicIndexOnChangelogStream() {
ElasticsearchDynamicSinkFactoryBase sinkFactory = createSinkFactory();
DynamicTableSink sink = sinkFactory.createDynamicTableSink(createPrefilledTestContext().withOption(ElasticsearchConnectorOptions.INDEX_OPTION.key(), "dynamic-index-{now()|yyyy-MM-dd}_index").build());
ChangelogMode changelogMode = ChangelogMode.newBuilder().addContainedKind(RowKind.DELETE).addContainedKind(RowKind.INSERT).build();
assertValidationException("Dynamic indexing based on system time only works on append only stream.", () -> sink.getChangelogMode(changelogMode));
}
use of org.apache.flink.table.connector.ChangelogMode in project flink by apache.
the class TestFormatFactory method createEncodingFormat.
@Override
public EncodingFormat<SerializationSchema<RowData>> createEncodingFormat(DynamicTableFactory.Context context, ReadableConfig formatConfig) {
FactoryUtil.validateFactoryOptions(this, formatConfig);
final ChangelogMode changelogMode = parseChangelogMode(formatConfig);
return new EncodingFormatMock(formatConfig.get(DELIMITER), changelogMode);
}
use of org.apache.flink.table.connector.ChangelogMode in project flink by apache.
the class TestFormatFactory method createDecodingFormat.
@Override
public DecodingFormat<DeserializationSchema<RowData>> createDecodingFormat(DynamicTableFactory.Context context, ReadableConfig formatConfig) {
FactoryUtil.validateFactoryOptions(this, formatConfig);
final Map<String, DataType> readableMetadata = convertToMetadataMap(formatConfig.get(READABLE_METADATA), context.getClassLoader());
final ChangelogMode changelogMode = parseChangelogMode(formatConfig);
return new DecodingFormatMock(formatConfig.get(DELIMITER), formatConfig.get(FAIL_ON_MISSING), changelogMode, readableMetadata);
}
use of org.apache.flink.table.connector.ChangelogMode in project flink by apache.
the class ChangelogModeJsonSerdeTest method testChangelogModeSerde.
@Test
public void testChangelogModeSerde() throws IOException {
ObjectMapper mapper = JsonSerdeUtil.getObjectMapper();
ChangelogMode changelogMode = ChangelogMode.newBuilder().addContainedKind(RowKind.INSERT).addContainedKind(RowKind.DELETE).addContainedKind(RowKind.UPDATE_AFTER).addContainedKind(RowKind.UPDATE_BEFORE).build();
StringWriter writer = new StringWriter(100);
try (JsonGenerator gen = mapper.getFactory().createGenerator(writer)) {
gen.writeObject(changelogMode);
}
String json = writer.toString();
ChangelogMode actual = mapper.readValue(json, ChangelogMode.class);
assertEquals(changelogMode, actual);
}
use of org.apache.flink.table.connector.ChangelogMode in project flink by apache.
the class DynamicSourceUtils method isUpsertSource.
/**
* Returns true if the table is an upsert source.
*/
public static boolean isUpsertSource(ResolvedSchema resolvedSchema, DynamicTableSource tableSource) {
if (!(tableSource instanceof ScanTableSource)) {
return false;
}
ChangelogMode mode = ((ScanTableSource) tableSource).getChangelogMode();
boolean isUpsertMode = mode.contains(RowKind.UPDATE_AFTER) && !mode.contains(RowKind.UPDATE_BEFORE);
boolean hasPrimaryKey = resolvedSchema.getPrimaryKey().isPresent();
return isUpsertMode && hasPrimaryKey;
}
Aggregations