use of org.apache.flink.table.data.binary.BinaryRowData in project flink by apache.
the class BytesMapTestBase method createRow.
protected BinaryRowData createRow(Integer f0, String f1, Double f2, Long f3, Boolean f4, Float f5, Short f6) {
BinaryRowData row = new BinaryRowData(7);
BinaryRowWriter writer = new BinaryRowWriter(row);
// int, string, double, long, boolean
if (f0 == null) {
writer.setNullAt(0);
} else {
writer.writeInt(0, f0);
}
if (f1 == null) {
writer.setNullAt(1);
} else {
writer.writeString(1, StringData.fromString(f1));
}
if (f2 == null) {
writer.setNullAt(2);
} else {
writer.writeDouble(2, f2);
}
if (f3 == null) {
writer.setNullAt(3);
} else {
writer.writeLong(3, f3);
}
if (f4 == null) {
writer.setNullAt(4);
} else {
writer.writeBoolean(4, f4);
}
if (f5 == null) {
writer.setNullAt(5);
} else {
writer.writeFloat(5, f5);
}
if (f6 == null) {
writer.setNullAt(6);
} else {
writer.writeShort(6, f6);
}
writer.complete();
return row;
}
use of org.apache.flink.table.data.binary.BinaryRowData in project flink by apache.
the class BytesMultiMapTestBase method testBuildAndRetrieve.
// ------------------------------------------------------------------------------------------
// Tests
// ------------------------------------------------------------------------------------------
@Test
public void testBuildAndRetrieve() throws Exception {
final int numMemSegments = needNumMemSegments(NUM_ENTRIES, rowLength(RowType.of(VALUE_TYPES)), rowLength(RowType.of(KEY_TYPES)), PAGE_SIZE);
int memorySize = numMemSegments * PAGE_SIZE;
MemoryManager memoryManager = MemoryManagerBuilder.newBuilder().setMemorySize(numMemSegments * PAGE_SIZE).build();
AbstractBytesMultiMap<K> table = createBytesMultiMap(memoryManager, memorySize, KEY_TYPES, VALUE_TYPES);
K[] keys = generateRandomKeys(NUM_ENTRIES / 10);
BinaryRowData[] values = genValues(NUM_VALUE_PER_KEY);
for (K key : keys) {
BytesMap.LookupInfo<K, Iterator<RowData>> lookupInfo;
for (BinaryRowData value : values) {
lookupInfo = table.lookup(key);
table.append(lookupInfo, value);
}
}
KeyValueIterator<K, Iterator<RowData>> iter = table.getEntryIterator(false);
while (iter.advanceNext()) {
int i = 0;
Iterator<RowData> valueIter = iter.getValue();
while (valueIter.hasNext()) {
Assert.assertEquals(valueIter.next(), values[i++]);
}
}
}
use of org.apache.flink.table.data.binary.BinaryRowData in project flink by apache.
the class WindowBytesMultiMapTest method generateRandomKeys.
@Override
public WindowKey[] generateRandomKeys(int num) {
final Random rnd = new Random(RANDOM_SEED);
BinaryRowData[] keys = getRandomizedInputs(num, rnd, true);
WindowKey[] windowKeys = new WindowKey[num];
for (int i = 0; i < num; i++) {
windowKeys[i] = new WindowKey(rnd.nextLong(), keys[i]);
}
return windowKeys;
}
use of org.apache.flink.table.data.binary.BinaryRowData in project flink by apache.
the class WindowKeySerializerTest method createRow.
private static BinaryRowData createRow(String f0, int f1) {
BinaryRowData row = new BinaryRowData(2);
BinaryRowWriter writer = new BinaryRowWriter(row);
writer.writeString(0, StringData.fromString(f0));
writer.writeInt(1, f1);
writer.complete();
return row;
}
use of org.apache.flink.table.data.binary.BinaryRowData in project flink by apache.
the class ResettableExternalBufferTest method testUpdateIteratorSpill.
private <T extends RowData> void testUpdateIteratorSpill(BinaryRowDataSerializer serializer, Class<T> clazz, boolean isRowAllInFixedPart) throws Exception {
ResettableExternalBuffer buffer = newBuffer(DEFAULT_PAGE_SIZE * 2, serializer, isRowAllInFixedPart);
int number = 100;
int step = 20;
int iters = 3;
List<RowData> expected = new ArrayList<>();
List<RowData> smallExpected = new ArrayList<>();
List<ResettableExternalBuffer.BufferIterator> iterators = new ArrayList<>();
for (int i = 0; i < iters; i++) {
iterators.add(buffer.newIterator());
}
for (int i = 0; i < number; i++) {
smallExpected.clear();
for (int j = 0; j < step; j++) {
RowData data = clazz.newInstance();
data.insertIntoBuffer(buffer);
expected.add(data);
smallExpected.add(data);
}
for (int j = 0; j < step; j++) {
for (ResettableExternalBuffer.BufferIterator iterator : iterators) {
assertTrue(iterator.advanceNext());
BinaryRowData row = iterator.getRow();
smallExpected.get(j).checkSame(row);
}
}
for (ResettableExternalBuffer.BufferIterator iterator : iterators) {
assertFalse(iterator.advanceNext());
}
}
for (ResettableExternalBuffer.BufferIterator iterator : iterators) {
iterator.reset();
}
for (int i = 0; i < number * step; i++) {
for (ResettableExternalBuffer.BufferIterator iterator : iterators) {
assertTrue(iterator.advanceNext());
BinaryRowData row = iterator.getRow();
expected.get(i).checkSame(row);
}
}
for (ResettableExternalBuffer.BufferIterator iterator : iterators) {
iterator.close();
}
assertMultiColumnRandomAccess(expected, buffer);
buffer.close();
}
Aggregations