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());
}
}
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();
}
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);
}
}
});
}
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);
}
Aggregations