如何为Titan Graph DB Vertex定义数据类型? [英] How to Define Data Type for Titan Graph DB Vertex?

查看:205
本文介绍了如何为Titan Graph DB Vertex定义数据类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Titan和Blueprint API创建图表数据表。我使用HBase作为后端。
我知道如何为关键指标定义数据类型。



示例:



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

现在我真的想在Titan DB Graph中表示一个RDBMS表。有没有什么过程可以通过它在Titan图模型中实现列数据类型(如RDBMS表中所示)?

解决方案

与关系数据库不同,Titan的模式很灵活。这意味着,您可以在数据库运行时添加新的属性键和边缘标签,而无需使用昂贵的ALTER TABLE命令。此外,Titan没有表格的概念,因为每个实体都由顶点表示,每个顶点可以通过边缘连接到任何其他顶点。



如果你有一个列名为NAME,AGE,UID(其中UID是该表的唯一主键)的USER表,你可以在Titan中定义下列属性键:



<$ p $ ()函数名称(名称)。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()

然后,为该表中的每个用户创建一个顶点并设置它们属性:

  v = g.addVertex(null); 
v.setProperty(name,john);
v.setProperty(age,29);
v.setProperty(uid,23482234);


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 ?

解决方案

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

这篇关于如何为Titan Graph DB Vertex定义数据类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