use of org.apache.flink.table.data.writer.BinaryRowWriter in project flink by apache.
the class BinaryRowDataTest method testRawValueData.
@Test
public void testRawValueData() {
BinaryRowData row = new BinaryRowData(3);
BinaryRowWriter writer = new BinaryRowWriter(row);
RawValueDataSerializer<String> binarySerializer = new RawValueDataSerializer<>(StringSerializer.INSTANCE);
RawValueData<String> hahah = RawValueData.fromObject("hahah");
writer.writeRawValue(0, hahah, binarySerializer);
writer.setNullAt(1);
writer.writeRawValue(2, hahah, binarySerializer);
writer.complete();
RawValueData<String> generic0 = row.getRawValue(0);
assertThat(generic0, equivalent(hahah, binarySerializer));
assertTrue(row.isNullAt(1));
RawValueData<String> generic2 = row.getRawValue(2);
assertThat(generic2, equivalent(hahah, binarySerializer));
}
use of org.apache.flink.table.data.writer.BinaryRowWriter in project flink by apache.
the class NestedRowDataTest method getBinaryRowData.
private BinaryRowData getBinaryRowData() {
BinaryRowData row = new BinaryRowData(1);
BinaryRowWriter writer = new BinaryRowWriter(row);
GenericTypeInfo<MyObj> info = new GenericTypeInfo<>(MyObj.class);
TypeSerializer<MyObj> genericSerializer = info.createSerializer(new ExecutionConfig());
GenericRowData gRow = new GenericRowData(5);
gRow.setField(0, 1);
gRow.setField(1, 5L);
gRow.setField(2, StringData.fromString("12345678"));
gRow.setField(3, null);
gRow.setField(4, RawValueData.fromObject(new MyObj(15, 5)));
RowDataSerializer serializer = new RowDataSerializer(new LogicalType[] { DataTypes.INT().getLogicalType(), DataTypes.BIGINT().getLogicalType(), DataTypes.STRING().getLogicalType(), DataTypes.STRING().getLogicalType(), DataTypes.RAW(info.getTypeClass(), info.createSerializer(new ExecutionConfig())).getLogicalType() }, new TypeSerializer[] { IntSerializer.INSTANCE, LongSerializer.INSTANCE, StringDataSerializer.INSTANCE, StringDataSerializer.INSTANCE, new RawValueDataSerializer<>(genericSerializer) });
writer.writeRow(0, gRow, serializer);
writer.complete();
return row;
}
use of org.apache.flink.table.data.writer.BinaryRowWriter in project flink by apache.
the class NestedRowDataTest method testNestInNestedRowData.
@Test
public void testNestInNestedRowData() {
// layer1
GenericRowData gRow = new GenericRowData(4);
gRow.setField(0, 1);
gRow.setField(1, 5L);
gRow.setField(2, StringData.fromString("12345678"));
gRow.setField(3, null);
// layer2
RowDataSerializer serializer = new RowDataSerializer(new LogicalType[] { DataTypes.INT().getLogicalType(), DataTypes.BIGINT().getLogicalType(), DataTypes.STRING().getLogicalType(), DataTypes.STRING().getLogicalType() }, new TypeSerializer[] { IntSerializer.INSTANCE, LongSerializer.INSTANCE, StringSerializer.INSTANCE, StringSerializer.INSTANCE });
BinaryRowData row = new BinaryRowData(2);
BinaryRowWriter writer = new BinaryRowWriter(row);
writer.writeString(0, StringData.fromString("hahahahafff"));
writer.writeRow(1, gRow, serializer);
writer.complete();
// layer3
BinaryRowData row2 = new BinaryRowData(1);
BinaryRowWriter writer2 = new BinaryRowWriter(row2);
writer2.writeRow(0, row, null);
writer2.complete();
// verify
{
NestedRowData nestedRow = (NestedRowData) row2.getRow(0, 2);
BinaryRowData binaryRow = new BinaryRowData(2);
binaryRow.pointTo(nestedRow.getSegments(), nestedRow.getOffset(), nestedRow.getSizeInBytes());
assertEquals(binaryRow, row);
}
assertEquals(row2.getRow(0, 2).getString(0), StringData.fromString("hahahahafff"));
RowData nestedRow = row2.getRow(0, 2).getRow(1, 4);
assertEquals(nestedRow.getInt(0), 1);
assertEquals(nestedRow.getLong(1), 5L);
assertEquals(nestedRow.getString(2), StringData.fromString("12345678"));
assertTrue(nestedRow.isNullAt(3));
}
use of org.apache.flink.table.data.writer.BinaryRowWriter in project flink by apache.
the class DataFormatTestUtil method get160BytesBinaryRow.
/**
* Get a binary row of 160 bytes long.
*/
public static BinaryRowData get160BytesBinaryRow() {
// header (8 bytes) +
// 72 byte length string (8 bytes in fixed-length, 72 bytes in variable-length) +
// 64 byte length string (8 bytes in fixed-length, 64 bytes in variable-length)
BinaryRowData row = new BinaryRowData(2);
BinaryRowWriter writer = new BinaryRowWriter(row);
writer.writeString(0, StringData.fromString(RandomStringUtils.randomNumeric(72)));
writer.writeString(1, StringData.fromString(RandomStringUtils.randomNumeric(64)));
writer.complete();
return row;
}
use of org.apache.flink.table.data.writer.BinaryRowWriter in project flink by apache.
the class UniformBinaryRowGenerator method next.
@Override
public BinaryRowData next(BinaryRowData reuse) {
if (!repeatKey) {
if (valCnt >= numVals + startVal) {
return null;
}
key.setValue(keyCnt++);
value.setValue(valCnt);
if (keyCnt == numKeys + startKey) {
keyCnt = startKey;
valCnt++;
}
} else {
if (keyCnt >= numKeys + startKey) {
return null;
}
key.setValue(keyCnt);
value.setValue(valCnt++);
if (valCnt == numVals + startVal) {
valCnt = startVal;
keyCnt++;
}
}
BinaryRowWriter writer = new BinaryRowWriter(reuse);
writer.writeInt(0, this.key.getValue());
writer.writeInt(1, this.value.getValue());
writer.complete();
return reuse;
}
Aggregations