Search in sources :

Example 1 with GenericRowData

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

the class RowDataFieldsKinesisPartitionKeyGeneratorTest method createElement.

private RowData createElement(LocalDateTime time, String ip, String route) {
    GenericRowData element = new GenericRowData(ROW_TYPE.getFieldCount());
    element.setField(0, TimestampData.fromLocalDateTime(time));
    element.setField(1, StringData.fromString(ip));
    element.setField(2, StringData.fromString(route));
    element.setField(3, StringData.fromString(String.valueOf(days(time))));
    element.setField(4, StringData.fromString(String.valueOf(year(time))));
    element.setField(5, StringData.fromString(String.valueOf(monthOfYear(time))));
    element.setField(6, StringData.fromString(String.valueOf(dayOfMonth(time))));
    return element;
}
Also used : GenericRowData(org.apache.flink.table.data.GenericRowData)

Example 2 with GenericRowData

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

the class FileSystemLookupFunction method checkCacheReload.

private void checkCacheReload() {
    if (nextLoadTime > System.currentTimeMillis()) {
        return;
    }
    if (nextLoadTime > 0) {
        LOG.info("Lookup join cache has expired after {} minute(s), reloading", reloadInterval.toMinutes());
    } else {
        LOG.info("Populating lookup join cache");
    }
    int numRetry = 0;
    while (true) {
        cache.clear();
        try {
            long count = 0;
            GenericRowData reuse = new GenericRowData(rowType.getFieldCount());
            partitionReader.open(partitionFetcher.fetch(fetcherContext));
            RowData row;
            while ((row = partitionReader.read(reuse)) != null) {
                count++;
                RowData rowData = serializer.copy(row);
                RowData key = extractLookupKey(rowData);
                List<RowData> rows = cache.computeIfAbsent(key, k -> new ArrayList<>());
                rows.add(rowData);
            }
            partitionReader.close();
            nextLoadTime = System.currentTimeMillis() + reloadInterval.toMillis();
            LOG.info("Loaded {} row(s) into lookup join cache", count);
            return;
        } catch (Exception e) {
            if (numRetry >= MAX_RETRIES) {
                throw new FlinkRuntimeException(String.format("Failed to load table into cache after %d retries", numRetry), e);
            }
            numRetry++;
            long toSleep = numRetry * RETRY_INTERVAL.toMillis();
            LOG.warn(String.format("Failed to load table into cache, will retry in %d seconds", toSleep / 1000), e);
            try {
                Thread.sleep(toSleep);
            } catch (InterruptedException ex) {
                LOG.warn("Interrupted while waiting to retry failed cache load, aborting");
                throw new FlinkRuntimeException(ex);
            }
        }
    }
}
Also used : RowData(org.apache.flink.table.data.RowData) GenericRowData(org.apache.flink.table.data.GenericRowData) FlinkRuntimeException(org.apache.flink.util.FlinkRuntimeException) GenericRowData(org.apache.flink.table.data.GenericRowData) FlinkRuntimeException(org.apache.flink.util.FlinkRuntimeException)

Example 3 with GenericRowData

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

the class HBaseSerde method convertToNewRow.

/**
 * Converts HBase {@link Result} into a new {@link RowData} instance.
 *
 * <p>Note: this method is thread-safe.
 */
public RowData convertToNewRow(Result result) {
    // The output rows needs to be initialized each time
    // to prevent the possibility of putting the output object into the cache.
    GenericRowData resultRow = new GenericRowData(fieldLength);
    GenericRowData[] familyRows = new GenericRowData[families.length];
    for (int f = 0; f < families.length; f++) {
        familyRows[f] = new GenericRowData(qualifiers[f].length);
    }
    return convertToRow(result, resultRow, familyRows);
}
Also used : GenericRowData(org.apache.flink.table.data.GenericRowData)

Example 4 with GenericRowData

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

the class DebeziumAvroSerDeSchemaTest method debeziumRow2RowData.

private static RowData debeziumRow2RowData() {
    GenericRowData rowData = new GenericRowData(4);
    rowData.setField(0, 107L);
    rowData.setField(1, StringData.fromString("rocks"));
    rowData.setField(2, StringData.fromString("box of assorted rocks"));
    rowData.setField(3, 5.3D);
    return rowData;
}
Also used : GenericRowData(org.apache.flink.table.data.GenericRowData)

Example 5 with GenericRowData

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

the class AvroRowDataDeSerializationSchemaTest method testSerializationWithTypesMismatch.

@Test
public void testSerializationWithTypesMismatch() throws Exception {
    AvroRowDataSerializationSchema serializationSchema = createSerializationSchema(ROW(FIELD("f0", INT()), FIELD("f1", STRING())).notNull());
    GenericRowData rowData = new GenericRowData(2);
    rowData.setField(0, 1);
    rowData.setField(0, 2);
    String errorMessage = "Fail to serialize at field: f1.";
    try {
        serializationSchema.serialize(rowData);
        fail("expecting exception message: " + errorMessage);
    } catch (Throwable t) {
        assertThat(t, FlinkMatchers.containsMessage(errorMessage));
    }
}
Also used : GenericRowData(org.apache.flink.table.data.GenericRowData) Test(org.junit.Test)

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