Search in sources :

Example 6 with ChangelogMode

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));
}
Also used : ChangelogMode(org.apache.flink.table.connector.ChangelogMode) DynamicTableSink(org.apache.flink.table.connector.sink.DynamicTableSink) Test(org.junit.jupiter.api.Test)

Example 7 with 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);
}
Also used : ChangelogMode(org.apache.flink.table.connector.ChangelogMode)

Example 8 with 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);
}
Also used : ChangelogMode(org.apache.flink.table.connector.ChangelogMode) DataType(org.apache.flink.table.types.DataType)

Example 9 with ChangelogMode

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);
}
Also used : ChangelogMode(org.apache.flink.table.connector.ChangelogMode) StringWriter(java.io.StringWriter) JsonGenerator(org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonGenerator) ObjectMapper(org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 10 with ChangelogMode

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;
}
Also used : ScanTableSource(org.apache.flink.table.connector.source.ScanTableSource) ChangelogMode(org.apache.flink.table.connector.ChangelogMode)

Aggregations

ChangelogMode (org.apache.flink.table.connector.ChangelogMode)13 DataType (org.apache.flink.table.types.DataType)4 Collections (java.util.Collections)3 List (java.util.List)3 TableException (org.apache.flink.table.api.TableException)3 DynamicTableSink (org.apache.flink.table.connector.sink.DynamicTableSink)3 ScanTableSource (org.apache.flink.table.connector.source.ScanTableSource)3 FactoryUtil (org.apache.flink.table.factories.FactoryUtil)3 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 Optional (java.util.Optional)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 Nullable (javax.annotation.Nullable)2 Internal (org.apache.flink.annotation.Internal)2 TypeInformation (org.apache.flink.api.common.typeinfo.TypeInformation)2