use of org.apache.flink.table.data.writer.BinaryRowWriter in project flink by apache.
the class RowDataTest method before.
@Before
public void before() {
str = StringData.fromString("haha");
generic = RawValueData.fromObject("haha");
genericSerializer = new RawValueDataSerializer<>(StringSerializer.INSTANCE);
decimal1 = DecimalData.fromUnscaledLong(10, 5, 0);
decimal2 = DecimalData.fromBigDecimal(new BigDecimal(11), 20, 0);
array = new BinaryArrayData();
{
BinaryArrayWriter arrayWriter = new BinaryArrayWriter(array, 2, 4);
arrayWriter.writeInt(0, 15);
arrayWriter.writeInt(1, 16);
arrayWriter.complete();
}
map = BinaryMapData.valueOf(array, array);
underRow = new BinaryRowData(2);
{
BinaryRowWriter writer = new BinaryRowWriter(underRow);
writer.writeInt(0, 15);
writer.writeInt(1, 16);
writer.complete();
}
bytes = new byte[] { 1, 5, 6 };
timestamp1 = TimestampData.fromEpochMillis(123L);
timestamp2 = TimestampData.fromLocalDateTime(LocalDateTime.of(1969, 1, 1, 0, 0, 0, 123456789));
}
use of org.apache.flink.table.data.writer.BinaryRowWriter in project flink by apache.
the class BinaryHashTableTest method testRepeatBuildJoinWithSpill.
@Test
public void testRepeatBuildJoinWithSpill() throws Exception {
final int numKeys = 30000;
final int numRows = 300000;
final int probeValsPerKey = 1;
MutableObjectIterator<BinaryRowData> buildInput = new MutableObjectIterator<BinaryRowData>() {
int cnt = 0;
@Override
public BinaryRowData next(BinaryRowData reuse) throws IOException {
return next();
}
@Override
public BinaryRowData next() throws IOException {
cnt++;
if (cnt > numRows) {
return null;
}
int value = cnt % numKeys;
BinaryRowData row = new BinaryRowData(2);
BinaryRowWriter writer = new BinaryRowWriter(row);
writer.writeInt(0, value);
writer.writeInt(1, value);
writer.complete();
return row;
}
};
MemoryManager memManager = MemoryManagerBuilder.newBuilder().setMemorySize(35 * PAGE_SIZE).build();
MutableObjectIterator<BinaryRowData> probeInput = new UniformBinaryRowGenerator(numKeys, probeValsPerKey, true);
final BinaryHashTable table = new BinaryHashTable(conf, new Object(), buildSideSerializer, probeSideSerializer, new MyProjection(), new MyProjection(), memManager, 35 * PAGE_SIZE, ioManager, 24, 200000, true, HashJoinType.INNER, null, false, new boolean[] { true }, true);
int numRecordsInJoinResult = join(table, buildInput, probeInput, true);
Assert.assertTrue("Wrong number of records in join result.", numRecordsInJoinResult < numRows);
table.close();
table.free();
}
use of org.apache.flink.table.data.writer.BinaryRowWriter in project flink by apache.
the class BinaryRowDataTest method testHashAndCopy.
@Test
public void testHashAndCopy() throws IOException {
MemorySegment[] segments = new MemorySegment[3];
for (int i = 0; i < 3; i++) {
segments[i] = MemorySegmentFactory.wrap(new byte[64]);
}
RandomAccessOutputView out = new RandomAccessOutputView(segments, 64);
BinaryRowDataSerializer serializer = new BinaryRowDataSerializer(2);
BinaryRowData row = new BinaryRowData(2);
BinaryRowWriter writer = new BinaryRowWriter(row);
writer.writeString(0, fromString("hahahahahahahahahahahahahahahahahahahhahahahahahahahahah"));
writer.writeString(1, fromString("hahahahahahahahahahahahahahahahahahahhahahahahahahahahaa"));
writer.complete();
serializer.serializeToPages(row, out);
ArrayList<MemorySegment> segmentList = new ArrayList<>(Arrays.asList(segments));
RandomAccessInputView input = new RandomAccessInputView(segmentList, 64, 64);
BinaryRowData mapRow = serializer.createInstance();
mapRow = serializer.mapFromPages(mapRow, input);
assertEquals(row, mapRow);
assertEquals(row.getString(0), mapRow.getString(0));
assertEquals(row.getString(1), mapRow.getString(1));
assertNotEquals(row.getString(0), mapRow.getString(1));
// test if the hash code before and after serialization are the same
assertEquals(row.hashCode(), mapRow.hashCode());
assertEquals(row.getString(0).hashCode(), mapRow.getString(0).hashCode());
assertEquals(row.getString(1).hashCode(), mapRow.getString(1).hashCode());
// test if the copy method produce a row with the same contents
assertEquals(row.copy(), mapRow.copy());
assertEquals(((BinaryStringData) row.getString(0)).copy(), ((BinaryStringData) mapRow.getString(0)).copy());
assertEquals(((BinaryStringData) row.getString(1)).copy(), ((BinaryStringData) mapRow.getString(1)).copy());
}
use of org.apache.flink.table.data.writer.BinaryRowWriter in project flink by apache.
the class BinaryRowDataTest method testReuseWriter.
@Test
public void testReuseWriter() {
BinaryRowData row = new BinaryRowData(2);
BinaryRowWriter writer = new BinaryRowWriter(row);
writer.writeString(0, fromString("01234567"));
writer.writeString(1, fromString("012345678"));
writer.complete();
assertEquals("01234567", row.getString(0).toString());
assertEquals("012345678", row.getString(1).toString());
writer.reset();
writer.writeString(0, fromString("1"));
writer.writeString(1, fromString("0123456789"));
writer.complete();
assertEquals("1", row.getString(0).toString());
assertEquals("0123456789", row.getString(1).toString());
}
use of org.apache.flink.table.data.writer.BinaryRowWriter in project flink by apache.
the class BinaryRowDataTest method testNested.
@Test
public void testNested() {
BinaryRowData row = new BinaryRowData(2);
BinaryRowWriter writer = new BinaryRowWriter(row);
writer.writeRow(0, GenericRowData.of(fromString("1"), 1), new RowDataSerializer(RowType.of(VarCharType.STRING_TYPE, new IntType())));
writer.setNullAt(1);
writer.complete();
RowData nestedRow = row.getRow(0, 2);
assertEquals("1", nestedRow.getString(0).toString());
assertEquals(1, nestedRow.getInt(1));
assertTrue(row.isNullAt(1));
}
Aggregations