Search in sources :

Example 1 with ValuePart

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;
}
Also used : FloatValuesPart(com.tencent.angel.psagent.matrix.transport.router.value.FloatValuesPart) ValuePart(com.tencent.angel.psagent.matrix.transport.router.ValuePart) ILongKeyPartOp(com.tencent.angel.psagent.matrix.transport.router.operator.ILongKeyPartOp) LongValuesPart(com.tencent.angel.psagent.matrix.transport.router.value.LongValuesPart) IIntKeyPartOp(com.tencent.angel.psagent.matrix.transport.router.operator.IIntKeyPartOp) IntValuesPart(com.tencent.angel.psagent.matrix.transport.router.value.IntValuesPart) DoubleValuesPart(com.tencent.angel.psagent.matrix.transport.router.value.DoubleValuesPart)

Example 2 with ValuePart

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;
}
Also used : ValueType(com.tencent.angel.ps.server.data.request.ValueType) CompStreamKeyValuePart(com.tencent.angel.psagent.matrix.transport.router.CompStreamKeyValuePart) ValuePart(com.tencent.angel.psagent.matrix.transport.router.ValuePart) KeyValuePart(com.tencent.angel.psagent.matrix.transport.router.KeyValuePart)

Example 3 with 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();
    }
}
Also used : IndexPartGetRowRequest(com.tencent.angel.ps.server.data.request.IndexPartGetRowRequest) ValuePart(com.tencent.angel.psagent.matrix.transport.router.ValuePart) KeyPart(com.tencent.angel.psagent.matrix.transport.router.KeyPart) ServerRow(com.tencent.angel.ps.storage.vector.ServerRow) StreamIndexPartGetRowResponse(com.tencent.angel.ps.server.data.response.StreamIndexPartGetRowResponse)

Example 4 with ValuePart

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;
}
Also used : IndexPartGetRowsRequest(com.tencent.angel.ps.server.data.request.IndexPartGetRowsRequest) ValuePart(com.tencent.angel.psagent.matrix.transport.router.ValuePart) IndexPartGetRowsResponse(com.tencent.angel.ps.server.data.response.IndexPartGetRowsResponse) KeyPart(com.tencent.angel.psagent.matrix.transport.router.KeyPart) ServerRow(com.tencent.angel.ps.storage.vector.ServerRow)

Aggregations

ValuePart (com.tencent.angel.psagent.matrix.transport.router.ValuePart)4 ServerRow (com.tencent.angel.ps.storage.vector.ServerRow)2 KeyPart (com.tencent.angel.psagent.matrix.transport.router.KeyPart)2 IndexPartGetRowRequest (com.tencent.angel.ps.server.data.request.IndexPartGetRowRequest)1 IndexPartGetRowsRequest (com.tencent.angel.ps.server.data.request.IndexPartGetRowsRequest)1 ValueType (com.tencent.angel.ps.server.data.request.ValueType)1 IndexPartGetRowsResponse (com.tencent.angel.ps.server.data.response.IndexPartGetRowsResponse)1 StreamIndexPartGetRowResponse (com.tencent.angel.ps.server.data.response.StreamIndexPartGetRowResponse)1 CompStreamKeyValuePart (com.tencent.angel.psagent.matrix.transport.router.CompStreamKeyValuePart)1 KeyValuePart (com.tencent.angel.psagent.matrix.transport.router.KeyValuePart)1 IIntKeyPartOp (com.tencent.angel.psagent.matrix.transport.router.operator.IIntKeyPartOp)1 ILongKeyPartOp (com.tencent.angel.psagent.matrix.transport.router.operator.ILongKeyPartOp)1 DoubleValuesPart (com.tencent.angel.psagent.matrix.transport.router.value.DoubleValuesPart)1 FloatValuesPart (com.tencent.angel.psagent.matrix.transport.router.value.FloatValuesPart)1 IntValuesPart (com.tencent.angel.psagent.matrix.transport.router.value.IntValuesPart)1 LongValuesPart (com.tencent.angel.psagent.matrix.transport.router.value.LongValuesPart)1