How to Define Data Type for Titan Graph DB Vertex?

坚强是说给别人听的谎言 提交于 2020-01-02 16:15:09

问题


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 ?


回答1:


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);


来源:https://stackoverflow.com/questions/14626142/how-to-define-data-type-for-titan-graph-db-vertex

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!