Search in sources :

Example 1 with DataLoadTarget

use of com.alibaba.maxgraph.sdkcommon.common.DataLoadTarget in project GraphScope by alibaba.

the class PrepareDataLoadExecutor method execute.

@Override
public DdlResult execute(ByteString ddlBlob, GraphDef graphDef, int partitionCount) throws InvalidProtocolBufferException {
    DataLoadTargetPb dataLoadTargetPb = DataLoadTargetPb.parseFrom(ddlBlob);
    DataLoadTarget dataLoadTarget = DataLoadTarget.parseProto(dataLoadTargetPb);
    String label = dataLoadTarget.getLabel();
    String srcLabel = dataLoadTarget.getSrcLabel();
    String dstLabel = dataLoadTarget.getDstLabel();
    long version = graphDef.getSchemaVersion();
    if (!graphDef.hasLabel(label)) {
        throw new DdlException("label [" + label + "] not exists, schema version [" + version + "]");
    }
    GraphDef.Builder graphDefBuilder = GraphDef.newBuilder(graphDef);
    TypeDef typeDef = graphDef.getTypeDef(label);
    long tableIdx = graphDef.getTableIdx();
    tableIdx++;
    DataLoadTarget.Builder targetBuilder = DataLoadTarget.newBuilder(dataLoadTarget);
    if (srcLabel == null || srcLabel.isEmpty()) {
        // Vertex type
        if (typeDef.getTypeEnum() != TypeEnum.VERTEX) {
            throw new DdlException("invalid data load target [" + dataLoadTarget + "], label is not a vertex");
        }
        graphDefBuilder.putVertexTableId(typeDef.getTypeLabelId(), tableIdx);
        targetBuilder.setLabelId(typeDef.getLabelId());
    } else {
        // Edge kind
        if (typeDef.getTypeEnum() != TypeEnum.EDGE) {
            throw new DdlException("invalid data load target [" + dataLoadTarget + "], label is not an edge");
        }
        EdgeKind.Builder edgeKindBuilder = EdgeKind.newBuilder();
        LabelId edgeLabelId = graphDef.getLabelId(label);
        if (edgeLabelId == null) {
            throw new DdlException("invalid edgeLabel [" + label + "], schema version [" + version + "]");
        }
        edgeKindBuilder.setEdgeLabelId(edgeLabelId);
        targetBuilder.setLabelId(edgeLabelId.getId());
        LabelId srcVertexLabelId = graphDef.getLabelId(srcLabel);
        if (srcVertexLabelId == null) {
            throw new DdlException("invalid srcVertexLabel [" + srcLabel + "], schema version [" + version + "]");
        }
        edgeKindBuilder.setSrcVertexLabelId(srcVertexLabelId);
        targetBuilder.setSrcLabelId(srcVertexLabelId.getId());
        LabelId dstVertexLabelId = graphDef.getLabelId(dstLabel);
        if (dstVertexLabelId == null) {
            throw new DdlException("invalid dstVertexLabel [" + dstLabel + "], schema version [" + version + "]");
        }
        edgeKindBuilder.setDstVertexLabelId(dstVertexLabelId);
        targetBuilder.setDstLabelId(dstVertexLabelId.getId());
        EdgeKind edgeKind = edgeKindBuilder.build();
        if (!graphDef.hasEdgeKind(edgeKind)) {
            throw new DdlException("invalid data load target [" + dataLoadTarget + "], edgeKind not exists");
        }
        graphDefBuilder.putEdgeTableId(edgeKind, tableIdx);
    }
    version++;
    graphDefBuilder.setTableIdx(tableIdx);
    graphDefBuilder.setVersion(version);
    GraphDef newGraphDef = graphDefBuilder.build();
    List<Operation> operations = new ArrayList<>(partitionCount);
    for (int i = 0; i < partitionCount; i++) {
        operations.add(new PrepareDataLoadOperation(i, version, targetBuilder.build(), tableIdx));
    }
    return new DdlResult(newGraphDef, operations);
}
Also used : DdlException(com.alibaba.graphscope.groot.schema.request.DdlException) EdgeKind(com.alibaba.maxgraph.sdkcommon.schema.EdgeKind) ArrayList(java.util.ArrayList) ByteString(com.google.protobuf.ByteString) Operation(com.alibaba.graphscope.groot.operation.Operation) PrepareDataLoadOperation(com.alibaba.graphscope.groot.operation.ddl.PrepareDataLoadOperation) DataLoadTargetPb(com.alibaba.maxgraph.proto.DataLoadTargetPb) GraphDef(com.alibaba.maxgraph.sdkcommon.schema.GraphDef) DataLoadTarget(com.alibaba.maxgraph.sdkcommon.common.DataLoadTarget) TypeDef(com.alibaba.maxgraph.sdkcommon.schema.TypeDef) LabelId(com.alibaba.maxgraph.sdkcommon.schema.LabelId) PrepareDataLoadOperation(com.alibaba.graphscope.groot.operation.ddl.PrepareDataLoadOperation)

