Search in sources :

Example 1 with TestTableResult

use of org.apache.flink.table.client.cli.utils.TestTableResult in project flink by apache.

the class MaterializedCollectBatchResultTest method testSnapshot.

@Test
public void testSnapshot() throws Exception {
    final ResolvedSchema schema = ResolvedSchema.physical(new String[] { "f0", "f1" }, new DataType[] { DataTypes.STRING(), DataTypes.INT() });
    @SuppressWarnings({ "unchecked", "rawtypes" }) final DataStructureConverter<RowData, Row> rowConverter = (DataStructureConverter) DataStructureConverters.getConverter(schema.toPhysicalRowDataType());
    try (TestMaterializedCollectBatchResult result = new TestMaterializedCollectBatchResult(new TestTableResult(ResultKind.SUCCESS_WITH_CONTENT, schema), Integer.MAX_VALUE, createInternalBinaryRowDataConverter(schema.toPhysicalRowDataType()))) {
        result.isRetrieving = true;
        result.processRecord(Row.of("A", 1));
        result.processRecord(Row.of("B", 1));
        result.processRecord(Row.of("A", 1));
        result.processRecord(Row.of("C", 2));
        assertEquals(TypedResult.payload(4), result.snapshot(1));
        assertRowEquals(Collections.singletonList(Row.of("A", 1)), result.retrievePage(1), rowConverter);
        assertRowEquals(Collections.singletonList(Row.of("B", 1)), result.retrievePage(2), rowConverter);
        assertRowEquals(Collections.singletonList(Row.of("A", 1)), result.retrievePage(3), rowConverter);
        assertRowEquals(Collections.singletonList(Row.of("C", 2)), result.retrievePage(4), rowConverter);
        result.processRecord(Row.of("A", 1));
        assertEquals(TypedResult.payload(5), result.snapshot(1));
        assertRowEquals(Collections.singletonList(Row.of("A", 1)), result.retrievePage(1), rowConverter);
        assertRowEquals(Collections.singletonList(Row.of("B", 1)), result.retrievePage(2), rowConverter);
        assertRowEquals(Collections.singletonList(Row.of("A", 1)), result.retrievePage(3), rowConverter);
        assertRowEquals(Collections.singletonList(Row.of("C", 2)), result.retrievePage(4), rowConverter);
        assertRowEquals(Collections.singletonList(Row.of("A", 1)), result.retrievePage(5), rowConverter);
    }
}
Also used : RowData(org.apache.flink.table.data.RowData) BinaryRowData(org.apache.flink.table.data.binary.BinaryRowData) DataStructureConverter(org.apache.flink.table.data.conversion.DataStructureConverter) Row(org.apache.flink.types.Row) TestTableResult(org.apache.flink.table.client.cli.utils.TestTableResult) ResolvedSchema(org.apache.flink.table.catalog.ResolvedSchema) Test(org.junit.Test)

Example 2 with TestTableResult

use of org.apache.flink.table.client.cli.utils.TestTableResult in project flink by apache.

the class MaterializedCollectBatchResultTest method testLimitedSnapshot.

@Test
public void testLimitedSnapshot() throws Exception {
    final ResolvedSchema schema = ResolvedSchema.physical(new String[] { "f0", "f1" }, new DataType[] { DataTypes.STRING(), DataTypes.INT() });
    @SuppressWarnings({ "unchecked", "rawtypes" }) final DataStructureConverter<RowData, Row> rowConverter = (DataStructureConverter) DataStructureConverters.getConverter(schema.toPhysicalRowDataType());
    try (TestMaterializedCollectBatchResult result = new TestMaterializedCollectBatchResult(new TestTableResult(ResultKind.SUCCESS_WITH_CONTENT, schema), // limit the materialized table to 2 rows
    2, 3, createInternalBinaryRowDataConverter(schema.toPhysicalRowDataType()))) {
        // with 3 rows overcommitment
        result.isRetrieving = true;
        result.processRecord(Row.of("D", 1));
        result.processRecord(Row.of("A", 1));
        result.processRecord(Row.of("B", 1));
        result.processRecord(Row.of("A", 1));
        assertRowEquals(Arrays.asList(null, null, Row.of("B", 1), // two over-committed rows
        Row.of("A", 1)), result.getMaterializedTable(), rowConverter);
        assertEquals(TypedResult.payload(2), result.snapshot(1));
        assertRowEquals(Collections.singletonList(Row.of("B", 1)), result.retrievePage(1), rowConverter);
        assertRowEquals(Collections.singletonList(Row.of("A", 1)), result.retrievePage(2), rowConverter);
        result.processRecord(Row.of("C", 1));
        assertRowEquals(// limit clean up has taken place
        Arrays.asList(Row.of("A", 1), Row.of("C", 1)), result.getMaterializedTable(), rowConverter);
        result.processRecord(Row.of("A", 1));
        assertRowEquals(Arrays.asList(null, Row.of("C", 1), Row.of("A", 1)), result.getMaterializedTable(), rowConverter);
    }
}
Also used : RowData(org.apache.flink.table.data.RowData) BinaryRowData(org.apache.flink.table.data.binary.BinaryRowData) DataStructureConverter(org.apache.flink.table.data.conversion.DataStructureConverter) Row(org.apache.flink.types.Row) TestTableResult(org.apache.flink.table.client.cli.utils.TestTableResult) ResolvedSchema(org.apache.flink.table.catalog.ResolvedSchema) Test(org.junit.Test)

