use of io.mycat.memory.unsafe.row.UnsafeRow in project Mycat-Server by MyCATApache.
the class UnsafeRowGrouper method addRow.
public void addRow(UnsafeRow rowDataPkg) throws UnsupportedEncodingException {
UnsafeRow key = getGroupKey(rowDataPkg);
UnsafeRow value = getValue(rowDataPkg);
if (aggregationMap.find(key)) {
UnsafeRow rs = aggregationMap.getAggregationBuffer(key);
aggregateRow(rs, value);
} else {
aggregationMap.put(key, value);
}
return;
}
use of io.mycat.memory.unsafe.row.UnsafeRow in project Mycat-Server by MyCATApache.
the class UnsafeFixedWidthAggregationMapSuite method testWithMemoryLeakDetection.
@Test
public void testWithMemoryLeakDetection() throws IOException, NoSuchFieldException, IllegalAccessException {
MyCatMemory myCatMemory = new MyCatMemory();
MemoryManager memoryManager = myCatMemory.getResultMergeMemoryManager();
DataNodeMemoryManager dataNodeMemoryManager = new DataNodeMemoryManager(memoryManager, Thread.currentThread().getId());
int fieldCount = 3;
ColMeta colMeta = null;
Map<String, ColMeta> colMetaMap = new HashMap<String, ColMeta>(fieldCount);
colMeta = new ColMeta(0, ColMeta.COL_TYPE_STRING);
colMetaMap.put("id", colMeta);
colMeta = new ColMeta(1, ColMeta.COL_TYPE_STRING);
colMetaMap.put("name", colMeta);
colMeta = new ColMeta(2, ColMeta.COL_TYPE_STRING);
colMetaMap.put("age", colMeta);
OrderCol[] orderCols = new OrderCol[1];
OrderCol orderCol = new OrderCol(colMetaMap.get("id"), OrderCol.COL_ORDER_TYPE_DESC);
orderCols[0] = orderCol;
groupKeySchema = new StructType(colMetaMap, fieldCount);
groupKeySchema.setOrderCols(orderCols);
fieldCount = 3;
colMeta = null;
colMetaMap = new HashMap<String, ColMeta>(fieldCount);
colMeta = new ColMeta(0, ColMeta.COL_TYPE_LONGLONG);
colMetaMap.put("age", colMeta);
colMeta = new ColMeta(1, ColMeta.COL_TYPE_LONGLONG);
colMetaMap.put("age1", colMeta);
colMeta = new ColMeta(2, ColMeta.COL_TYPE_STRING);
colMetaMap.put("name", colMeta);
orderCols = new OrderCol[1];
orderCol = new OrderCol(colMetaMap.get("id"), OrderCol.COL_ORDER_TYPE_DESC);
orderCols[0] = orderCol;
aggBufferSchema = new StructType(colMetaMap, fieldCount);
aggBufferSchema.setOrderCols(orderCols);
/**
* value
*/
BufferHolder bufferHolder;
emptyAggregationBuffer = new UnsafeRow(3);
bufferHolder = new BufferHolder(emptyAggregationBuffer, 0);
UnsafeRowWriter unsafeRowWriter = new UnsafeRowWriter(bufferHolder, 3);
bufferHolder.reset();
String value = "ok,hello";
emptyAggregationBuffer.setLong(0, 0);
emptyAggregationBuffer.setLong(1, 0);
unsafeRowWriter.write(2, value.getBytes());
emptyAggregationBuffer.setTotalSize(bufferHolder.totalSize());
UnsafeFixedWidthAggregationMap map = new UnsafeFixedWidthAggregationMap(emptyAggregationBuffer, aggBufferSchema, groupKeySchema, dataNodeMemoryManager, 2 * 1024, PAGE_SIZE_BYTES, false);
int i;
List<UnsafeRow> rows = new ArrayList<UnsafeRow>();
for (i = 0; i < 1000; i++) {
String line = "testUnsafeRow" + i;
/**
* key
*/
UnsafeRow groupKey = new UnsafeRow(3);
bufferHolder = new BufferHolder(groupKey, 0);
unsafeRowWriter = new UnsafeRowWriter(bufferHolder, 3);
bufferHolder.reset();
final byte[] key = getRandomByteArray(rand.nextInt(8));
String age = "5" + i;
unsafeRowWriter.write(0, key);
unsafeRowWriter.write(1, line.getBytes());
unsafeRowWriter.write(2, age.getBytes());
groupKey.setTotalSize(bufferHolder.totalSize());
map.getAggregationBuffer(groupKey);
rows.add(groupKey);
}
Assert.assertEquals(i, rows.size());
UnsafeRow row = rows.get(12);
UnsafeRow rs = map.getAggregationBuffer(row);
rs.setLong(0, 12);
rs = map.getAggregationBuffer(row);
Assert.assertEquals(12, rs.getLong(0));
map.free();
}
Aggregations