use of com.alibaba.pegasus.builder.JobBuilder in project GraphScope by alibaba.
the class GremlinStepResource method addGremlinStep.
protected void addGremlinStep(StepBuilder stepBuilder) {
Step t = stepBuilder.getStep();
JobBuilder target = (JobBuilder) stepBuilder.getJobBuilder();
GremlinStep.Builder builder = createResourceBuilder(t, stepBuilder.getConf());
Object stepResurce = getStepResource(t, stepBuilder.getConf());
if (stepResurce instanceof Gremlin.GraphStep) {
builder.setGraphStep((Gremlin.GraphStep) stepResurce);
target.addSource(builder.build().toByteString());
} else if (stepResurce instanceof Gremlin.VertexStep) {
builder.setVertexStep((Gremlin.VertexStep) stepResurce);
target.flatMap(builder.build().toByteString());
} else if (stepResurce instanceof Gremlin.PathStep) {
builder.setPathStep((Gremlin.PathStep) stepResurce);
target.map(builder.build().toByteString());
} else if (stepResurce instanceof Gremlin.IdentityStep) {
builder.setIdentityStep((Gremlin.IdentityStep) stepResurce);
target.map(builder.build().toByteString());
} else if (stepResurce instanceof Gremlin.SelectStep) {
builder.setSelectStep((Gremlin.SelectStep) stepResurce);
target.map(builder.build().toByteString());
} else if (stepResurce instanceof Gremlin.PropertiesStep) {
builder.setPropertiesStep((Gremlin.PropertiesStep) stepResurce);
target.flatMap(builder.build().toByteString());
} else if (stepResurce instanceof Gremlin.PathLocalCountStep) {
builder.setPathLocalCountStep((Gremlin.PathLocalCountStep) stepResurce);
target.map(builder.build().toByteString());
} else if (stepResurce instanceof Gremlin.EdgeVertexStep) {
builder.setEdgeVertexStep((Gremlin.EdgeVertexStep) stepResurce);
target.map(builder.build().toByteString());
} else if (stepResurce instanceof Gremlin.UnfoldStep) {
builder.setUnfoldStep((Gremlin.UnfoldStep) stepResurce);
target.flatMap(builder.build().toByteString());
} else if (stepResurce instanceof Gremlin.EdgeBothVStep) {
builder.setEdgeBothVStep((Gremlin.EdgeBothVStep) stepResurce);
target.flatMap(builder.build().toByteString());
} else if (stepResurce instanceof Gremlin.SelectStep) {
builder.setSelectStep((Gremlin.SelectStep) stepResurce);
target.map(builder.build().toByteString());
} else if (stepResurce instanceof Gremlin.SelectOneStepWithoutBy) {
builder.setSelectOneWithoutBy((Gremlin.SelectOneStepWithoutBy) stepResurce);
target.map(builder.build().toByteString());
} else if (stepResurce instanceof Gremlin.TransformTraverserStep) {
builder.setTransformTraverserStep((Gremlin.TransformTraverserStep) stepResurce);
target.map(builder.build().toByteString());
} else {
throw new UnsupportedOperationException("operator " + t.getClass() + " not implemented");
}
}
use of com.alibaba.pegasus.builder.JobBuilder in project GraphScope by alibaba.
the class GremlinStepResource method attachResource.
@Override
public void attachResource(StepBuilder stepBuilder) {
Step step = stepBuilder.getStep();
AbstractBuilder target = stepBuilder.getJobBuilder();
if (ShuffleStrategy.needShuffle(step)) {
((JobBuilder) target).exchange(ByteString.EMPTY);
}
addGremlinStep(stepBuilder);
}
use of com.alibaba.pegasus.builder.JobBuilder in project GraphScope by alibaba.
the class ClientExample method main.
public static void main(String[] args) throws Exception {
RpcChannel rpcChannel0 = new RpcChannel("localhost", 1234);
RpcChannel rpcChannel1 = new RpcChannel("localhost", 1235);
List<RpcChannel> channels = new ArrayList<>();
channels.add(rpcChannel0);
channels.add(rpcChannel1);
RpcClient rpcClient = new RpcClient(channels);
logger.info("Will try to send request");
JobConfig confPb = JobConfig.newBuilder().setJobId(2).setJobName("ping_pong_example").setWorkers(2).setAll(PegasusClient.Empty.newBuilder().build()).build();
// for job build
JobBuilder jobBuilder = new JobBuilder(confPb);
// for nested task
JobBuilder start = new JobBuilder();
// construct job
jobBuilder.addSource(getSeed(0)).repeat(3, start.exchange(getRoute()).map(add(1)).flatMap(copy(8))).sink(getSink());
JobRequest req = jobBuilder.build();
CloseableIterator<JobResponse> iterator = rpcClient.submit(req);
// process response
try {
while (iterator.hasNext()) {
JobResponse response = iterator.next();
process(response);
}
} catch (Exception e) {
if (iterator != null) {
try {
iterator.close();
} catch (IOException ioe) {
// Ignore
}
}
error(Status.fromThrowable(e));
throw e;
}
finish();
rpcClient.shutdown();
}
use of com.alibaba.pegasus.builder.JobBuilder in project GraphScope by alibaba.
the class JobBuilderTest method main.
public static void main(String[] args) {
JobBuilder builder = new JobBuilder();
builder.addSource(ByteString.EMPTY).filter(ByteString.EMPTY).map(ByteString.EMPTY).filter(ByteString.EMPTY);
PlanUtils.print(builder);
}
use of com.alibaba.pegasus.builder.JobBuilder in project GraphScope by alibaba.
the class JobBuilderResource method attachResource.
@Override
public void attachResource(StepBuilder stepBuilder) {
AbstractBuilder target = stepBuilder.getJobBuilder();
Step step = stepBuilder.getStep();
buildJob(stepBuilder);
if (!step.getLabels().isEmpty() && target instanceof JobBuilder) {
// do nothing just as(tag)
Gremlin.QueryParams params = Gremlin.QueryParams.newBuilder().setRequiredProperties(PlanUtils.convertFrom(new ToFetchProperties(false, Collections.EMPTY_LIST))).build();
Gremlin.IdentityStep.Builder identityStep = Gremlin.IdentityStep.newBuilder().setQueryParams(params);
((JobBuilder) target).map(GremlinStepResource.createResourceBuilder(step, stepBuilder.getConf()).setIdentityStep(identityStep).build().toByteString());
}
}
Aggregations