Example 3 with TestTableResult

use of org.apache.flink.table.client.cli.utils.TestTableResult in project flink by apache.

the class ChangelogCollectResultTest method testRetrieveChanges.

@Test
public void testRetrieveChanges() throws Exception {
    int totalCount = ChangelogCollectResult.CHANGE_RECORD_BUFFER_SIZE * 2;
    CloseableIterator<Row> data = CloseableIterator.adapterForIterator(IntStream.range(0, totalCount).mapToObj(Row::of).iterator());
    ChangelogCollectResult changelogResult = new ChangelogCollectResult(new TestTableResult(ResultKind.SUCCESS_WITH_CONTENT, ResolvedSchema.of(Column.physical("id", DataTypes.INT())), data));
    int count = 0;
    boolean running = true;
    while (running) {
        final TypedResult<List<RowData>> result = changelogResult.retrieveChanges();
        // slow the processing down
        Thread.sleep(100);
        switch(result.getType()) {
            case EMPTY:
                // do nothing
                break;
            case EOS:
                running = false;
                break;
            case PAYLOAD:
                count += result.getPayload().size();
                break;
            default:
                throw new SqlExecutionException("Unknown result type: " + result.getType());
        }
    }
    assertEquals(totalCount, count);
}
Also used : SqlExecutionException(org.apache.flink.table.client.gateway.SqlExecutionException) List(java.util.List) Row(org.apache.flink.types.Row) TestTableResult(org.apache.flink.table.client.cli.utils.TestTableResult) Test(org.junit.Test)

Example 4 with TestTableResult

use of org.apache.flink.table.client.cli.utils.TestTableResult in project flink by apache.

the class MaterializedCollectStreamResultTest method testSnapshot.

@Test
public void testSnapshot() throws Exception {
    final ResolvedSchema schema = ResolvedSchema.physical(new String[] { "f0", "f1" }, new DataType[] { DataTypes.STRING(), DataTypes.INT() });
    @SuppressWarnings({ "unchecked", "rawtypes" }) final DataStructureConverter<RowData, Row> rowConverter = (DataStructureConverter) DataStructureConverters.getConverter(schema.toPhysicalRowDataType());
    try (TestMaterializedCollectStreamResult result = new TestMaterializedCollectStreamResult(new TestTableResult(ResultKind.SUCCESS_WITH_CONTENT, schema), Integer.MAX_VALUE, createInternalBinaryRowDataConverter(schema.toPhysicalRowDataType()))) {
        result.isRetrieving = true;
        result.processRecord(Row.ofKind(RowKind.INSERT, "A", 1));
        result.processRecord(Row.ofKind(RowKind.INSERT, "B", 1));
        result.processRecord(Row.ofKind(RowKind.INSERT, "A", 1));
        result.processRecord(Row.ofKind(RowKind.INSERT, "C", 2));
        assertEquals(TypedResult.payload(4), result.snapshot(1));
        assertRowEquals(Collections.singletonList(Row.of("A", 1)), result.retrievePage(1), rowConverter);
        assertRowEquals(Collections.singletonList(Row.of("B", 1)), result.retrievePage(2), rowConverter);
        assertRowEquals(Collections.singletonList(Row.of("A", 1)), result.retrievePage(3), rowConverter);
        assertRowEquals(Collections.singletonList(Row.of("C", 2)), result.retrievePage(4), rowConverter);
        result.processRecord(Row.ofKind(RowKind.UPDATE_BEFORE, "A", 1));
        assertEquals(TypedResult.payload(3), result.snapshot(1));
        assertRowEquals(Collections.singletonList(Row.of("A", 1)), result.retrievePage(1), rowConverter);
        assertRowEquals(Collections.singletonList(Row.of("B", 1)), result.retrievePage(2), rowConverter);
        assertRowEquals(Collections.singletonList(Row.of("C", 2)), result.retrievePage(3), rowConverter);
        result.processRecord(Row.ofKind(RowKind.UPDATE_BEFORE, "C", 2));
        result.processRecord(Row.ofKind(RowKind.UPDATE_BEFORE, "A", 1));
        result.processRecord(Row.ofKind(RowKind.UPDATE_AFTER, "D", 1));
        assertEquals(TypedResult.payload(2), result.snapshot(1));
        assertRowEquals(Collections.singletonList(Row.of("B", 1)), result.retrievePage(1), rowConverter);
        assertRowEquals(Collections.singletonList(Row.of("D", 1)), result.retrievePage(2), rowConverter);
    }
}
Also used : RowData(org.apache.flink.table.data.RowData) BinaryRowData(org.apache.flink.table.data.binary.BinaryRowData) DataStructureConverter(org.apache.flink.table.data.conversion.DataStructureConverter) Row(org.apache.flink.types.Row) TestTableResult(org.apache.flink.table.client.cli.utils.TestTableResult) ResolvedSchema(org.apache.flink.table.catalog.ResolvedSchema) Test(org.junit.Test)

