Search in sources :

Example 6 with DdlException

use of com.alibaba.graphscope.groot.schema.request.DdlException in project GraphScope by alibaba.

the class SchemaClient method submitBatchDdl.

public long submitBatchDdl(String requestId, String sessionId, DdlRequestBatchPb ddlRequestBatchPb) {
    SubmitBatchDdlRequest request = SubmitBatchDdlRequest.newBuilder().setRequestId(requestId).setSessionId(sessionId).setDdlRequests(ddlRequestBatchPb).build();
    SubmitBatchDdlResponse submitBatchDdlResponse = stub.submitBatchDdl(request);
    if (submitBatchDdlResponse.getSuccess()) {
        long ddlSnapshotId = submitBatchDdlResponse.getDdlSnapshotId();
        return ddlSnapshotId;
    } else {
        throw new DdlException(submitBatchDdlResponse.getMsg());
    }
}
Also used : DdlException(com.alibaba.graphscope.groot.schema.request.DdlException) SubmitBatchDdlRequest(com.alibaba.maxgraph.proto.groot.SubmitBatchDdlRequest) SubmitBatchDdlResponse(com.alibaba.maxgraph.proto.groot.SubmitBatchDdlResponse)

Example 7 with DdlException

use of com.alibaba.graphscope.groot.schema.request.DdlException in project GraphScope by alibaba.

the class CoordinatorRpcTest method testSchemaService.

@Test
void testSchemaService() {
    SchemaManager schemaManager = mock(SchemaManager.class);
    doAnswer(invocationOnMock -> {
        CompletionCallback<Long> callback = invocationOnMock.getArgument(3);
        callback.onCompleted(10L);
        callback.onError(new DdlException("test_exception"));
        return null;
    }).when(schemaManager).submitBatchDdl(eq("test_req"), eq("test_session"), any(), any());
    SchemaService schemaService = new SchemaService(schemaManager);
    StreamObserver<SubmitBatchDdlResponse> streamObserver = mock(StreamObserver.class);
    schemaService.submitBatchDdl(SubmitBatchDdlRequest.newBuilder().setRequestId("test_req").setSessionId("test_session").build(), streamObserver);
    verify(streamObserver).onNext(SubmitBatchDdlResponse.newBuilder().setSuccess(true).setDdlSnapshotId(10L).build());
    verify(streamObserver).onNext(SubmitBatchDdlResponse.newBuilder().setSuccess(false).setMsg("test_exception").build());
    verify(streamObserver, times(2)).onCompleted();
}
Also used : DdlException(com.alibaba.graphscope.groot.schema.request.DdlException) SchemaService(com.alibaba.graphscope.groot.coordinator.SchemaService) Test(org.junit.jupiter.api.Test)

Example 8 with DdlException

use of com.alibaba.graphscope.groot.schema.request.DdlException in project GraphScope by alibaba.

the class SchemaService method submitBatchDdl.

@Override
public void submitBatchDdl(SubmitBatchDdlRequest request, StreamObserver<SubmitBatchDdlResponse> responseObserver) {
    String requestId = request.getRequestId();
    String sessionId = request.getSessionId();
    DdlRequestBatch ddlRequestBatch = DdlRequestBatch.parseProto(request.getDdlRequests());
    this.schemaManager.submitBatchDdl(requestId, sessionId, ddlRequestBatch, new CompletionCallback<Long>() {

        @Override
        public void onCompleted(Long res) {
            responseObserver.onNext(SubmitBatchDdlResponse.newBuilder().setSuccess(true).setDdlSnapshotId(res).build());
            responseObserver.onCompleted();
        }

        @Override
        public void onError(Throwable t) {
            if (t instanceof DdlException) {
                responseObserver.onNext(SubmitBatchDdlResponse.newBuilder().setSuccess(false).setMsg(t.getMessage()).build());
                responseObserver.onCompleted();
            } else {
                responseObserver.onError(t);
            }
        }
    });
}
Also used : DdlException(com.alibaba.graphscope.groot.schema.request.DdlException) DdlRequestBatch(com.alibaba.graphscope.groot.schema.request.DdlRequestBatch)

