Adam Elsodaney
Adam Elsodaney

Reputation: 7818

Are multiple vertex labels in Gremlin/Janusgraph possible, or is an alternative solution better?

I am working on an import runner for a new graph database.

It needs to work with:

So I am creating the graph where the Entity (Nodes/Verticies) have multiple Types (Labels), some being orthogonal to each other, as well as multi-dimensional.

For example, an Entity representing an order made online would be labeled as Order, Online, Spend, Transaction.

             | Spend       Chargeback
----------------------------------------
 Transaction | Purchase    Refund
 Line        | Sale        Return

Zooming into the Spend column.

          | Online      Instore
----------------------------------------
 Purchase | Order       InstorePurchase
 Sale     | OnlineSale  InstoreSale 

In Neo4j and its Cypher query language, this proves to be very powerful for creating Relationships/Edges across multiple types without explicitly knowing what transaction_id values are in the graph :

MATCH (a:Transaction), (b:Line)
WHERE a.transaction_id = b.transaction_id
MERGE (a)<-[edge:TRANSACTED_IN]-(b)
RETURN count(edge);

Problem is, Gremlin/Tinkerpop does not natively support multiple Labels for its Verticies.

Server implementations like AWS Neptune will support this using a delimiter eg. Order::Online::Spend::Transaction and the Gremlin client does support it for a Neo4j server but I haven't been able to find an example where this works for JanusGraph.

Ultimately, I need to be able to run a Gremlin query equivalent to the Cypher one above:

g
  .V().hasLabel("Line").as("b")
  .V().hasLabel("Transaction").as("a")
  .where("b", eq("a")).by("transaction_id")
  .addE("TRANSACTED_IN").from("b").to("a")';

So there are multiple questions here:

  1. Is there a way to make JanusGraph accept multiple vertex labels?
  2. If not possible, or this is not the best approach, should there be an additional vertex property containing a list of labels?
  3. In the case of option 2, should the label name be the high-level label (Transaction) or the low-level label (Order)?

Upvotes: 1

Views: 1200

Answers (1)

bechbd
bechbd

Reputation: 6341

Is there a way to make JanusGraph accept multiple vertex labels?

No, there is not a way to have multiple vertex labels in JanusGraph.

If not possible, or this is not the best approach, should there be an additional vertex property containing a list of labels?

In the case of option 2, should the label name be the high-level label (Transaction) or the low-level label (Order)?

I'll answer these two together. Based on what you have described above I would create a single label, probably named Transaction, and with different properties associated with them such as Location (Online or InStore) and Type (Purchase, Refund, Return, Chargeback, etc.). Looking at how you describe the problem above you are really talking only about a single entity, a Transaction where all the other items you are using as labels (Online/InStore, Spend/Refund) are really just additional metadata about how that Transaction occurred. As such the above approach would allow for simple filtering on one or more of these attributes to achieve anything that could be done with the multiple labels you are using in Neo4j.

Upvotes: 3

Related Questions