use of com.tencent.angel.psagent.matrix.transport.router.ValuePart in project angel by Tencent.
the class ServerRowUtils method getByKeys.
public static ValuePart getByKeys(ServerRow row, KeyPart keyPart) {
ValuePart result;
if (keyPart instanceof IIntKeyPartOp) {
// Index is int
IIntKeyPartOp intKeyPart = (IIntKeyPartOp) keyPart;
if (row instanceof ServerIntFloatRow) {
float[] values = ((ServerIntFloatRow) row).get(intKeyPart.getKeys());
result = new FloatValuesPart(values);
} else if (row instanceof ServerIntDoubleRow) {
double[] values = ((ServerIntDoubleRow) row).get(intKeyPart.getKeys());
result = new DoubleValuesPart(values);
} else if (row instanceof ServerIntIntRow) {
int[] values = ((ServerIntIntRow) row).get(intKeyPart.getKeys());
result = new IntValuesPart(values);
} else if (row instanceof ServerIntLongRow) {
long[] values = ((ServerIntLongRow) row).get(intKeyPart.getKeys());
result = new LongValuesPart(values);
} else {
throw new UnsupportedOperationException("Unsupport row type " + row.getClass().getName());
}
} else if (keyPart instanceof ILongKeyPartOp) {
// Index is long
ILongKeyPartOp longKeyPart = (ILongKeyPartOp) keyPart;
if (row instanceof ServerLongFloatRow) {
float[] values = ((ServerLongFloatRow) row).get(longKeyPart.getKeys());
result = new FloatValuesPart(values);
} else if (row instanceof ServerLongDoubleRow) {
double[] values = ((ServerLongDoubleRow) row).get(longKeyPart.getKeys());
result = new DoubleValuesPart(values);
} else if (row instanceof ServerLongIntRow) {
int[] values = ((ServerLongIntRow) row).get(longKeyPart.getKeys());
result = new IntValuesPart(values);
} else if (row instanceof ServerLongLongRow) {
long[] values = ((ServerLongLongRow) row).get(longKeyPart.getKeys());
result = new LongValuesPart(values);
} else {
throw new UnsupportedOperationException("Unsupport row type " + row.getClass().getName());
}
} else {
throw new UnsupportedOperationException("Unsupport index type " + keyPart.getClass().getName());
}
return result;
}
use of com.tencent.angel.psagent.matrix.transport.router.ValuePart in project angel by Tencent.
the class ByteBufSerdeUtils method deserializeValuePart.
public static ValuePart deserializeValuePart(ByteBuf in) {
int typeCode = deserializeInt(in);
ValueType valueType = ValueType.valueOf(typeCode);
ValuePart valuePart = DataPartFactory.createValuePart(valueType);
valuePart.deserialize(in);
return valuePart;
}
use of com.tencent.angel.psagent.matrix.transport.router.ValuePart in project angel by Tencent.
the class IndexGetRowHandler method handle.
@Override
public ResponseData handle(RequestHeader header, RequestData data) throws Exception {
IndexPartGetRowRequest request = (IndexPartGetRowRequest) data;
KeyPart keyPart = request.getKeyPart();
ServerRow row = MatrixUtils.getRow(context.getMatrixStorageManager(), header.matrixId, header.partId, request.getRowId());
ValuePart result;
StreamIndexPartGetRowResponse response;
row.startRead();
try {
result = ServerRowUtils.getByKeys(row, keyPart);
response = new StreamIndexPartGetRowResponse(result);
return response;
} finally {
row.endRead();
}
}
use of com.tencent.angel.psagent.matrix.transport.router.ValuePart in project angel by Tencent.
the class IndexGetRowsHandler method handle.
@Override
public ResponseData handle(RequestHeader header, RequestData data) throws Exception {
IndexPartGetRowsRequest request = (IndexPartGetRowsRequest) data;
int[] rowIds = request.getRowIds();
KeyPart keyPart = request.getKeyPart();
ServerRow[] rows = new ServerRow[rowIds.length];
ValuePart[] results = new ValuePart[rowIds.length];
for (int i = 0; i < rowIds.length; i++) {
rows[i] = context.getMatrixStorageManager().getRow(header.matrixId, rowIds[i], header.partId);
rows[i].startRead();
try {
results[i] = ServerRowUtils.getByKeys(rows[i], keyPart);
} finally {
rows[i].endRead();
}
}
IndexPartGetRowsResponse response = new IndexPartGetRowsResponse(results);
return response;
}
Aggregations