Search in sources :

Example 1 with DataGenTableSource

use of org.apache.flink.connector.datagen.table.DataGenTableSource in project flink by apache.

the class DataGenTableSourceFactoryTest method testSequenceCheckpointRestore.

@Test
public void testSequenceCheckpointRestore() throws Exception {
    DescriptorProperties descriptor = new DescriptorProperties();
    descriptor.putString(FactoryUtil.CONNECTOR.key(), "datagen");
    descriptor.putString(DataGenConnectorOptionsUtil.FIELDS + ".f0." + DataGenConnectorOptionsUtil.KIND, DataGenConnectorOptionsUtil.SEQUENCE);
    descriptor.putLong(DataGenConnectorOptionsUtil.FIELDS + ".f0." + DataGenConnectorOptionsUtil.START, 0);
    descriptor.putLong(DataGenConnectorOptionsUtil.FIELDS + ".f0." + DataGenConnectorOptionsUtil.END, 100);
    DynamicTableSource dynamicTableSource = createTableSource(ResolvedSchema.of(Column.physical("f0", DataTypes.BIGINT())), descriptor.asMap());
    DataGenTableSource dataGenTableSource = (DataGenTableSource) dynamicTableSource;
    DataGeneratorSource<RowData> source = dataGenTableSource.createSource();
    final int initElement = 0;
    final int maxElement = 100;
    final Set<RowData> expectedOutput = new HashSet<>();
    for (long i = initElement; i <= maxElement; i++) {
        expectedOutput.add(GenericRowData.of(i));
    }
    DataGeneratorSourceTest.innerTestDataGenCheckpointRestore(() -> {
        try {
            return InstantiationUtil.clone(source);
        } catch (IOException | ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
    }, expectedOutput);
}
Also used : DescriptorProperties(org.apache.flink.table.descriptors.DescriptorProperties) IOException(java.io.IOException) GenericRowData(org.apache.flink.table.data.GenericRowData) RowData(org.apache.flink.table.data.RowData) DynamicTableSource(org.apache.flink.table.connector.source.DynamicTableSource) DataGenTableSource(org.apache.flink.connector.datagen.table.DataGenTableSource) HashSet(java.util.HashSet) DataGeneratorSourceTest(org.apache.flink.streaming.api.functions.source.datagen.DataGeneratorSourceTest) Test(org.junit.Test)

Example 2 with DataGenTableSource

use of org.apache.flink.connector.datagen.table.DataGenTableSource in project flink by apache.

the class DataGenTableSourceFactoryTest method runGenerator.

private List<RowData> runGenerator(ResolvedSchema schema, DescriptorProperties descriptor) throws Exception {
    DynamicTableSource source = createTableSource(schema, descriptor.asMap());
    assertTrue(source instanceof DataGenTableSource);
    DataGenTableSource dataGenTableSource = (DataGenTableSource) source;
    DataGeneratorSource<RowData> gen = dataGenTableSource.createSource();
    // test java serialization.
    gen = InstantiationUtil.clone(gen);
    StreamSource<RowData, DataGeneratorSource<RowData>> src = new StreamSource<>(gen);
    AbstractStreamOperatorTestHarness<RowData> testHarness = new AbstractStreamOperatorTestHarness<>(src, 1, 1, 0);
    testHarness.open();
    TestContext ctx = new TestContext();
    gen.run(ctx);
    return ctx.results;
}
Also used : GenericRowData(org.apache.flink.table.data.GenericRowData) RowData(org.apache.flink.table.data.RowData) DataGeneratorSource(org.apache.flink.streaming.api.functions.source.datagen.DataGeneratorSource) StreamSource(org.apache.flink.streaming.api.operators.StreamSource) DynamicTableSource(org.apache.flink.table.connector.source.DynamicTableSource) DataGenTableSource(org.apache.flink.connector.datagen.table.DataGenTableSource) AbstractStreamOperatorTestHarness(org.apache.flink.streaming.util.AbstractStreamOperatorTestHarness)

Aggregations

DataGenTableSource (org.apache.flink.connector.datagen.table.DataGenTableSource)2 DynamicTableSource (org.apache.flink.table.connector.source.DynamicTableSource)2 GenericRowData (org.apache.flink.table.data.GenericRowData)2 RowData (org.apache.flink.table.data.RowData)2 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 DataGeneratorSource (org.apache.flink.streaming.api.functions.source.datagen.DataGeneratorSource)1 DataGeneratorSourceTest (org.apache.flink.streaming.api.functions.source.datagen.DataGeneratorSourceTest)1 StreamSource (org.apache.flink.streaming.api.operators.StreamSource)1 AbstractStreamOperatorTestHarness (org.apache.flink.streaming.util.AbstractStreamOperatorTestHarness)1 DescriptorProperties (org.apache.flink.table.descriptors.DescriptorProperties)1 Test (org.junit.Test)1