Example 5 with TestTableResult

use of org.apache.flink.table.client.cli.utils.TestTableResult in project flink by apache.

the class MaterializedCollectStreamResultTest method testLimitedSnapshot.

@Test
public void testLimitedSnapshot() throws Exception {
    final ResolvedSchema schema = ResolvedSchema.physical(new String[] { "f0", "f1" }, new DataType[] { DataTypes.STRING(), DataTypes.INT() });
    @SuppressWarnings({ "unchecked", "rawtypes" }) final DataStructureConverter<RowData, Row> rowConverter = (DataStructureConverter) DataStructureConverters.getConverter(schema.toPhysicalRowDataType());
    // with 3 rows overcommitment
    try (TestMaterializedCollectStreamResult result = new TestMaterializedCollectStreamResult(new TestTableResult(ResultKind.SUCCESS_WITH_CONTENT, schema), 2, 3, createInternalBinaryRowDataConverter(schema.toPhysicalRowDataType()))) {
        result.isRetrieving = true;
        result.processRecord(Row.ofKind(RowKind.INSERT, "D", 1));
        result.processRecord(Row.ofKind(RowKind.INSERT, "A", 1));
        result.processRecord(Row.ofKind(RowKind.INSERT, "B", 1));
        result.processRecord(Row.ofKind(RowKind.INSERT, "A", 1));
        assertRowEquals(Arrays.asList(null, null, Row.ofKind(RowKind.INSERT, "B", 1), // two over-committed rows
        Row.ofKind(RowKind.INSERT, "A", 1)), result.getMaterializedTable(), rowConverter);
        assertEquals(TypedResult.payload(2), result.snapshot(1));
        assertRowEquals(Collections.singletonList(Row.ofKind(RowKind.INSERT, "B", 1)), result.retrievePage(1), rowConverter);
        assertRowEquals(Collections.singletonList(Row.ofKind(RowKind.INSERT, "A", 1)), result.retrievePage(2), rowConverter);
        result.processRecord(Row.ofKind(RowKind.INSERT, "C", 1));
        assertRowEquals(Arrays.asList(Row.ofKind(RowKind.INSERT, "A", 1), // limit clean up has taken place
        Row.ofKind(RowKind.INSERT, "C", 1)), result.getMaterializedTable(), rowConverter);
        result.processRecord(Row.ofKind(RowKind.DELETE, "A", 1));
        assertRowEquals(Collections.singletonList(// regular clean up has taken place
        Row.ofKind(RowKind.INSERT, "C", 1)), result.getMaterializedTable(), rowConverter);
    }
}
Also used : RowData(org.apache.flink.table.data.RowData) BinaryRowData(org.apache.flink.table.data.binary.BinaryRowData) DataStructureConverter(org.apache.flink.table.data.conversion.DataStructureConverter) Row(org.apache.flink.types.Row) TestTableResult(org.apache.flink.table.client.cli.utils.TestTableResult) ResolvedSchema(org.apache.flink.table.catalog.ResolvedSchema) Test(org.junit.Test)

Aggregations

TestTableResult (org.apache.flink.table.client.cli.utils.TestTableResult)5 Row (org.apache.flink.types.Row)5 Test (org.junit.Test)5 ResolvedSchema (org.apache.flink.table.catalog.ResolvedSchema)4 RowData (org.apache.flink.table.data.RowData)4 BinaryRowData (org.apache.flink.table.data.binary.BinaryRowData)4 DataStructureConverter (org.apache.flink.table.data.conversion.DataStructureConverter)4 List (java.util.List)1 SqlExecutionException (org.apache.flink.table.client.gateway.SqlExecutionException)1