/** * Get template configuration if exists, else return null. * * @return Map<String, Object> */ public Map<String, Object> getTemplateConfiguration() { final List<Map<String, Object>> templateConfigurations = graph.traversal().V().has(PROPERTY_TEMPLATE, true).valueMap().toList(); if (templateConfigurations.size() == 0) return null; if (templateConfigurations.size() > 1) { log.warn("Your configuration management graph is an a bad state. Please " + "ensure you have just one template configuration. The behavior " + "of the class' APIs are henceforth unpredictable until this is fixed."); } templateConfigurations.get(0).remove(PROPERTY_TEMPLATE); return deserializeVertexProperties(templateConfigurations.get(0)); }
private void updateVertexWithProperties(String propertyKey, Object propertyValue, Map<Object, Object> map) { if (graph.traversal().V().has(propertyKey, propertyValue).hasNext()) { final Vertex v = graph.traversal().V().has(propertyKey, propertyValue).next(); map.forEach((key, value) -> v.property((String) key, value)); graph.tx().commit(); } }
@Test public void testReadGraphOfTheGods() { GraphOfTheGodsFactory.load(graph, null, true); assertEquals(12L, (long) graph.traversal().V().count().next()); Graph g = GraphFactory.open("target/test-classes/cassandra-read.properties"); GraphTraversalSource t = g.traversal(GraphTraversalSource.computer(SparkGraphComputer.class)); assertEquals(12L, (long) t.V().count().next()); }
@Test public void testQuerySingleIndexedPropertyByEqual() { HugeGraph graph = graph(); init5Computers(); List<Vertex> vertexes = graph.traversal().V() .has("band", "lenovo").toList(); Assert.assertEquals(2, vertexes.size()); vertexes = graph.traversal().V().has("band", "apple").toList(); Assert.assertEquals(1, vertexes.size()); }
@Test public void testQueryByPrimaryValues() { HugeGraph graph = graph(); init10Vertices(); // Query vertex by primary-values List<Vertex> vertexes = graph.traversal().V() .hasLabel("author").has("id", 1).toList(); Assert.assertEquals(1, vertexes.size()); assertContains(vertexes, T.label, "author", "id", 1, "name", "James Gosling", "age", 62, "lived", "Canadian"); }
@SuppressWarnings("SameReturnValue") @Benchmark public long withinWithIn() { this.sqlgGraph.configuration().setProperty("bulk.within.count", this.count); List<Vertex> vertices = this.gt.V().hasLabel("Person").has("uid", P.within(this.smallUidSet)).toList(); assertEquals(this.count, vertices.size()); return 1000000; }
@Test @LoadGraphWith(MODERN) public void shouldHavePropertyForEachRemainingBehaviorEvenWithStrategyRewrite() { final GraphTraversal<Vertex, Map<Object, Long>> traversal = g.V().out().groupCount(); traversal.forEachRemaining(Map.class, map -> assertTrue(map instanceof Map)); }
assertNumStep(numV / 5, 1, gts.V(sv[0]).outE("knows").has("weight", 1), TitanVertexStep.class); assertNumStep(numV, 1, gts.V(sv[0]).outE("knows"), TitanVertexStep.class); assertNumStep(numV, 1, gts.V(sv[0]).out("knows"), TitanVertexStep.class); assertNumStep(10, 1, gts.V(sv[0]).local(__.outE("knows").limit(10)), TitanVertexStep.class); assertNumStep(10, 1, gts.V(sv[0]).local(__.outE("knows").range(10, 20)), LocalStep.class); assertNumStep(numV, 2, gts.V(sv[0]).outE("knows").order().by("weight", decr), TitanVertexStep.class, OrderGlobalStep.class); assertNumStep(10, 1, gts.V(sv[0]).local(__.outE("knows").order().by("weight", decr).limit(10)), TitanVertexStep.class); assertNumStep(numV / 5, 2, gts.V(sv[0]).outE("knows").has("weight", 1).order().by("weight", incr), TitanVertexStep.class, OrderGlobalStep.class); assertNumStep(10, 1, gts.V(sv[0]).local(__.outE("knows").has("weight", 1).order().by("weight", incr).limit(10)), TitanVertexStep.class); assertNumStep(5, 1, gts.V(sv[0]).local(__.outE("knows").has("weight", 1).has("weight", 1).order().by("weight", incr).range(10, 15)), LocalStep.class); assertNumStep(1, 1, gts.V(sv[0]).outE("knows").filter(__.inV().is(vs[50])), TitanVertexStep.class); assertNumStep(1, 1, gts.V(sv[0]).outE("knows").filter(__.otherV().is(vs[50])), TitanVertexStep.class); assertNumStep(1, 1, gts.V(sv[0]).bothE("knows").filter(__.otherV().is(vs[50])), TitanVertexStep.class); assertNumStep(1, 2, gts.V(sv[0]).bothE("knows").filter(__.inV().is(vs[50])), TitanVertexStep.class, TraversalFilterStep.class); assertNumStep(numV / 5, 1, gts.V(sv[0]).properties("names").has("weight", 1), TitanPropertiesStep.class); assertNumStep(numV, 1, gts.V(sv[0]).properties("names"), TitanPropertiesStep.class); assertNumStep(10, 1, gts.V(sv[0]).local(__.properties("names").order().by("weight", decr).limit(10)), TitanPropertiesStep.class); assertNumStep(numV, 2, gts.V(sv[0]).outE("knows").values("weight"), TitanVertexStep.class, TitanPropertiesStep.class); assertNumStep(1, 1, gts.V().has("id", numV / 5), TitanGraphStep.class); assertNumStep(1, 1, gts.V().has("id", numV / 5).has("weight", (numV / 5) % 5), TitanGraphStep.class); assertNumStep(numV / 5, 1, gts.V().has("weight", 1), TitanGraphStep.class); assertNumStep(10, 1, gts.V().has("weight", 1).range(0, 10), TitanGraphStep.class); assertNumStep(superV, 1, gts.V().has("id", sid), TitanGraphStep.class); assertNumStep(1, 1, gts.V().has("id", numV / 5).as("x"), TitanGraphStep.class); assertNumStep(1, 1, gts.V().has("id", numV / 5).has("weight", (numV / 5) % 5).as("x"), TitanGraphStep.class);
@Test public void testTinkerPopCardinality() { PropertyKey id = mgmt.makePropertyKey("id").cardinality(Cardinality.SINGLE).dataType(Integer.class).make(); PropertyKey name = mgmt.makePropertyKey("name").cardinality(Cardinality.SINGLE).dataType(String.class).make(); PropertyKey names = mgmt.makePropertyKey("names").cardinality(Cardinality.LIST).dataType(String.class).make(); mgmt.buildIndex("byId", Vertex.class).addKey(id).buildCompositeIndex(); finishSchema(); GraphTraversalSource gts; Vertex v; v = graph.addVertex("id", 1); v.property(single, "name", "t1"); graph.addVertex("id", 2, "names", "n1", "names", "n2"); graph.tx().commit(); gts = graph.traversal(); v = gts.V().has("id", 1).next(); v.property(single, "name", "t2"); v = gts.V().has("id", 1).next(); v.property(single, "name", "t3"); assertCount(1, gts.V(v).properties("name")); assertCount(2, gts.V().has("id", 2).properties("names")); assertCount(2, gts.V().hasLabel("vertex")); }
@Test public void testQueryComplexIndexedPropertyByNotEqualOnePrefix() { HugeGraph graph = graph(); init5Computers(); List<Vertex> vertexes = graph.traversal().V() .has("cpu", "2.8GHz").toList(); Assert.assertEquals(0, vertexes.size()); vertexes = graph.traversal().V().has("cpu", "4.8GHz").toList(); Assert.assertEquals(0, vertexes.size()); }
@Test public void testQueryByLabelAndKeyName() { HugeGraph graph = graph(); init10Vertices(); // Query by vertex label and key-name List<Vertex> vertexes = graph.traversal().V().hasLabel("language") .has("dynamic").toList(); Assert.assertEquals(1, vertexes.size()); assertContains(vertexes, T.label, "language", "name", "python", "dynamic", true); }
@SuppressWarnings("SameReturnValue") @Benchmark public long withinWithJoin() { this.sqlgGraph.configuration().setProperty("bulk.within.count", this.count - 1); List<Vertex> vertices = this.gt.V().hasLabel("Person").has("uid", P.within(this.smallUidSet)).toList(); assertEquals(this.count, vertices.size()); return 1000000; }
/** * Get Configuration according to supplied graphName mapped to a specific * {@link Graph}; if does not exist, return null. * * @return Map<String, Object> */ public Map<String, Object> getConfiguration(final String configName) { final List<Map<String, Object>> graphConfiguration = graph.traversal().V().has(PROPERTY_GRAPH_NAME, configName).valueMap().toList(); if (graphConfiguration.isEmpty()) return null; else if (graphConfiguration.size() > 1) { // this case shouldn't happen because our index has a unique constraint log.warn("Your configuration management graph is an a bad state. Please " + "ensure you have just one configuration per graph. The behavior " + "of the class' APIs are henceforth unpredictable until this is fixed."); } return deserializeVertexProperties(graphConfiguration.get(0)); }
@Test @LoadGraphWith(MODERN) public void shouldSucceedWithProperTraverserRequirements() throws Exception { final VertexProgramQ vp = VertexProgramQ.build().property("pl").create(); final Map<String, List<Integer>> expected = new HashMap<>(); expected.put("vadas", Collections.singletonList(2)); expected.put("lop", Arrays.asList(2, 2, 2, 3)); expected.put("josh", Collections.singletonList(2)); expected.put("ripple", Arrays.asList(2, 3)); try { g.V().repeat(__.out()).emit().program(vp).dedup() .valueMap("name", "pl").forEachRemaining((Map<Object, Object> map) -> { final String name = (String) ((List) map.get("name")).get(0); final List<Integer> pathLengths = (List<Integer>) map.get("pl"); assertTrue(expected.containsKey(name)); final List<Integer> expectedPathLengths = expected.remove(name); assertTrue(expectedPathLengths.containsAll(pathLengths)); assertTrue(pathLengths.containsAll(expectedPathLengths)); }); assertTrue(expected.isEmpty()); } catch (VerificationException ex) { assumeNoException(ex); } }
assertNumStep(numV / 5, 1, gts.V(sv[0]).outE("knows").has("weight", 1), JanusGraphVertexStep.class); assertNumStep(numV, 1, gts.V(sv[0]).outE("knows"), JanusGraphVertexStep.class); assertNumStep(numV, 1, gts.V(sv[0]).out("knows"), JanusGraphVertexStep.class); assertNumStep(10, 1, gts.V(sv[0]).local(__.outE("knows").limit(10)), JanusGraphVertexStep.class); assertNumStep(10, 1, gts.V(sv[0]).local(__.outE("knows").range(10, 20)), LocalStep.class); assertNumStep(numV, 2, gts.V(sv[0]).outE("knows").order().by("weight", decr), JanusGraphVertexStep.class, OrderGlobalStep.class); assertNumStep(10, 0, gts.V(sv[0]).local(__.outE("knows").order().by("weight", decr).limit(10)), LocalStep.class); assertNumStep(numV / 5, 2, gts.V(sv[0]).outE("knows").has("weight", 1).order().by("weight", incr), JanusGraphVertexStep.class, OrderGlobalStep.class); assertNumStep(10, 0, gts.V(sv[0]).local(__.outE("knows").has("weight", 1).order().by("weight", incr).limit(10)), LocalStep.class); assertNumStep(5, 1, gts.V(sv[0]).local(__.outE("knows").has("weight", 1).has("weight", 1).order().by("weight", incr).range(10, 15)), LocalStep.class); assertNumStep(1, 1, gts.V(sv[0]).outE("knows").filter(__.inV().is(vs[50])), JanusGraphVertexStep.class); assertNumStep(1, 1, gts.V(sv[0]).outE("knows").filter(__.otherV().is(vs[50])), JanusGraphVertexStep.class); assertNumStep(1, 1, gts.V(sv[0]).bothE("knows").filter(__.otherV().is(vs[50])), JanusGraphVertexStep.class); assertNumStep(1, 2, gts.V(sv[0]).bothE("knows").filter(__.inV().is(vs[50])), JanusGraphVertexStep.class, TraversalFilterStep.class); assertNumStep(numV / 5, 1, gts.V(sv[0]).properties("names").has("weight", 1), JanusGraphPropertiesStep.class); assertNumStep(numV, 1, gts.V(sv[0]).properties("names"), JanusGraphPropertiesStep.class); assertNumStep(10, 0, gts.V(sv[0]).local(__.properties("names").order().by("weight", decr).limit(10)), LocalStep.class); assertNumStep(numV, 2, gts.V(sv[0]).outE("knows").values("weight"), JanusGraphVertexStep.class, JanusGraphPropertiesStep.class); assertNumStep(1, 1, gts.V().has("id", numV / 5), JanusGraphStep.class); assertNumStep(1, 1, gts.V().has("id", numV / 5).has("weight", (numV / 5) % 5), JanusGraphStep.class); assertNumStep(numV / 5, 1, gts.V().has("weight", 1), JanusGraphStep.class); assertNumStep(10, 1, gts.V().has("weight", 1).range(0, 10), JanusGraphStep.class); assertNumStep(superV, 1, gts.V().has("id", sid), JanusGraphStep.class);
@Test public void testReadWideVertexWithManyProperties() { int numProps = 1 << 16; long numV = 1; mgmt.makePropertyKey("p").cardinality(Cardinality.LIST).dataType(Integer.class).make(); mgmt.commit(); finishSchema(); for (int j = 0; j < numV; j++) { Vertex v = graph.addVertex(); for (int i = 0; i < numProps; i++) { v.property("p", i); } } graph.tx().commit(); assertEquals(numV, (long) graph.traversal().V().count().next()); Map<String, Object> propertiesOnVertex = graph.traversal().V().valueMap().next(); List<?> valuesOnP = (List)propertiesOnVertex.values().iterator().next(); assertEquals(numProps, valuesOnP.size()); Graph g = GraphFactory.open("target/test-classes/cassandra-read.properties"); GraphTraversalSource t = g.traversal(GraphTraversalSource.computer(SparkGraphComputer.class)); assertEquals(numV, (long) t.V().count().next()); propertiesOnVertex = t.V().valueMap().next(); valuesOnP = (List)propertiesOnVertex.values().iterator().next(); assertEquals(numProps, valuesOnP.size()); }