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);
}
}
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 } };
}
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 } };
}
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);
}
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));
}
Aggregations