use of com.tinkerpop.gremlin.java.GremlinPipeline in project gremlin by tinkerpop.
the class MapStepTest method test_g_v1_map.
public void test_g_v1_map() {
super.test_g_v1_map(new GremlinPipeline(g.getVertex(1)).map());
super.test_g_v1_map(new GremlinPipeline(g.getVertex(1)).optimize(false).map());
}
use of com.tinkerpop.gremlin.java.GremlinPipeline in project gremlin by tinkerpop.
the class MapStepTest method test_g_v1_outXknowsX_map.
public void test_g_v1_outXknowsX_map() {
super.test_g_v1_outXknowsX_map(new GremlinPipeline(g.getVertex(1)).out("knows").map());
super.test_g_v1_outXknowsX_map(new GremlinPipeline(g.getVertex(1)).optimize(false).out("knows").map());
}
use of com.tinkerpop.gremlin.java.GremlinPipeline in project orientdb by orientechnologies.
the class OGremlinHelper method execute.
public static Object execute(final OrientBaseGraph graph, final String iText, final Map<Object, Object> iConfiguredParameters, Map<Object, Object> iCurrentParameters, final List<Object> iResult, final OGremlinCallback iBeforeExecution, final OGremlinCallback iAfterExecution) {
try {
final ScriptEngine engine = getGremlinEngine(graph);
try {
final String output = OGremlinHelper.bindParameters(engine, iConfiguredParameters, iCurrentParameters);
if (iBeforeExecution != null)
if (!iBeforeExecution.call(engine, graph))
return null;
if (iText == null) {
return null;
}
final Object scriptResult = engine.eval(iText);
if (iAfterExecution != null)
if (!iAfterExecution.call(engine, graph))
return null;
// - Map -> ODocument
if (output != null) {
if (scriptResult instanceof GremlinPipeline) {
Iterator<?> it = ((GremlinPipeline<?, ?>) scriptResult).iterator();
while (it.hasNext()) // ignore iCurrentRecord but traverse still required
it.next();
}
final Map<String, Object> map = (Map<String, Object>) engine.get(output);
ODocument oDocument = new ODocument(map);
iResult.add(oDocument);
return oDocument;
}
// returned for this call in the last pipe
if (scriptResult instanceof GremlinPipeline) {
final Iterator<?> it = ((GremlinPipeline<?, ?>) scriptResult).iterator();
Object finalResult = null;
List<Object> resultCollection = null;
while (it.hasNext()) {
Object current = it.next();
if (finalResult != null) {
if (resultCollection == null) {
// CONVERT IT INTO A COLLECTION
resultCollection = new ArrayList<Object>();
resultCollection.add(finalResult);
}
resultCollection.add(current);
} else
finalResult = current;
}
if (resultCollection != null) {
iResult.addAll(resultCollection);
return resultCollection;
} else {
if (finalResult != null)
iResult.add(finalResult);
return finalResult;
}
} else if (scriptResult != null)
iResult.add(scriptResult);
return scriptResult;
} catch (Exception e) {
throw OException.wrapException(new OCommandExecutionException("Error on execution of the GREMLIN script"), e);
} finally {
OGremlinHelper.global().releaseEngine(engine);
}
} finally {
OGremlinHelper.global().releaseGraph(graph);
}
}
use of com.tinkerpop.gremlin.java.GremlinPipeline in project orientdb by orientechnologies.
the class TestDirtyTrackingTreeRidBagRemote method test.
@Test
public void test() {
final int max = OGlobalConfiguration.RID_BAG_EMBEDDED_TO_SBTREEBONSAI_THRESHOLD.getValueAsInteger() * 2;
OrientGraph graph = new OrientGraph("remote:localhost:3064/" + TestDirtyTrackingTreeRidBagRemote.class.getSimpleName(), "root", "root");
try {
graph.getRawGraph().declareIntent(new OIntentMassiveInsert());
graph.createEdgeType("Edge");
OIdentifiable oneVertex = null;
Map<Object, Vertex> vertices = new HashMap<Object, Vertex>();
for (int i = 0; i < max; i++) {
Vertex v = graph.addVertex("class:V");
v.setProperty("key", "foo" + i);
graph.commit();
vertices.put(v.getProperty("key"), v);
if (i == max / 2 + 1)
oneVertex = ((OrientVertex) v).getIdentity();
}
graph.commit();
// Add the edges
for (int i = 0; i < max; i++) {
String codeUCD1 = "foo" + i;
// Take the first vertex
Vertex med1 = (Vertex) vertices.get(codeUCD1);
// For the 2nd term
for (int j = 0; j < max; j++) {
String key = "foo" + j;
// Take the second vertex
Vertex med2 = (Vertex) vertices.get(key);
// ((OrientVertex)med2).getRecord().reload();
OrientEdge eInteraction = graph.addEdge(null, med1, med2, "Edge");
assertNotNull(graph.getRawGraph().getTransaction().getRecordEntry(((OrientVertex) med2).getIdentity()));
}
// COMMIT
graph.commit();
}
graph.getRawGraph().getLocalCache().clear();
OrientVertex vertex = graph.getVertex(oneVertex);
assertEquals(new GremlinPipeline<Vertex, Long>().start(vertex).in("Edge").count(), max);
} finally {
graph.shutdown();
}
}
use of com.tinkerpop.gremlin.java.GremlinPipeline in project incubator-atlas by apache.
the class AtlasEntityQueryTest method testExecute_Collection_update.
@Test
public void testExecute_Collection_update() throws Exception {
AtlasGraph graph = createStrictMock(AtlasGraph.class);
QueryExpression expression = createStrictMock(QueryExpression.class);
ResourceDefinition resourceDefinition = createStrictMock(ResourceDefinition.class);
Request request = createStrictMock(Request.class);
GremlinPipeline initialPipeline = createStrictMock(GremlinPipeline.class);
Pipe queryPipe = createStrictMock(Pipe.class);
Pipe expressionPipe = createStrictMock(Pipe.class);
Pipe notDeletedPipe = createStrictMock(Pipe.class);
GremlinPipeline rootPipeline = createStrictMock(GremlinPipeline.class);
GremlinPipeline queryPipeline = createStrictMock(GremlinPipeline.class);
GremlinPipeline expressionPipeline = createStrictMock(GremlinPipeline.class);
GremlinPipeline notDeletedPipeline = createStrictMock(GremlinPipeline.class);
Vertex vertex1 = createStrictMock(Vertex.class);
VertexWrapper vertex1Wrapper = createStrictMock(VertexWrapper.class);
Capture<Long> modifiedTimestampCapture = newCapture();
List<Vertex> results = new ArrayList<>();
results.add(vertex1);
Map<String, Object> vertex1PropertyMap = new HashMap<>();
vertex1PropertyMap.put("prop1", "prop1.value1");
vertex1PropertyMap.put("prop2", "prop2.value1");
Map<String, Object> filteredVertex1PropertyMap = new HashMap<>();
filteredVertex1PropertyMap.put("prop1", "prop1.value1");
Map<String, Object> updateProperties = new HashMap<>();
updateProperties.put("prop3", "newValue");
// mock expectations
expect(initialPipeline.add(queryPipe)).andReturn(queryPipeline);
expect(initialPipeline.add(notDeletedPipe)).andReturn(notDeletedPipeline);
expect(initialPipeline.as("root")).andReturn(rootPipeline);
expect(expression.asPipe()).andReturn(expressionPipe);
expect(rootPipeline.add(expressionPipe)).andReturn(expressionPipeline);
expect(expressionPipeline.back("root")).andReturn(rootPipeline);
expect(rootPipeline.toList()).andReturn(results);
graph.commit();
vertex1Wrapper.setProperty("prop3", "newValue");
vertex1Wrapper.setProperty(eq(Constants.MODIFICATION_TIMESTAMP_PROPERTY_KEY), capture(modifiedTimestampCapture));
expect(vertex1Wrapper.getPropertyMap()).andReturn(vertex1PropertyMap);
expect(resourceDefinition.filterProperties(request, vertex1PropertyMap)).andReturn(filteredVertex1PropertyMap);
expect(resourceDefinition.resolveHref(filteredVertex1PropertyMap)).andReturn("/foo/bar");
expect(request.getCardinality()).andReturn(Request.Cardinality.COLLECTION);
replay(graph, expression, resourceDefinition, request, initialPipeline, queryPipe, expressionPipe, notDeletedPipe, rootPipeline, queryPipeline, expressionPipeline, notDeletedPipeline, vertex1, vertex1Wrapper);
// end mock expectations
AtlasEntityQuery query = new TestAtlasEntityQuery(expression, resourceDefinition, request, initialPipeline, queryPipe, notDeletedPipe, graph, vertex1Wrapper);
long startTime = System.currentTimeMillis();
// invoke method being tested
Collection<Map<String, Object>> queryResults = query.execute(updateProperties);
long endTime = System.currentTimeMillis();
assertEquals(queryResults.size(), 1);
Map<String, Object> queryResultMap = queryResults.iterator().next();
assertEquals(queryResultMap.size(), 2);
assertEquals(queryResultMap.get("prop1"), "prop1.value1");
assertEquals(queryResultMap.get("href"), "/foo/bar");
long modifiedTimestamp = modifiedTimestampCapture.getValue();
assertTrue(modifiedTimestamp >= startTime && modifiedTimestamp <= endTime);
verify(graph, expression, resourceDefinition, request, initialPipeline, queryPipe, expressionPipe, notDeletedPipe, rootPipeline, queryPipeline, expressionPipeline, notDeletedPipeline, vertex1, vertex1Wrapper);
}
Aggregations