Search in sources :

Example 16 with GenericRowData

use of org.apache.flink.table.data.GenericRowData in project flink by apache.

the class DebeziumAvroSerializationSchema method open.

@Override
public void open(InitializationContext context) throws Exception {
    avroSerializer.open(context);
    outputReuse = new GenericRowData(3);
}
Also used : GenericRowData(org.apache.flink.table.data.GenericRowData)

Example 17 with GenericRowData

use of org.apache.flink.table.data.GenericRowData in project flink by apache.

the class PythonTypeUtilsTest method testLogicalTypeToDataConverter.

@Test
public void testLogicalTypeToDataConverter() {
    PythonTypeUtils.DataConverter converter = PythonTypeUtils.toDataConverter(new IntType());
    GenericRowData data = new GenericRowData(1);
    data.setField(0, 10);
    Object externalData = converter.toExternal(data, 0);
    assertTrue(externalData instanceof Long);
    assertEquals(externalData, 10L);
}
Also used : GenericRowData(org.apache.flink.table.data.GenericRowData) BigIntType(org.apache.flink.table.types.logical.BigIntType) IntType(org.apache.flink.table.types.logical.IntType) Test(org.junit.Test)

Example 18 with GenericRowData

use of org.apache.flink.table.data.GenericRowData in project flink by apache.

the class JdbcRowDataInputFormatTest method testJdbcInputFormatWithoutParallelismAndNumericColumnSplitting.

@Test
public void testJdbcInputFormatWithoutParallelismAndNumericColumnSplitting() throws IOException {
    final long min = TEST_DATA[0].id;
    final long max = TEST_DATA[TEST_DATA.length - 1].id;
    // generate a single split
    final long fetchSize = max + 1;
    JdbcParameterValuesProvider pramProvider = new JdbcNumericBetweenParametersProvider(min, max).ofBatchSize(fetchSize);
    inputFormat = JdbcRowDataInputFormat.builder().setDrivername(DERBY_EBOOKSHOP_DB.getDriverClass()).setDBUrl(DERBY_EBOOKSHOP_DB.getUrl()).setQuery(SELECT_ALL_BOOKS_SPLIT_BY_ID).setParametersProvider(pramProvider).setResultSetType(ResultSet.TYPE_SCROLL_INSENSITIVE).setRowConverter(dialect.getRowConverter(rowType)).build();
    inputFormat.openInputFormat();
    InputSplit[] splits = inputFormat.createInputSplits(1);
    // assert that a single split was generated
    Assert.assertEquals(1, splits.length);
    int recordCount = 0;
    RowData row = new GenericRowData(5);
    for (InputSplit split : splits) {
        inputFormat.open(split);
        while (!inputFormat.reachedEnd()) {
            RowData next = inputFormat.nextRecord(row);
            assertEquals(TEST_DATA[recordCount], next);
            recordCount++;
        }
        inputFormat.close();
    }
    inputFormat.closeInputFormat();
    Assert.assertEquals(TEST_DATA.length, recordCount);
}
Also used : GenericRowData(org.apache.flink.table.data.GenericRowData) RowData(org.apache.flink.table.data.RowData) GenericRowData(org.apache.flink.table.data.GenericRowData) JdbcNumericBetweenParametersProvider(org.apache.flink.connector.jdbc.split.JdbcNumericBetweenParametersProvider) InputSplit(org.apache.flink.core.io.InputSplit) JdbcParameterValuesProvider(org.apache.flink.connector.jdbc.split.JdbcParameterValuesProvider) Test(org.junit.Test)

Example 19 with GenericRowData

use of org.apache.flink.table.data.GenericRowData in project flink by apache.

the class JdbcRowDataInputFormatTest method testJdbcInputFormatWithoutParallelism.

@Test
public void testJdbcInputFormatWithoutParallelism() throws IOException {
    inputFormat = JdbcRowDataInputFormat.builder().setDrivername(DERBY_EBOOKSHOP_DB.getDriverClass()).setDBUrl(DERBY_EBOOKSHOP_DB.getUrl()).setQuery(SELECT_ALL_BOOKS).setResultSetType(ResultSet.TYPE_SCROLL_INSENSITIVE).setRowConverter(dialect.getRowConverter(rowType)).build();
    // this query does not exploit parallelism
    Assert.assertEquals(1, inputFormat.createInputSplits(1).length);
    inputFormat.openInputFormat();
    inputFormat.open(null);
    RowData row = new GenericRowData(5);
    int recordCount = 0;
    while (!inputFormat.reachedEnd()) {
        RowData next = inputFormat.nextRecord(row);
        assertEquals(TEST_DATA[recordCount], next);
        recordCount++;
    }
    inputFormat.close();
    inputFormat.closeInputFormat();
    Assert.assertEquals(TEST_DATA.length, recordCount);
}
Also used : GenericRowData(org.apache.flink.table.data.GenericRowData) RowData(org.apache.flink.table.data.RowData) GenericRowData(org.apache.flink.table.data.GenericRowData) Test(org.junit.Test)

Example 20 with GenericRowData

use of org.apache.flink.table.data.GenericRowData in project flink by apache.

the class JdbcRowDataInputFormatTest method verifySplit.

private void verifySplit(InputSplit split, int expectedIDSum) throws IOException {
    int sum = 0;
    RowData row = new GenericRowData(5);
    inputFormat.open(split);
    RowData.FieldGetter idFieldGetter = RowData.createFieldGetter(new IntType(), 0);
    while (!inputFormat.reachedEnd()) {
        row = inputFormat.nextRecord(row);
        int id = (int) idFieldGetter.getFieldOrNull(row);
        int testDataIndex = id - 1001;
        assertEquals(TEST_DATA[testDataIndex], row);
        sum += id;
    }
    Assert.assertEquals(expectedIDSum, sum);
}
Also used : GenericRowData(org.apache.flink.table.data.GenericRowData) RowData(org.apache.flink.table.data.RowData) GenericRowData(org.apache.flink.table.data.GenericRowData) IntType(org.apache.flink.table.types.logical.IntType)

Aggregations

GenericRowData (org.apache.flink.table.data.GenericRowData)94 RowData (org.apache.flink.table.data.RowData)32 JoinedRowData (org.apache.flink.table.data.utils.JoinedRowData)16 Test (org.junit.Test)14 BinaryRowData (org.apache.flink.table.data.binary.BinaryRowData)13 RowType (org.apache.flink.table.types.logical.RowType)13 IOException (java.io.IOException)11 ArrayList (java.util.ArrayList)11 IntType (org.apache.flink.table.types.logical.IntType)11 List (java.util.List)9 LogicalType (org.apache.flink.table.types.logical.LogicalType)9 GenericArrayData (org.apache.flink.table.data.GenericArrayData)6 StringData (org.apache.flink.table.data.StringData)6 Arrays (java.util.Arrays)5 HashMap (java.util.HashMap)5 OutputStream (java.io.OutputStream)4 PrintStream (java.io.PrintStream)4 Collections (java.util.Collections)4 Random (java.util.Random)4 Consumer (java.util.function.Consumer)4