Example 9 with DdlException

use of com.alibaba.graphscope.groot.schema.request.DdlException in project GraphScope by alibaba.

the class CommitDataLoadExecutor method execute.

@Override
public DdlResult execute(ByteString ddlBlob, GraphDef graphDef, int partitionCount) throws InvalidProtocolBufferException {
    CommitDataLoadPb commitDataLoadPb = CommitDataLoadPb.parseFrom(ddlBlob);
    DataLoadTargetPb dataLoadTargetPb = commitDataLoadPb.getTarget();
    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);
    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");
        }
        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");
        }
    }
    version++;
    graphDefBuilder.setVersion(version);
    GraphDef newGraphDef = graphDefBuilder.build();
    List<Operation> operations = new ArrayList<>(partitionCount);
    for (int i = 0; i < partitionCount; i++) {
        operations.add(new CommitDataLoadOperation(i, version, CommitDataLoadPb.newBuilder().setTableIdx(commitDataLoadPb.getTableIdx()).setTarget(targetBuilder.build().toProto()).build()));
    }
    return new DdlResult(newGraphDef, operations);
}
Also used : DdlException(com.alibaba.graphscope.groot.schema.request.DdlException) EdgeKind(com.alibaba.maxgraph.sdkcommon.schema.EdgeKind) CommitDataLoadOperation(com.alibaba.graphscope.groot.operation.ddl.CommitDataLoadOperation) ArrayList(java.util.ArrayList) ByteString(com.google.protobuf.ByteString) Operation(com.alibaba.graphscope.groot.operation.Operation) CommitDataLoadOperation(com.alibaba.graphscope.groot.operation.ddl.CommitDataLoadOperation) CommitDataLoadPb(com.alibaba.maxgraph.proto.CommitDataLoadPb) 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)

Aggregations

DdlException (com.alibaba.graphscope.groot.schema.request.DdlException)9 Operation (com.alibaba.graphscope.groot.operation.Operation)6 GraphDef (com.alibaba.maxgraph.sdkcommon.schema.GraphDef)6 LabelId (com.alibaba.maxgraph.sdkcommon.schema.LabelId)6 ByteString (com.google.protobuf.ByteString)6 ArrayList (java.util.ArrayList)6 EdgeKind (com.alibaba.maxgraph.sdkcommon.schema.EdgeKind)5 TypeDef (com.alibaba.maxgraph.sdkcommon.schema.TypeDef)4 DataLoadTargetPb (com.alibaba.maxgraph.proto.DataLoadTargetPb)2 EdgeKindPb (com.alibaba.maxgraph.proto.groot.EdgeKindPb)2 TypeDefPb (com.alibaba.maxgraph.proto.groot.TypeDefPb)2 DataLoadTarget (com.alibaba.maxgraph.sdkcommon.common.DataLoadTarget)2 PropertyDef (com.alibaba.maxgraph.sdkcommon.schema.PropertyDef)2 SchemaService (com.alibaba.graphscope.groot.coordinator.SchemaService)1 AddEdgeKindOperation (com.alibaba.graphscope.groot.operation.ddl.AddEdgeKindOperation)1 CommitDataLoadOperation (com.alibaba.graphscope.groot.operation.ddl.CommitDataLoadOperation)1 PrepareDataLoadOperation (com.alibaba.graphscope.groot.operation.ddl.PrepareDataLoadOperation)1 RemoveEdgeKindOperation (com.alibaba.graphscope.groot.operation.ddl.RemoveEdgeKindOperation)1 DdlRequestBatch (com.alibaba.graphscope.groot.schema.request.DdlRequestBatch)1 CommitDataLoadPb (com.alibaba.maxgraph.proto.CommitDataLoadPb)1