Question

I am creating a Graph Data Table using Titan and Blueprint API. I am using HBase as backend. I know how to define data types for key indexes.

Example:

TitanKey name = graph.makeType().name("name").dataType(String.class).functional().makePropertyKey();

Now I actually want to represent a RDBMS Table in Titan DB Graph. Is there any process through which I can implement 'Column Data Type' (as in RDBMS Table) in the Titan Graph Model ?

Was it helpful?

Solution

Unlike a relational database, Titan's schema is flexible. That means, you can add new property keys and edge labels while the database is running without expensive "ALTER TABLE" commands. Also, Titan does not have a notion of "table" since every entity is represented by a vertex and every vertex can be connected to any other vertex by an edge.

If you have a USER table with columns NAME, AGE, UID (where UID is the unique primary key for that table) you would define the following property keys in Titan:

graph.makeType().name("name").dataType(String.class).functional().makePropertyKey()
graph.makeType().name("age").dataType(Integer.class).functional().makePropertyKey()
graph.makeType().name("uid").dataType(Long.class).functional().indexed().unique().makePropertyKey()

Then, for each user in that table you would create a vertex and set those properties:

v = g.addVertex(null);
v.setProperty("name","john");
v.setProperty("age",29);
v.setProperty("uid",23482234);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top