Example 2 with DataLoadTarget

use of com.alibaba.maxgraph.sdkcommon.common.DataLoadTarget in project GraphScope by alibaba.

the class ClientTest method testCommitData.

@Test
void testCommitData() {
    long tableId = -4611686018427387871L;
    DataLoadTarget target = DataLoadTarget.newBuilder().setLabel("person").build();
    client.commitDataLoad(Collections.singletonMap(tableId, target));
}
Also used : DataLoadTarget(com.alibaba.maxgraph.sdkcommon.common.DataLoadTarget) Test(org.junit.jupiter.api.Test)

Example 3 with DataLoadTarget

use of com.alibaba.maxgraph.sdkcommon.common.DataLoadTarget in project GraphScope by alibaba.

the class ClientService method prepareDataLoad.

@Override
public void prepareDataLoad(PrepareDataLoadRequest request, StreamObserver<PrepareDataLoadResponse> responseObserver) {
    DdlRequestBatch.Builder builder = DdlRequestBatch.newBuilder();
    for (DataLoadTargetPb dataLoadTargetPb : request.getDataLoadTargetsList()) {
        DataLoadTarget dataLoadTarget = DataLoadTarget.parseProto(dataLoadTargetPb);
        builder.addDdlRequest(new com.alibaba.graphscope.groot.schema.request.PrepareDataLoadRequest(dataLoadTarget));
    }
    DdlRequestBatch batch = builder.build();
    try {
        long snapshotId = this.batchDdlClient.batchDdl(batch);
        this.snapshotCache.addListener(snapshotId, () -> {
            responseObserver.onNext(PrepareDataLoadResponse.newBuilder().setGraphDef(this.snapshotCache.getSnapshotWithSchema().getGraphDef().toProto()).build());
            responseObserver.onCompleted();
        });
    } catch (Exception e) {
        logger.error("prepare data load failed", e);
        responseObserver.onError(Status.INTERNAL.withDescription(e.getMessage()).asRuntimeException());
    }
}
Also used : com.alibaba.graphscope.groot.schema.request(com.alibaba.graphscope.groot.schema.request) DataLoadTarget(com.alibaba.maxgraph.sdkcommon.common.DataLoadTarget) com.alibaba.maxgraph.proto.groot(com.alibaba.maxgraph.proto.groot) DataLoadTargetPb(com.alibaba.maxgraph.proto.DataLoadTargetPb)

Example 4 with DataLoadTarget

use of com.alibaba.maxgraph.sdkcommon.common.DataLoadTarget in project GraphScope by alibaba.

the class ClientService method commitDataLoad.

