use of com.tinkerpop.pipes.Pipe in project gremlin by tinkerpop.
the class GremlinFluentUtility method optimizePipelineForVertexQuery.
public static boolean optimizePipelineForVertexQuery(final GremlinPipeline pipeline, final Pipe pipe) {
VertexQueryPipe queryPipe = null;
for (int i = pipeline.size() - 1; i > 0; i--) {
final Pipe temp = pipeline.get(i);
if (temp instanceof VertexQueryPipe) {
queryPipe = (VertexQueryPipe) temp;
break;
} else if (!(temp instanceof IdentityPipe))
break;
}
if (null != queryPipe) {
if (pipe instanceof EdgesVerticesPipe) {
if (queryPipe.getResultElementClass().equals(Vertex.class))
return false;
queryPipe.setResultingElementClass(Vertex.class);
} else if (pipe instanceof VerticesVerticesPipe) {
if (queryPipe.getResultElementClass().equals(Vertex.class))
return false;
queryPipe.setDirection(((VerticesVerticesPipe) pipe).getDirection());
queryPipe.setLabels(((VerticesVerticesPipe) pipe).getLabels());
queryPipe.setBranchFactor(((VerticesVerticesPipe) pipe).getBranchFactor());
} else if (pipe instanceof VerticesEdgesPipe) {
if (queryPipe.getResultElementClass().equals(Vertex.class))
return false;
queryPipe.setResultingElementClass(Edge.class);
queryPipe.setDirection(((VerticesEdgesPipe) pipe).getDirection());
queryPipe.setLabels(((VerticesEdgesPipe) pipe).getLabels());
queryPipe.setBranchFactor(((VerticesEdgesPipe) pipe).getBranchFactor());
} else if (pipe instanceof PropertyFilterPipe) {
if (queryPipe.getResultElementClass().equals(Vertex.class))
return false;
final PropertyFilterPipe temp = (PropertyFilterPipe) pipe;
queryPipe.addHasContainer(new QueryPipe.HasContainer(temp.getKey(), temp.getPredicate(), temp.getValue()));
} else if (pipe instanceof IntervalFilterPipe) {
if (queryPipe.getResultElementClass().equals(Vertex.class))
return false;
final IntervalFilterPipe temp = (IntervalFilterPipe) pipe;
queryPipe.addIntervalContainer(new QueryPipe.IntervalContainer(temp.getKey(), temp.getStartValue(), temp.getEndValue()));
} else if (pipe instanceof RangeFilterPipe) {
queryPipe.setLowRange(((RangeFilterPipe) pipe).getLowRange());
queryPipe.setHighRange(((RangeFilterPipe) pipe).getHighRange());
}
pipeline.addPipe(new IdentityPipe());
return true;
} else {
return false;
}
}
use of com.tinkerpop.pipes.Pipe in project gremlin by tinkerpop.
the class GremlinStartPipeTest method testNoGraphInPath.
public void testNoGraphInPath() {
Graph graph = TinkerGraphFactory.createTinkerGraph();
Pipe pipe = new GremlinStartPipe(graph);
pipe.enablePath(true);
assertEquals(pipe.getCurrentPath().size(), 0);
pipe = new StartPipe(graph);
pipe.enablePath(true);
assertEquals(pipe.getCurrentPath().size(), 1);
}
use of com.tinkerpop.pipes.Pipe in project incubator-atlas by apache.
the class ProjectionQueryExpression method asPipe.
@Override
public Pipe asPipe() {
//todo: encapsulate all of this path logic including path sep escaping and normalizing
final int sepIdx = getField().indexOf(QueryFactory.PATH_SEP_TOKEN);
final String edgeToken = getField().substring(0, sepIdx);
GremlinPipeline pipeline = new GremlinPipeline();
Relation relation = resourceDefinition.getRelations().get(fieldSegments[0]);
if (relation != null) {
pipeline = pipeline.outE();
pipeline.add(relation.asPipe()).inV();
} else {
if (resourceDefinition.getProjections().get(fieldSegments[0]) != null) {
return super.asPipe();
} else {
//todo: default Relation implementation
pipeline = pipeline.outE().has("label", Text.REGEX, String.format(".*\\.%s", edgeToken)).inV();
}
}
//todo: set resource definition from relation on underlying expression where appropriate
String childFieldName = getField().substring(sepIdx + QueryFactory.PATH_SEP_TOKEN.length());
underlyingExpression.setField(childFieldName);
Pipe childPipe;
if (childFieldName.contains(QueryFactory.PATH_SEP_TOKEN)) {
childPipe = new ProjectionQueryExpression(underlyingExpression, resourceDefinition).asPipe();
} else {
childPipe = underlyingExpression.asPipe();
}
pipeline.add(childPipe);
return negate ? new FilterFunctionPipe(new ExcludePipeFunction(pipeline)) : pipeline;
}
use of com.tinkerpop.pipes.Pipe in project incubator-atlas by apache.
the class BooleanQueryExpression method processAndClauses.
private Collection<Pipe> processAndClauses(Map<BooleanClause.Occur, Collection<BooleanClause>> groupedClauses) {
Collection<BooleanClause> andClauses = groupedClauses.get(BooleanClause.Occur.MUST);
Collection<Pipe> andPipes = new ArrayList<>();
if (andClauses != null) {
for (BooleanClause andClause : andClauses) {
QueryExpression queryExpression = queryFactory.create(andClause.getQuery(), resourceDefinition);
properties.addAll(queryExpression.getProperties());
andPipes.add(queryExpression.asPipe());
}
}
return andPipes;
}
use of com.tinkerpop.pipes.Pipe in project incubator-atlas by apache.
the class BooleanQueryExpression method processNotClauses.
private Collection<Pipe> processNotClauses(Map<BooleanClause.Occur, Collection<BooleanClause>> groupedClauses) {
Collection<BooleanClause> notClauses = groupedClauses.get(BooleanClause.Occur.MUST_NOT);
Collection<Pipe> notPipes = new ArrayList<>();
if (notClauses != null) {
for (BooleanClause notClause : notClauses) {
QueryExpression queryExpression = queryFactory.create(notClause.getQuery(), resourceDefinition);
queryExpression.setNegate();
properties.addAll(queryExpression.getProperties());
notPipes.add(queryExpression.asPipe());
}
}
return notPipes;
}
Aggregations