Java Code Examples for org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal#by()
The following examples show how to use
org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal#by() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Select.java From gremlin-ogm with Apache License 2.0 | 6 votes |
@Override public GraphTraversal<Element, Map<String, Object>> apply( GraphTraversal<Element, Element> traversal) { GraphTraversal<Element, Map<String, Object>> selectTraversal; if (selectKey2 == null) { selectTraversal = traversal.select(selectKey1); } else { selectTraversal = traversal.select(selectKey1, selectKey2, otherSelectKeys.toArray(new String[] {})); } if (selectKey1 != null) { selectTraversal.by(); } if (selectKey2 != null) { selectTraversal.by(); } otherSelectKeys.forEach(otherSelectKey -> { selectTraversal.by(); }); return selectTraversal; }
Example 2
Source File: SortDescription.java From timbuctoo with GNU General Public License v3.0 | 6 votes |
public void sort(GraphTraversal<Vertex, Vertex> searchResult, List<SortParameter> sortParameters) { if (sortParameters.isEmpty()) { return; } List<SortTraversal> traversals = collectTraversals(sortParameters); if (traversals.isEmpty()) { return; } searchResult.order(); for (SortTraversal sortTraversal : traversals) { for (GraphTraversal<Object, Object> traversal : sortTraversal.traversals) { searchResult.by(traversal, sortTraversal.order); } } }
Example 3
Source File: KillrVideoTraversalDsl.java From graph-examples with Apache License 2.0 | 5 votes |
/** * Expects an incoming {@code Vertex} and projects it to a {@code Map} with the specified {@link Enrichment} values * passed to it. * * @param includeIdLabel adds the {@code id} and {@code label} when {@code true} * @param enrichments the additional data to calculate and include for each {code Vertex} */ public default GraphTraversal<S, Map<String,Object>> enrich(boolean includeIdLabel, Enrichment... enrichments) { // get the traversals associated with each enrichment and flatten them to the traversals that // will be passed to the by() modulators List<GraphTraversal> projectTraversals = Stream.of(enrichments).map(Enrichment::getTraversals). flatMap(Collection::stream).collect(Collectors.toList()); if (includeIdLabel) { projectTraversals.add(__.id()); projectTraversals.add(__.label()); } // the keys should occur in the same order as the by() modulators - like the traversals above the list of // keys per enrichment are flattened so as to be passed to the project() step List<String> keys = Stream.of(enrichments).map(Enrichment::getProjectedKey). flatMap(Collection::stream).collect(Collectors.toList()); if (includeIdLabel) { keys.add("id"); keys.add("label"); } // the project() step has a signature that does not allow for an empty set of keys. the first key in the list // needs to be passed explicitly followed by a the rest of the list as varargs String[] projectKeys = new String[keys.size() - 1]; projectKeys = keys.subList(1, keys.size()).toArray(projectKeys); GraphTraversal t = project(keys.get(0), projectKeys); for (GraphTraversal projectTraversal : projectTraversals) { t = t.by(projectTraversal); } return t; }