Search in sources :

Example 31 with GenericRowData

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

the class ReplicateRowsFunction method eval.

public void eval(Object... inputs) {
    final long replication = (long) inputs[0];
    final int rowLength = inputs.length - 1;
    final GenericRowData row = new GenericRowData(rowLength);
    for (int i = 0; i < rowLength; i++) {
        row.setField(i, inputs[i + 1]);
    }
    for (int i = 0; i < replication; i++) {
        collect(row);
    }
}
Also used : GenericRowData(org.apache.flink.table.data.GenericRowData)

Example 32 with GenericRowData

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

the class RowDataSerializerTest method testRowDataSerializerWithKryo.

private static Object[] testRowDataSerializerWithKryo() {
    RawValueDataSerializer<WrappedString> rawValueSerializer = new RawValueDataSerializer<>(new KryoSerializer<>(WrappedString.class, new ExecutionConfig()));
    RowDataSerializer serializer = new RowDataSerializer(new LogicalType[] { new RawType(RawValueData.class, rawValueSerializer) }, new TypeSerializer[] { rawValueSerializer });
    GenericRowData row = new GenericRowData(1);
    row.setField(0, RawValueData.fromObject(new WrappedString("a")));
    return new Object[] { serializer, new GenericRowData[] { row } };
}
Also used : GenericRowData(org.apache.flink.table.data.GenericRowData) RawValueData(org.apache.flink.table.data.RawValueData) ExecutionConfig(org.apache.flink.api.common.ExecutionConfig) RawType(org.apache.flink.table.types.logical.RawType)

Example 33 with GenericRowData

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

the class RowDataSerializerTest method testRowDataSerializer.

private static Object[] testRowDataSerializer() {
    InternalTypeInfo<RowData> typeInfo = InternalTypeInfo.ofFields(new IntType(), VarCharType.STRING_TYPE);
    GenericRowData row1 = new GenericRowData(2);
    row1.setField(0, 1);
    row1.setField(1, fromString("a"));
    GenericRowData row2 = new GenericRowData(2);
    row2.setField(0, 2);
    row2.setField(1, null);
    RowDataSerializer serializer = typeInfo.toRowSerializer();
    return new Object[] { serializer, new RowData[] { row1, row2 } };
}
Also used : GenericRowData(org.apache.flink.table.data.GenericRowData) RowData(org.apache.flink.table.data.RowData) BinaryRowData(org.apache.flink.table.data.binary.BinaryRowData) GenericRowData(org.apache.flink.table.data.GenericRowData) IntType(org.apache.flink.table.types.logical.IntType)

Example 34 with GenericRowData

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

the class RowDataHarnessAssertor method assertOutputEquals.

private void assertOutputEquals(String message, Collection<Object> expected, Collection<Object> actual, boolean needSort) {
    if (needSort) {
        Preconditions.checkArgument(comparator != null, "Comparator should not be null!");
    }
    assertEquals(expected.size(), actual.size());
    // first, compare only watermarks, their position should be deterministic
    Iterator<Object> exIt = expected.iterator();
    Iterator<Object> actIt = actual.iterator();
    while (exIt.hasNext()) {
        Object nextEx = exIt.next();
        Object nextAct = actIt.next();
        if (nextEx instanceof Watermark) {
            assertEquals(nextEx, nextAct);
        }
    }
    List<GenericRowData> expectedRecords = new ArrayList<>();
    List<GenericRowData> actualRecords = new ArrayList<>();
    for (Object ex : expected) {
        if (ex instanceof StreamRecord) {
            RowData row = (RowData) ((StreamRecord) ex).getValue();
            if (row instanceof GenericRowData) {
                expectedRecords.add((GenericRowData) row);
            } else {
                GenericRowData genericRow = RowDataTestUtil.toGenericRowDeeply(row, types);
                expectedRecords.add(genericRow);
            }
        }
    }
    for (Object act : actual) {
        if (act instanceof StreamRecord) {
            RowData actualOutput = (RowData) ((StreamRecord) act).getValue();
            // joined row can't equals to generic row, so cast joined row to generic row first
            GenericRowData actualRow = RowDataTestUtil.toGenericRowDeeply(actualOutput, types);
            actualRecords.add(actualRow);
        }
    }
    GenericRowData[] sortedExpected = expectedRecords.toArray(new GenericRowData[expectedRecords.size()]);
    GenericRowData[] sortedActual = actualRecords.toArray(new GenericRowData[actualRecords.size()]);
    if (needSort) {
        Arrays.sort(sortedExpected, comparator);
        Arrays.sort(sortedActual, comparator);
    }
    Assert.assertArrayEquals(message, sortedExpected, sortedActual);
}
Also used : RowData(org.apache.flink.table.data.RowData) GenericRowData(org.apache.flink.table.data.GenericRowData) StreamRecord(org.apache.flink.streaming.runtime.streamrecord.StreamRecord) ArrayList(java.util.ArrayList) GenericRowData(org.apache.flink.table.data.GenericRowData) Watermark(org.apache.flink.streaming.api.watermark.Watermark)

Example 35 with GenericRowData

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

the class RowDataSerializerTest method testWrongCopy.

@Test
public void testWrongCopy() {
    thrown.expect(IllegalArgumentException.class);
    serializer.copy(new GenericRowData(serializer.getArity() + 1));
}
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