@Override
public void commitDataLoad(CommitDataLoadRequest request, StreamObserver<CommitDataLoadResponse> responseObserver) {
    DdlRequestBatch.Builder builder = DdlRequestBatch.newBuilder();
    Map<Long, DataLoadTargetPb> tableToTarget = request.getTableToTargetMap();
    tableToTarget.forEach((tableId, targetPb) -> {
        DataLoadTarget dataLoadTarget = DataLoadTarget.parseProto(targetPb);
        builder.addDdlRequest(new com.alibaba.graphscope.groot.schema.request.CommitDataLoadRequest(dataLoadTarget, tableId));
    });
    DdlRequestBatch batch = builder.build();
    try {
        long snapshotId = this.batchDdlClient.batchDdl(batch);
        this.snapshotCache.addListener(snapshotId, () -> {
            responseObserver.onNext(CommitDataLoadResponse.newBuilder().build());
            responseObserver.onCompleted();
        });
    } catch (Exception e) {
        logger.error("commit data load failed", e);
        responseObserver.onError(Status.INTERNAL.withDescription(e.getMessage()).asRuntimeException());
    }
}
Also used : com.alibaba.graphscope.groot.schema.request(com.alibaba.graphscope.groot.schema.request) DataLoadTarget(com.alibaba.maxgraph.sdkcommon.common.DataLoadTarget) com.alibaba.maxgraph.proto.groot(com.alibaba.maxgraph.proto.groot) DataLoadTargetPb(com.alibaba.maxgraph.proto.DataLoadTargetPb)

Example 5 with DataLoadTarget

use of com.alibaba.maxgraph.sdkcommon.common.DataLoadTarget in project GraphScope by alibaba.

the class MaxGraphClient method prepareDataLoad.

public GraphSchema prepareDataLoad(List<DataLoadTarget> targets) {
    PrepareDataLoadRequest.Builder builder = PrepareDataLoadRequest.newBuilder();
    for (DataLoadTarget target : targets) {
        builder.addDataLoadTargets(target.toProto());
    }
    PrepareDataLoadResponse response = this.stub.prepareDataLoad(builder.build());
    return GraphDef.parseProto(response.getGraphDef());
}
Also used : DataLoadTarget(com.alibaba.maxgraph.sdkcommon.common.DataLoadTarget) PrepareDataLoadRequest(com.alibaba.maxgraph.proto.groot.PrepareDataLoadRequest) PrepareDataLoadResponse(com.alibaba.maxgraph.proto.groot.PrepareDataLoadResponse)

Aggregations

DataLoadTarget (com.alibaba.maxgraph.sdkcommon.common.DataLoadTarget)9 DataLoadTargetPb (com.alibaba.maxgraph.proto.DataLoadTargetPb)4 Operation (com.alibaba.graphscope.groot.operation.Operation)2 com.alibaba.graphscope.groot.schema.request (com.alibaba.graphscope.groot.schema.request)2 DdlException (com.alibaba.graphscope.groot.schema.request.DdlException)2 MaxGraphClient (com.alibaba.graphscope.groot.sdk.MaxGraphClient)2 GraphEdge (com.alibaba.maxgraph.compiler.api.schema.GraphEdge)2 GraphElement (com.alibaba.maxgraph.compiler.api.schema.GraphElement)2 com.alibaba.maxgraph.proto.groot (com.alibaba.maxgraph.proto.groot)2 EdgeKind (com.alibaba.maxgraph.sdkcommon.schema.EdgeKind)2 GraphDef (com.alibaba.maxgraph.sdkcommon.schema.GraphDef)2 LabelId (com.alibaba.maxgraph.sdkcommon.schema.LabelId)2 TypeDef (com.alibaba.maxgraph.sdkcommon.schema.TypeDef)2 ByteString (com.google.protobuf.ByteString)2 ArrayList (java.util.ArrayList)2 CommitDataLoadOperation (com.alibaba.graphscope.groot.operation.ddl.CommitDataLoadOperation)1 PrepareDataLoadOperation (com.alibaba.graphscope.groot.operation.ddl.PrepareDataLoadOperation)1 GraphSchema (com.alibaba.maxgraph.compiler.api.schema.GraphSchema)1 ColumnMappingInfo (com.alibaba.maxgraph.dataload.databuild.ColumnMappingInfo)1 CommitDataLoadPb (com.alibaba.maxgraph.proto.CommitDataLoadPb)1