Search in sources :

Example 6 with PipeFunction

use of com.tinkerpop.pipes.PipeFunction in project gremlin by tinkerpop.

the class TransformStepTest method test_g_v1_transformXnameX.

public void test_g_v1_transformXnameX() {
    super.test_g_v1_transformXnameX(new GremlinPipeline(g.getVertex(1)).transform(new PipeFunction<Vertex, String>() {

        public String compute(Vertex vertex) {
            return (String) vertex.getProperty("name");
        }
    }));
    super.test_g_v1_transformXnameX(new GremlinPipeline(g.getVertex(1)).optimize(false).transform(new PipeFunction<Vertex, String>() {

        public String compute(Vertex vertex) {
            return (String) vertex.getProperty("name");
        }
    }));
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) GremlinPipeline(com.tinkerpop.gremlin.java.GremlinPipeline) PipeFunction(com.tinkerpop.pipes.PipeFunction)

Example 7 with PipeFunction

use of com.tinkerpop.pipes.PipeFunction in project gremlin by tinkerpop.

the class TransformStepTest method test_g_v1_out_transformXnameX_transformXlengthX.

public void test_g_v1_out_transformXnameX_transformXlengthX() {
    super.test_g_v1_out_transformXnameX_transformXlengthX(new GremlinPipeline(g.getVertex(1)).out().transform(new PipeFunction<Vertex, String>() {

        public String compute(Vertex vertex) {
            return (String) vertex.getProperty("name");
        }
    }).transform(new PipeFunction<String, Integer>() {

        public Integer compute(String name) {
            return name.length();
        }
    }));
    super.test_g_v1_out_transformXnameX_transformXlengthX(new GremlinPipeline(g.getVertex(1)).optimize(false).out().transform(new PipeFunction<Vertex, String>() {

        public String compute(Vertex vertex) {
            return (String) vertex.getProperty("name");
        }
    }).transform(new PipeFunction<String, Integer>() {

        public Integer compute(String name) {
            return name.length();
        }
    }));
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) GremlinPipeline(com.tinkerpop.gremlin.java.GremlinPipeline) PipeFunction(com.tinkerpop.pipes.PipeFunction)

Example 8 with PipeFunction

use of com.tinkerpop.pipes.PipeFunction in project gremlin by tinkerpop.

the class TransformStepTest method test_g_v1_outE_label_transformXlengthX.

public void test_g_v1_outE_label_transformXlengthX() {
    super.test_g_v1_outE_label_transformXlengthX(new GremlinPipeline(g.getVertex(1)).outE().label().transform(new PipeFunction<String, Integer>() {

        public Integer compute(String name) {
            return name.length();
        }
    }));
    super.test_g_v1_outE_label_transformXlengthX(new GremlinPipeline(g.getVertex(1)).optimize(false).outE().label().transform(new PipeFunction<String, Integer>() {

        public Integer compute(String name) {
            return name.length();
        }
    }));
}
Also used : GremlinPipeline(com.tinkerpop.gremlin.java.GremlinPipeline) PipeFunction(com.tinkerpop.pipes.PipeFunction)

Example 9 with PipeFunction

use of com.tinkerpop.pipes.PipeFunction in project incubator-atlas by apache.

the class TermResourceDefinition method getHierarchyProjection.

private Projection getHierarchyProjection() {
    final String projectionName = "hierarchy";
    return new Projection(projectionName, Projection.Cardinality.SINGLE, new TransformFunctionPipe<>(new PipeFunction<VertexWrapper, Collection<ProjectionResult>>() {

        @Override
        public Collection<ProjectionResult> compute(VertexWrapper start) {
            Map<String, Object> map = new TreeMap<>(new ResourceComparator());
            TermPath termPath = new TermPath(start.getVertex().<String>getProperty(Constants.ENTITY_TYPE_PROPERTY_KEY));
            map.put("path", termPath.getPath());
            map.put("short_name", termPath.getShortName());
            map.put("taxonomy", termPath.getTaxonomyName());
            return Collections.singleton(new ProjectionResult(projectionName, start, Collections.singleton(map)));
        }
    }));
}
Also used : ResourceComparator(org.apache.atlas.catalog.ResourceComparator) ProjectionResult(org.apache.atlas.catalog.projection.ProjectionResult) VertexWrapper(org.apache.atlas.catalog.VertexWrapper) TermPath(org.apache.atlas.catalog.TermPath) Projection(org.apache.atlas.catalog.projection.Projection) PipeFunction(com.tinkerpop.pipes.PipeFunction)

Example 10 with PipeFunction

use of com.tinkerpop.pipes.PipeFunction in project incubator-atlas by apache.

the class TermResourceDefinition method getSubTermProjection.

private Projection getSubTermProjection() {
    // todo: combine with other term projections
    final String termsProjectionName = "terms";
    return new Projection(termsProjectionName, Projection.Cardinality.SINGLE, new TransformFunctionPipe<>(new PipeFunction<VertexWrapper, Collection<ProjectionResult>>() {

        @Override
        public Collection<ProjectionResult> compute(VertexWrapper start) {
            Map<String, Object> map = new TreeMap<>(new ResourceComparator());
            StringBuilder sb = new StringBuilder();
            sb.append("v1/taxonomies/");
            TermPath termPath = new TermPath(start.getVertex().<String>getProperty(Constants.ENTITY_TYPE_PROPERTY_KEY));
            String[] paths = termPath.getPathSegments();
            sb.append(termPath.getTaxonomyName());
            for (String path : paths) {
                // todo: shouldn't need to check for null or empty after TermPath addition
                if (path != null && !path.isEmpty()) {
                    sb.append("/terms/");
                    sb.append(path);
                }
            }
            sb.append("/terms");
            map.put("href", sb.toString());
            return Collections.singleton(new ProjectionResult(termsProjectionName, start, Collections.singleton(map)));
        }
    }));
}
Also used : ResourceComparator(org.apache.atlas.catalog.ResourceComparator) Projection(org.apache.atlas.catalog.projection.Projection) ProjectionResult(org.apache.atlas.catalog.projection.ProjectionResult) VertexWrapper(org.apache.atlas.catalog.VertexWrapper) TermPath(org.apache.atlas.catalog.TermPath) PipeFunction(com.tinkerpop.pipes.PipeFunction)

Aggregations

PipeFunction (com.tinkerpop.pipes.PipeFunction)17 GremlinPipeline (com.tinkerpop.gremlin.java.GremlinPipeline)13 Vertex (com.tinkerpop.blueprints.Vertex)11 VertexWrapper (org.apache.atlas.catalog.VertexWrapper)5 Projection (org.apache.atlas.catalog.projection.Projection)4 ProjectionResult (org.apache.atlas.catalog.projection.ProjectionResult)4 ResourceComparator (org.apache.atlas.catalog.ResourceComparator)3 HashMap (java.util.HashMap)2 List (java.util.List)2 TermPath (org.apache.atlas.catalog.TermPath)2 Edge (com.tinkerpop.blueprints.Edge)1 TermVertexWrapper (org.apache.atlas.catalog.TermVertexWrapper)1