com.thinkaurelius.titan.core.TitanVertex Java Examples
The following examples show how to use
com.thinkaurelius.titan.core.TitanVertex.
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: Titan1IndexQuery.java From incubator-atlas with Apache License 2.0 | 6 votes |
@Override public Iterator<Result<Titan1Vertex, Titan1Edge>> vertices(int offset, int limit) { Preconditions.checkArgument(offset >=0, "Index offset should be greater than or equals to 0"); Preconditions.checkArgument(limit >=0, "Index limit should be greater than or equals to 0"); Iterator<TitanIndexQuery.Result<TitanVertex>> results = query .offset(offset) .limit(limit) .vertices().iterator(); Function<TitanIndexQuery.Result<TitanVertex>, Result<Titan1Vertex, Titan1Edge>> function = new Function<TitanIndexQuery.Result<TitanVertex>, Result<Titan1Vertex, Titan1Edge>>() { @Override public Result<Titan1Vertex, Titan1Edge> apply(TitanIndexQuery.Result<TitanVertex> source) { return new ResultImpl(source); } }; return Iterators.transform(results, function); }
Example #2
Source File: PropertyPlacementStrategy.java From titan1withtp3.1 with Apache License 2.0 | 6 votes |
private int getPartitionIDbyKey(TitanVertex vertex) { Preconditions.checkState(idManager!=null && key!=null,"PropertyPlacementStrategy has not been initialized correctly"); assert idManager.getPartitionBound()<=Integer.MAX_VALUE; int partitionBound = (int)idManager.getPartitionBound(); TitanVertexProperty p = (TitanVertexProperty)Iterables.getFirst(vertex.query().keys(key).properties(),null); if (p==null) return -1; int hashPid = Math.abs(p.value().hashCode())%partitionBound; assert hashPid>=0 && hashPid<partitionBound; if (isExhaustedPartition(hashPid)) { //We keep trying consecutive partition ids until we find a non-exhausted one int newPid=hashPid; do { newPid = (newPid+1)%partitionBound; if (newPid==hashPid) //We have gone full circle - no more ids to try throw new IDPoolExhaustedException("Could not find non-exhausted partition"); } while (isExhaustedPartition(newPid)); return newPid; } else return hashPid; }
Example #3
Source File: TitanIndexTest.java From titan1withtp3.1 with Apache License 2.0 | 6 votes |
private void testInstant(Instant firstTimestamp, Instant secondTimestamp, TitanVertex v1, TitanVertex v2) { assertEquals(v1, getOnlyVertex(graph.query().has("instant", Cmp.EQUAL, firstTimestamp))); assertEquals(v2, getOnlyVertex(graph.query().has("instant", Cmp.GREATER_THAN, firstTimestamp))); assertEquals(Sets.newHashSet(v1, v2), Sets.newHashSet(graph.query().has("instant", Cmp.GREATER_THAN_EQUAL, firstTimestamp).vertices())); assertEquals(v1, getOnlyVertex(graph.query().has("instant", Cmp.LESS_THAN, secondTimestamp))); assertEquals(Sets.newHashSet(v1, v2), Sets.newHashSet(graph.query().has("instant", Cmp.LESS_THAN_EQUAL, secondTimestamp).vertices())); assertEquals(v2, getOnlyVertex(graph.query().has("instant", Cmp.NOT_EQUAL, firstTimestamp))); clopen();//Flush the index assertEquals(v1, getOnlyVertex(graph.query().has("instant", Cmp.EQUAL, firstTimestamp))); assertEquals(v2, getOnlyVertex(graph.query().has("instant", Cmp.GREATER_THAN, firstTimestamp))); assertEquals(Sets.newHashSet(v1, v2), Sets.newHashSet(graph.query().has("instant", Cmp.GREATER_THAN_EQUAL, firstTimestamp).vertices())); assertEquals(v1, getOnlyVertex(graph.query().has("instant", Cmp.LESS_THAN, secondTimestamp))); assertEquals(Sets.newHashSet(v1, v2), Sets.newHashSet(graph.query().has("instant", Cmp.LESS_THAN_EQUAL, secondTimestamp).vertices())); assertEquals(v2, getOnlyVertex(graph.query().has("instant", Cmp.NOT_EQUAL, firstTimestamp))); }
Example #4
Source File: VertexLongList.java From titan1withtp3.1 with Apache License 2.0 | 6 votes |
@Override public Iterator<TitanVertex> iterator() { return new Iterator<TitanVertex>() { private int pos = -1; @Override public boolean hasNext() { return (pos + 1) < size(); } @Override public TitanVertex next() { if (!hasNext()) throw new NoSuchElementException(); pos++; return get(pos); } @Override public void remove() { throw new UnsupportedOperationException("Vertices cannot be removed from neighborhood list"); } }; }
Example #5
Source File: EdgeSerializerTest.java From titan1withtp3.1 with Apache License 2.0 | 6 votes |
@Test public void testValueOrdering() { StandardTitanGraph graph = (StandardTitanGraph) StorageSetup.getInMemoryGraph(); TitanManagement mgmt = graph.openManagement(); EdgeLabel father = mgmt.makeEdgeLabel("father").multiplicity(Multiplicity.MANY2ONE).make(); for (int i=1;i<=5;i++) mgmt.makePropertyKey("key" + i).dataType(Integer.class).make(); mgmt.commit(); TitanVertex v1 = graph.addVertex(), v2 = graph.addVertex(); TitanEdge e1 = v1.addEdge("father",v2); for (int i=1;i<=5;i++) e1.property("key"+i,i); graph.tx().commit(); e1.remove(); graph.tx().commit(); }
Example #6
Source File: ElementUtils.java From titan1withtp3.1 with Apache License 2.0 | 6 votes |
public static long getVertexId(Object id) { if (null == id) return 0; if (id instanceof TitanVertex) //allows vertices to be "re-attached" to the current transaction return ((TitanVertex) id).longId(); if (id instanceof Long) return (Long) id; if (id instanceof Number) return ((Number) id).longValue(); try { // handles the case of a user passing a "detached" Vertex (DetachedVertex, StarVertex, etc). if (id instanceof Vertex) return Long.parseLong(((Vertex) id).id().toString()); else return Long.valueOf(id.toString()).longValue(); } catch (NumberFormatException e) { return 0; } }
Example #7
Source File: VertexMapJob.java From titan1withtp3.1 with Apache License 2.0 | 6 votes |
@Override public void process(TitanVertex vertex, ScanMetrics metrics) { PreloadedVertex v = (PreloadedVertex) vertex; if (vertexMemory != null) { VertexMemoryHandler vh = new VertexMemoryHandler(vertexMemory, v); v.setPropertyMixing(vh); } v.setAccessCheck(MAPREDUCE_CHECK); if (idManager.isPartitionedVertex(v.longId()) && !idManager.isCanonicalVertexId(v.longId())) { return; //Only consider the canonical partition vertex representative } else { for (Map.Entry<MapReduce, FulgoraMapEmitter> mapJob : mapJobs.entrySet()) { MapReduce job = mapJob.getKey(); try { job.map(v, mapJob.getValue()); metrics.incrementCustom(MAP_JOB_SUCCESS); } catch (Throwable ex) { log.error("Encountered exception executing map job [" + job + "] on vertex [" + vertex + "]:", ex); metrics.incrementCustom(MAP_JOB_FAILURE); } } } }
Example #8
Source File: PartitionedVertexProgramExecutor.java From titan1withtp3.1 with Apache License 2.0 | 6 votes |
@Override public void run() { try { TitanVertex vertex = tx.getInternalVertex(vertexId); Preconditions.checkArgument(vertex instanceof PreloadedVertex, "The bounding transaction is not configured correctly"); PreloadedVertex v = (PreloadedVertex)vertex; v.setAccessCheck(PreloadedVertex.OPENSTAR_CHECK); v.addToQueryCache(VertexProgramScanJob.SYSTEM_PROPS_QUERY,preloaded); VertexMemoryHandler.Partition<M> vh = new VertexMemoryHandler.Partition<M>(vertexMemory,v); v.setPropertyMixing(vh); vertexProgram.execute(v,vh,memory); metrics.incrementCustom(PARTITION_VERTEX_POSTSUCCESS); } catch (Throwable e) { metrics.incrementCustom(PARTITION_VERTEX_POSTFAIL); log.error("Error post-processing partition vertex: " + vertexId,e); } }
Example #9
Source File: TitanIndexTest.java From titan1withtp3.1 with Apache License 2.0 | 6 votes |
/** * Tests indexing using _all virtual field */ @Test public void testWidcardQuery() { if (supportsWildcardQuery()) { PropertyKey p1 = makeKey("p1", String.class); PropertyKey p2 = makeKey("p2", String.class); mgmt.buildIndex("mixedIndex", Vertex.class).addKey(p1).addKey(p2).buildMixedIndex(INDEX); finishSchema(); clopen(); TitanVertex v1 = graph.addVertex(); v1.property("p1", "test1"); v1.property("p2", "test2"); clopen();//Flush the index assertEquals(v1, graph.indexQuery("mixedIndex", "v.*:\"test1\"").vertices().iterator().next().getElement()); assertEquals(v1, graph.indexQuery("mixedIndex", "v.*:\"test2\"").vertices().iterator().next().getElement()); } }
Example #10
Source File: TitanIndexTest.java From titan1withtp3.1 with Apache License 2.0 | 6 votes |
@Test public void testIndexQueryWithScore() throws InterruptedException { PropertyKey textKey = mgmt.makePropertyKey("text").dataType(String.class).make(); mgmt.buildIndex("store1", Vertex.class).addKey(textKey).buildMixedIndex(INDEX); mgmt.commit(); TitanVertex v1 = tx.addVertex(); TitanVertex v2 = tx.addVertex(); TitanVertex v3 = tx.addVertex(); v1.property("text", "Hello Hello Hello Hello Hello Hello Hello Hello"); v2.property("text", "Hello abab abab fsdfsd sfdfsd sdffs fsdsdf fdf fsdfsd aera fsad abab abab fsdfsd sfdf"); v3.property("text", "Hello"); tx.commit(); Thread.sleep(5000); Set<Double> scores = new HashSet<Double>(); for (TitanIndexQuery.Result<TitanVertex> r : graph.indexQuery("store1", "v.text:(Hello)").vertices()) { scores.add(r.getScore()); } Assert.assertEquals(3, scores.size()); }
Example #11
Source File: TitanIndexTest.java From titan1withtp3.1 with Apache License 2.0 | 6 votes |
@Test // this tests a case when there as AND with a single CONTAINS condition inside AND(name:(was here)) // which (in case of Solr) spans multiple conditions such as AND(AND(name:was, name:here)) // so we need to make sure that we don't apply AND twice. public void testContainsWithMultipleValues() throws Exception { PropertyKey name = makeKey("name", String.class); mgmt.buildIndex("store1", Vertex.class).addKey(name).buildMixedIndex(INDEX); mgmt.commit(); TitanVertex v1 = tx.addVertex(); v1.property("name", "hercules was here"); tx.commit(); Thread.sleep(2000); TitanVertex r = Iterables.<TitanVertex>get(graph.query().has("name", Text.CONTAINS, "hercules here").vertices(), 0); Assert.assertEquals(r.property("name").value(), "hercules was here"); }
Example #12
Source File: ManagementSystem.java From titan1withtp3.1 with Apache License 2.0 | 6 votes |
@Override public <T extends RelationType> Iterable<T> getRelationTypes(Class<T> clazz) { Preconditions.checkNotNull(clazz); Iterable<? extends TitanVertex> types = null; if (PropertyKey.class.equals(clazz)) { types = QueryUtil.getVertices(transaction, BaseKey.SchemaCategory, TitanSchemaCategory.PROPERTYKEY); } else if (EdgeLabel.class.equals(clazz)) { types = QueryUtil.getVertices(transaction, BaseKey.SchemaCategory, TitanSchemaCategory.EDGELABEL); } else if (RelationType.class.equals(clazz)) { types = Iterables.concat(getRelationTypes(EdgeLabel.class), getRelationTypes(PropertyKey.class)); } else throw new IllegalArgumentException("Unknown type class: " + clazz); return Iterables.filter(Iterables.filter(types, clazz), new Predicate<T>() { @Override public boolean apply(@Nullable T t) { //Filter out all relation type indexes return ((InternalRelationType) t).getBaseType() == null; } }); }
Example #13
Source File: VertexArrayList.java From titan1withtp3.1 with Apache License 2.0 | 5 votes |
/** * Utility method used to convert the list of vertices into a list of vertex ids (assuming all vertices have ids) * * @param vertices * @return */ private static final LongArrayList toLongList(List<TitanVertex> vertices) { LongArrayList result = new LongArrayList(vertices.size()); for (TitanVertex n : vertices) { result.add(n.longId()); } return result; }
Example #14
Source File: TitanIndexTest.java From titan1withtp3.1 with Apache License 2.0 | 5 votes |
/** * Tests indexing boolean */ @Test public void testBooleanIndexing() { PropertyKey name = makeKey("visible", Boolean.class); mgmt.buildIndex("booleanIndex", Vertex.class). addKey(name).buildMixedIndex(INDEX); finishSchema(); clopen(); TitanVertex v1 = graph.addVertex(); v1.property("visible", true); TitanVertex v2 = graph.addVertex(); v2.property("visible", false); assertCount(2, graph.vertices()); assertEquals(v1, getOnlyVertex(graph.query().has("visible", true))); assertEquals(v2, getOnlyVertex(graph.query().has("visible", false))); assertEquals(v2, getOnlyVertex(graph.query().has("visible", Cmp.NOT_EQUAL, true))); assertEquals(v1, getOnlyVertex(graph.query().has("visible", Cmp.NOT_EQUAL, false))); clopen();//Flush the index assertCount(2, graph.vertices()); assertEquals(v1, getOnlyVertex(graph.query().has("visible", true))); assertEquals(v2, getOnlyVertex(graph.query().has("visible", false))); assertEquals(v2, getOnlyVertex(graph.query().has("visible", Cmp.NOT_EQUAL, true))); assertEquals(v1, getOnlyVertex(graph.query().has("visible", Cmp.NOT_EQUAL, false))); }
Example #15
Source File: TitanIndexTest.java From titan1withtp3.1 with Apache License 2.0 | 5 votes |
/** * Tests indexing dates */ @Test public void testDateIndexing() { PropertyKey name = makeKey("date", Date.class); mgmt.buildIndex("dateIndex", Vertex.class). addKey(name).buildMixedIndex(INDEX); finishSchema(); clopen(); TitanVertex v1 = graph.addVertex(); v1.property("date", new Date(1)); TitanVertex v2 = graph.addVertex(); v2.property("date", new Date(2000)); assertEquals(v1, getOnlyVertex(graph.query().has("date", Cmp.EQUAL, new Date(1)))); assertEquals(v2, getOnlyVertex(graph.query().has("date", Cmp.GREATER_THAN, new Date(1)))); assertEquals(Sets.newHashSet(v1, v2), Sets.newHashSet(graph.query().has("date", Cmp.GREATER_THAN_EQUAL, new Date(1)).vertices())); assertEquals(v1, getOnlyVertex(graph.query().has("date", Cmp.LESS_THAN, new Date(2000)))); assertEquals(Sets.newHashSet(v1, v2), Sets.newHashSet(graph.query().has("date", Cmp.LESS_THAN_EQUAL, new Date(2000)).vertices())); assertEquals(v2, getOnlyVertex(graph.query().has("date", Cmp.NOT_EQUAL, new Date(1)))); clopen();//Flush the index assertEquals(v1, getOnlyVertex(graph.query().has("date", Cmp.EQUAL, new Date(1)))); assertEquals(v2, getOnlyVertex(graph.query().has("date", Cmp.GREATER_THAN, new Date(1)))); assertEquals(Sets.newHashSet(v1, v2), Sets.newHashSet(graph.query().has("date", Cmp.GREATER_THAN_EQUAL, new Date(1)).vertices())); assertEquals(v1, getOnlyVertex(graph.query().has("date", Cmp.LESS_THAN, new Date(2000)))); assertEquals(Sets.newHashSet(v1, v2), Sets.newHashSet(graph.query().has("date", Cmp.LESS_THAN_EQUAL, new Date(2000)).vertices())); assertEquals(v2, getOnlyVertex(graph.query().has("date", Cmp.NOT_EQUAL, new Date(1)))); }
Example #16
Source File: TitanIndexTest.java From titan1withtp3.1 with Apache License 2.0 | 5 votes |
private void setupChainGraph(int numV, String[] strs, boolean sameNameMapping) { clopen(option(INDEX_NAME_MAPPING, INDEX), sameNameMapping); TitanGraphIndex vindex = getExternalIndex(Vertex.class, INDEX); TitanGraphIndex eindex = getExternalIndex(Edge.class, INDEX); TitanGraphIndex pindex = getExternalIndex(TitanVertexProperty.class, INDEX); PropertyKey name = makeKey("name", String.class); mgmt.addIndexKey(vindex, name, getStringMapping()); mgmt.addIndexKey(eindex, name, getStringMapping()); mgmt.addIndexKey(pindex, name, getStringMapping(), Parameter.of("mapped-name", "xstr")); PropertyKey text = makeKey("text", String.class); mgmt.addIndexKey(vindex, text, getTextMapping(), Parameter.of("mapped-name", "xtext")); mgmt.addIndexKey(eindex, text, getTextMapping()); mgmt.addIndexKey(pindex, text, getTextMapping()); mgmt.makeEdgeLabel("knows").signature(name).make(); mgmt.makePropertyKey("uid").dataType(String.class).signature(text).make(); finishSchema(); TitanVertex previous = null; for (int i = 0; i < numV; i++) { TitanVertex v = graph.addVertex("name", strs[i % strs.length], "text", strs[i % strs.length]); Edge e = v.addEdge("knows", previous == null ? v : previous, "name", strs[i % strs.length], "text", strs[i % strs.length]); VertexProperty p = v.property("uid", "v" + i, "name", strs[i % strs.length], "text", strs[i % strs.length]); previous = v; } }
Example #17
Source File: TitanIndexTest.java From titan1withtp3.1 with Apache License 2.0 | 5 votes |
private void addVertex(int time, String text, double height, String[] phones) { newTx(); TitanVertex v = tx.addVertex("text", text, "time", time, "height", height); for (String phone : phones) { v.property("phone", phone); } newTx(); }
Example #18
Source File: TitanIndexTest.java From titan1withtp3.1 with Apache License 2.0 | 5 votes |
/** * Tests indexing boolean */ @Test public void testUUIDIndexing() { PropertyKey name = makeKey("uid", UUID.class); mgmt.buildIndex("uuidIndex", Vertex.class). addKey(name).buildMixedIndex(INDEX); finishSchema(); clopen(); UUID uid1 = UUID.randomUUID(); UUID uid2 = UUID.randomUUID(); TitanVertex v1 = graph.addVertex(); v1.property("uid", uid1); TitanVertex v2 = graph.addVertex(); v2.property("uid", uid2); assertCount(2, graph.query().vertices()); assertEquals(v1, getOnlyVertex(graph.query().has("uid", uid1))); assertEquals(v2, getOnlyVertex(graph.query().has("uid", uid2))); assertEquals(v2, getOnlyVertex(graph.query().has("uid", Cmp.NOT_EQUAL, uid1))); assertEquals(v1, getOnlyVertex(graph.query().has("uid", Cmp.NOT_EQUAL, uid2))); clopen();//Flush the index assertCount(2, graph.query().vertices()); assertEquals(v1, getOnlyVertex(graph.query().has("uid", uid1))); assertEquals(v2, getOnlyVertex(graph.query().has("uid", uid2))); assertEquals(v2, getOnlyVertex(graph.query().has("uid", Cmp.NOT_EQUAL, uid1))); assertEquals(v1, getOnlyVertex(graph.query().has("uid", Cmp.NOT_EQUAL, uid2))); }
Example #19
Source File: CassandraScanJobIT.java From titan1withtp3.1 with Apache License 2.0 | 5 votes |
@Test public void testPartitionedVertexFilteredScan() throws Exception { tearDown(); clearGraph(getConfiguration()); WriteConfiguration partConf = getConfiguration(); open(partConf); mgmt.makeVertexLabel("part").partition().make(); finishSchema(); TitanVertex supernode = graph.addVertex("part"); for (int i = 0; i < 128; i++) { TitanVertex v = graph.addVertex("part"); v.addEdge("default", supernode); if (0 < i && 0 == i % 4) graph.tx().commit(); } graph.tx().commit(); org.apache.hadoop.conf.Configuration c = new org.apache.hadoop.conf.Configuration(); c.set(ConfigElement.getPath(TitanHadoopConfiguration.GRAPH_CONFIG_KEYS, true) + "." + "storage.cassandra.keyspace", getClass().getSimpleName()); c.set(ConfigElement.getPath(TitanHadoopConfiguration.GRAPH_CONFIG_KEYS, true) + "." + "storage.backend", "cassandrathrift"); c.set(ConfigElement.getPath(TitanHadoopConfiguration.FILTER_PARTITIONED_VERTICES), "true"); c.set("cassandra.input.partitioner.class", "org.apache.cassandra.dht.Murmur3Partitioner"); Job job = getVertexJobWithDefaultMapper(c); // Should succeed assertTrue(job.waitForCompletion(true)); }
Example #20
Source File: CassandraScanJobIT.java From titan1withtp3.1 with Apache License 2.0 | 5 votes |
@Test public void testPartitionedVertexScan() throws Exception { tearDown(); clearGraph(getConfiguration()); WriteConfiguration partConf = getConfiguration(); open(partConf); mgmt.makeVertexLabel("part").partition().make(); finishSchema(); TitanVertex supernode = graph.addVertex("part"); for (int i = 0; i < 128; i++) { TitanVertex v = graph.addVertex("part"); v.addEdge("default", supernode); if (0 < i && 0 == i % 4) graph.tx().commit(); } graph.tx().commit(); org.apache.hadoop.conf.Configuration c = new org.apache.hadoop.conf.Configuration(); c.set(ConfigElement.getPath(TitanHadoopConfiguration.GRAPH_CONFIG_KEYS, true) + "." + "storage.cassandra.keyspace", getClass().getSimpleName()); c.set(ConfigElement.getPath(TitanHadoopConfiguration.GRAPH_CONFIG_KEYS, true) + "." + "storage.backend", "cassandrathrift"); c.set("cassandra.input.partitioner.class", "org.apache.cassandra.dht.Murmur3Partitioner"); Job job = getVertexJobWithDefaultMapper(c); // Should throw an exception since filter-partitioned-vertices wasn't enabled assertFalse(job.waitForCompletion(true)); }
Example #21
Source File: TitanIndexTest.java From titan1withtp3.1 with Apache License 2.0 | 5 votes |
public static void assertGraphOfTheGods(TitanGraph gotg) { assertCount(12, gotg.query().vertices()); assertCount(3, gotg.query().has(LABEL_NAME, "god").vertices()); TitanVertex h = getOnlyVertex(gotg.query().has("name", "hercules")); assertEquals(30, h.<Integer>value("age").intValue()); assertEquals("demigod", h.label()); assertCount(5, h.query().direction(Direction.BOTH).edges()); gotg.tx().commit(); }
Example #22
Source File: PropertyPlacementStrategy.java From titan1withtp3.1 with Apache License 2.0 | 5 votes |
@Override public int getPartition(InternalElement element) { if (element instanceof TitanVertex) { int pid = getPartitionIDbyKey((TitanVertex)element); if (pid>=0) return pid; } return super.getPartition(element); }
Example #23
Source File: ManagementSystem.java From titan1withtp3.1 with Apache License 2.0 | 5 votes |
private TitanEdge addSchemaEdge(TitanVertex out, TitanVertex in, TypeDefinitionCategory def, Object modifier) { assert def.isEdge(); TitanEdge edge = transaction.addEdge(out, in, BaseLabel.SchemaDefinitionEdge); TypeDefinitionDescription desc = new TypeDefinitionDescription(def, modifier); edge.property(BaseKey.SchemaDefinitionDesc.name(), desc); return edge; }
Example #24
Source File: ManagementSystem.java From titan1withtp3.1 with Apache License 2.0 | 5 votes |
public TitanSchemaElement getSchemaElement(long id) { TitanVertex v = transaction.getVertex(id); if (v == null) return null; if (v instanceof RelationType) { if (((InternalRelationType) v).getBaseType() == null) return (RelationType) v; return new RelationTypeIndexWrapper((InternalRelationType) v); } if (v instanceof TitanSchemaVertex) { TitanSchemaVertex sv = (TitanSchemaVertex) v; if (sv.getDefinition().containsKey(TypeDefinitionCategory.INTERNAL_INDEX)) { return new TitanGraphIndexWrapper(sv.asIndexType()); } } throw new IllegalArgumentException("Not a valid schema element vertex: " + id); }
Example #25
Source File: VertexProgramScanJob.java From titan1withtp3.1 with Apache License 2.0 | 5 votes |
@Override public void process(TitanVertex vertex, ScanMetrics metrics) { PreloadedVertex v = (PreloadedVertex)vertex; long vertexId = v.longId(); VertexMemoryHandler<M> vh = new VertexMemoryHandler(vertexMemory,v); v.setAccessCheck(PreloadedVertex.OPENSTAR_CHECK); if (idManager.isPartitionedVertex(vertexId)) { if (idManager.isCanonicalVertexId(vertexId)) { EntryList results = v.getFromCache(SYSTEM_PROPS_QUERY); if (results == null) results = EntryList.EMPTY_LIST; vertexMemory.setLoadedProperties(vertexId,results); } for (MessageScope scope : vertexMemory.getPreviousScopes()) { if (scope instanceof MessageScope.Local) { M combinedMsg = null; for (Iterator<M> msgIter = vh.receiveMessages(scope).iterator(); msgIter.hasNext(); ) { M msg = msgIter.next(); if (combinedMsg==null) combinedMsg=msg; else combinedMsg = combiner.combine(combinedMsg,msg); } if (combinedMsg!=null) vertexMemory.aggregateMessage(vertexId,combinedMsg,scope); } } } else { v.setPropertyMixing(vh); vertexProgram.execute(v, vh, memory); } }
Example #26
Source File: TitanTraversalUtil.java From titan1withtp3.1 with Apache License 2.0 | 5 votes |
public static TitanVertex getTitanVertex(Element v) { while (v instanceof WrappedVertex) { v = ((WrappedVertex<Vertex>) v).getBaseVertex(); } if (v instanceof TitanVertex) { return (TitanVertex) v; } else throw new IllegalArgumentException("Expected traverser of Titan vertex but found: " + v); }
Example #27
Source File: AbstractEdge.java From titan1withtp3.1 with Apache License 2.0 | 5 votes |
@Override public TitanVertex otherVertex(Vertex vertex) { if (start.equals(vertex)) return end; if (end.equals(vertex)) return start; throw new IllegalArgumentException("Edge is not incident on vertex"); }
Example #28
Source File: RelationIdentifier.java From titan1withtp3.1 with Apache License 2.0 | 5 votes |
TitanRelation findRelation(TitanTransaction tx) { TitanVertex v = ((StandardTitanTx)tx).getInternalVertex(outVertexId); if (v == null || v.isRemoved()) return null; TitanVertex typeVertex = tx.getVertex(typeId); if (typeVertex == null) return null; if (!(typeVertex instanceof RelationType)) throw new IllegalArgumentException("Invalid RelationIdentifier: typeID does not reference a type"); RelationType type = (RelationType) typeVertex; Iterable<? extends TitanRelation> rels; if (((RelationType) typeVertex).isEdgeLabel()) { Direction dir = Direction.OUT; TitanVertex other = ((StandardTitanTx)tx).getInternalVertex(inVertexId); if (other==null || other.isRemoved()) return null; if (((StandardTitanTx) tx).isPartitionedVertex(v) && !((StandardTitanTx) tx).isPartitionedVertex(other)) { //Swap for likely better performance TitanVertex tmp = other; other = v; v = tmp; dir = Direction.IN; } rels = ((VertexCentricQueryBuilder) v.query()).noPartitionRestriction().types((EdgeLabel) type).direction(dir).adjacent(other).edges(); } else { rels = ((VertexCentricQueryBuilder) v.query()).noPartitionRestriction().types((PropertyKey) type).properties(); } for (TitanRelation r : rels) { //Find current or previous relation if (r.longId() == relationId || ((r instanceof StandardRelation) && ((StandardRelation) r).getPreviousID() == relationId)) return r; } return null; }
Example #29
Source File: Titan1IndexQuery.java From incubator-atlas with Apache License 2.0 | 5 votes |
@Override public Iterator<Result<Titan1Vertex, Titan1Edge>> vertices() { Iterator<TitanIndexQuery.Result<TitanVertex>> results = query.vertices().iterator(); Function<TitanIndexQuery.Result<TitanVertex>, Result<Titan1Vertex, Titan1Edge>> function = new Function<TitanIndexQuery.Result<TitanVertex>, Result<Titan1Vertex, Titan1Edge>>() { @Override public Result<Titan1Vertex, Titan1Edge> apply(TitanIndexQuery.Result<TitanVertex> source) { return new ResultImpl(source); } }; return Iterators.transform(results, function); }
Example #30
Source File: Titan0Vertex.java From incubator-atlas with Apache License 2.0 | 5 votes |
@Override public <T> Collection<T> getPropertyValues(String key, Class<T> clazz) { TitanVertex tv = getAsTitanVertex(); Collection<T> result = new ArrayList<>(); for (TitanProperty property : tv.getProperties(key)) { result.add((T) property.getValue()); } return result; }