Search in sources :

Example 1 with JobBuilder

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");
    }
}
Also used : Step(org.apache.tinkerpop.gremlin.process.traversal.Step) RemovePathHistoryStep(com.alibaba.graphscope.gaia.plan.strategy.global.RemovePathHistoryStep) GremlinStep(com.alibaba.graphscope.common.proto.Gremlin.GremlinStep) Gremlin(com.alibaba.graphscope.common.proto.Gremlin) JobBuilder(com.alibaba.pegasus.builder.JobBuilder) GremlinStep(com.alibaba.graphscope.common.proto.Gremlin.GremlinStep)

Example 2 with JobBuilder

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);
}
Also used : AbstractBuilder(com.alibaba.pegasus.builder.AbstractBuilder) JobBuilder(com.alibaba.pegasus.builder.JobBuilder) Step(org.apache.tinkerpop.gremlin.process.traversal.Step) RemovePathHistoryStep(com.alibaba.graphscope.gaia.plan.strategy.global.RemovePathHistoryStep) GremlinStep(com.alibaba.graphscope.common.proto.Gremlin.GremlinStep)

Example 3 with JobBuilder

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();
}
Also used : JobRequest(com.alibaba.pegasus.service.protocol.PegasusClient.JobRequest) ArrayList(java.util.ArrayList) JobBuilder(com.alibaba.pegasus.builder.JobBuilder) JobResponse(com.alibaba.pegasus.service.protocol.PegasusClient.JobResponse) IOException(java.io.IOException) JobConfig(com.alibaba.pegasus.service.protocol.PegasusClient.JobConfig) IOException(java.io.IOException)

Example 4 with JobBuilder

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);
}
Also used : JobBuilder(com.alibaba.pegasus.builder.JobBuilder)

Example 5 with JobBuilder

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());
    }
}
Also used : AbstractBuilder(com.alibaba.pegasus.builder.AbstractBuilder) ToFetchProperties(com.alibaba.graphscope.gaia.plan.strategy.global.property.cache.ToFetchProperties) JobBuilder(com.alibaba.pegasus.builder.JobBuilder) Step(org.apache.tinkerpop.gremlin.process.traversal.Step) Gremlin(com.alibaba.graphscope.common.proto.Gremlin)

Aggregations

JobBuilder (com.alibaba.pegasus.builder.JobBuilder)5 Step (org.apache.tinkerpop.gremlin.process.traversal.Step)3 Gremlin (com.alibaba.graphscope.common.proto.Gremlin)2 GremlinStep (com.alibaba.graphscope.common.proto.Gremlin.GremlinStep)2 RemovePathHistoryStep (com.alibaba.graphscope.gaia.plan.strategy.global.RemovePathHistoryStep)2 AbstractBuilder (com.alibaba.pegasus.builder.AbstractBuilder)2 ToFetchProperties (com.alibaba.graphscope.gaia.plan.strategy.global.property.cache.ToFetchProperties)1 JobConfig (com.alibaba.pegasus.service.protocol.PegasusClient.JobConfig)1 JobRequest (com.alibaba.pegasus.service.protocol.PegasusClient.JobRequest)1 JobResponse (com.alibaba.pegasus.service.protocol.PegasusClient.JobResponse)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1