1

Here they have set the type as a property on each vertex. However what if I want to give a type some properties itself? In that case wouldn't it make more sense to create a vertex to represent a type and have every other vertex have a 'type' edge? Otherwise I'd end up duplicating a type's properties.

Would this extra layer of indirection have a significant effect on performance if I, say, wanted to retrieve all vertices of a specific type?

Ian Warburton
  • 15,170
  • 23
  • 107
  • 189

2 Answers2

6

I see the titan tag so I'm going to give a Titan-specific answer.

With Titan, you can add properties to properties. So if you are tagging types by using properties instead of Vertex Labels then you can definitely add meta-properties.

That said, types are typically modeled using Vertex Labels and Edge Labels. Property Types, Vertex Labels, and Edge Labels are all actually stored as vertices. So if you want to attach schema meta-data or ontology info to the Titan types (Vertex Labels, Edge Labels, and Property Types) then you can do that too.

Bob B
  • 4,484
  • 3
  • 24
  • 32
  • 1
    I'm just about following. So you're saying that if every vertex is given a type property then you can add meta-data to the property and avoid having an edge for every vertex just to point to a type vertex? :) – Ian Warburton Oct 24 '14 at 15:00
  • 1
    Yes. Imagine a sensor that collects temperature readings. For each "reading" you store the temp, and also annotate that property value w/ a "time of collect" meta-property value. – Bob B Oct 24 '14 at 18:24
  • Would you be so kind to review this answer in light of the recent JanusGraph release? As Titan has been acquired and killed by Datastax. – lucid_dreamer May 04 '17 at 08:08
2

How about an it-depends answer?

You can use links to type nodes. For example, if you want to model that a person has a CS degree and that CS degree is type of BS degree which in turn is type of undergraduate degree, and you want to be able to reference that as part of your queries, then use links to types to indicate node type.

If you do not want to model a type hierarchy in the graph, then:

If your use case is to start a query with all entities of a certain type, and you do not have property indexes, then you could traverse from a known starting point to a "types" node to the "specific type" node and from there to all nodes of that type. If you have property indexes you could also put a type property on each node and use the index to look up the nodes of a desired type.

If the use case is filtering nodes by type mid-query, then using properties makes for a cleaner filter step. An alternative to both options is to use unique relationship labels for each source type / target type pair. For example, if a person "has" friends and a person "has" stuff you can save the node-type filter by changing your model to person "has friend" friend and person "owns" stuff.

If all the above doesn't help, I'd suggest thinking about how you want to query your model and go with whatever seems to fit your problem more naturally.

lucid_dreamer
  • 362
  • 4
  • 9
Paul Jackson
  • 2,077
  • 2
  • 19
  • 29
  • 2
    "conflate your graph metadata with your data". I'm not convinced this is what would happen. Another way of looking at it is that you're just categorising your vertexes. But if you're right and you use a type property instead then how is that not also adding metadata to the data? – Ian Warburton Oct 27 '14 at 01:16
  • 2
    I concede. I was thinking of the type hierarchy as being the metadata but your are right about the type itself being metadata as well. – Paul Jackson Oct 27 '14 at 12:27