janusgraph的数据模型---》参考

  1.简介

  janusgraph的数据模型,就是一数据结构中得图结构相似。所以janusgraph的数据schema主要定义在三个要素上:顶点,边,属性。上面的god图中,红色的点就是顶点,点与点之间的线就是边,在点和边上的方框中写的就是点和边的属性

  在janusgraph中,对schema进行操作都要打开

  gremlin> mgmt=graph.openManagement()

  ==>org.janusgraph.graphdb.database.management.ManagementSystem@2484dbb7

  2.对点的标签进行操作(Vertex Label)

    2.1 vertice label描述的是vertice的语义,不过vertice label是optional的,用来区分不同类型的vertice,比如 user 和 product。

    2.2 利用 makeVertexLabel(String).make() 来创建vertice label  
    2.3 vertice label必须保持全局唯一性
    查询出所有的vertice label

mgmt.vertexLabels

    增加一个vertice label 

mgmt = graph.openManagement()
person = mgmt.makeVertexLabel('person').make()
mgmt.commit()
// Create a labeled vertex
person = graph.addVertex(label, 'person')
// Create an unlabeled vertex
v = graph.addVertex()
graph.tx().commit()

   3.对Edge label进行操作

    3.1在一个事务中,用makeEdgeLabel(String) 来定义一个edge label。edge label必须是唯一的,这个方法会返回一个 builder,这个 builder 可以用来获取这种edge label的多度关系multiplicity,这个指标限定了每对(pair)之间edge最大的数量。

    3.2 创建edge label 中有一个属性 Multiplicity ,通过设置这个属性值来限定每对(pair)之间edge最大的数量。

      MULTI,SIMPLE,MANY2ONE,ONE2MANY,ONE2ONE

    3.3 如果在创建过程中不进行设置,默认使用MULTI

mgmt = graph.openManagement()
follow = mgmt.makeEdgeLabel('follow').multiplicity(MULTI).make()
mother = mgmt.makeEdgeLabel('mother').multiplicity(MANY2ONE).make()
mgmt.commit()

   4.Property keys

    属性Property的定义在顶点点和边上,Property是key-value的形式存在

    通过 makePropertyKey(String) 方法来创建Property key,属性名应该尽可能避免使用空格和特殊字符

    Native JanusGraph Data Types

Name Description

String

Character sequence

Character

Individual character

Boolean

true or false

Byte

byte value

Short

short value

Integer

integer value

Long

long value

Float

4 byte floating point number

Double

8 byte floating point number

Date

Specific instant in time (java.util.Date)

Geoshape

Geographic shape like point, circle or box

UUID

Universally unique identifier (java.util.UUID)

  在创建Property是需要注意 Property key Data Type 和 Property Key Cardinality

  Property key Data Type

  每个属性的key和value都有自己的数据类型,必须是上述表格的数据类型的一种,通过dataType(Class)来定义数据类型。

  数据类型可以声明为Object.class ,但是如果这样使用的话,会造成空间的浪费,同时在进行数据导入时janusgraph无法帮我我们判断数据类型是否符合要求

  Property Key Cardinality

  使用方法cardinality(Cardinality)方法来定义某个顶点的某个属性的基底

  在janusgraph的图数据库中有三个选择

    SINGLE:每一个元素对于这个key只能有一个value,比如 birthDate 就是一个single基底,因为每个人最多只能有一个生日。

    LIST:每个元素对于这个key可以有任意数量的值,比如我们建模传感器(sensor),其有一个属性是 sensorRecords,那么,对于这个属性,可能有一系列的值。注意,LIST是允许有重复元素的。

    SET: 与LIST相同,不同的是,SET不允许有重复的元素。
  默认的cardinality是single。注意,对于边属性来说,property key的基底始终是single。
  

mgmt = graph.openManagement()
birthDate = mgmt.makePropertyKey('birthDate').dataType(Long.class).cardinality(Cardinality.SINGLE).make()
name = mgmt.makePropertyKey('name').dataType(String.class).cardinality(Cardinality.SET).make()
sensorReading = mgmt.makePropertyKey('sensorReading').dataType(Double.class).cardinality(Cardinality.LIST).make()
mgmt.commit()

  5.Relation Type

  Edge labels和property keys共同称为Relation Types。关系类型的名称在图形中必须是唯一的,这意味着property keys和Edge labels不能具有相同的名称。JanusGraph API中有一些方法可以查询是否存在或检索包含property keys和Edge labels的关系类型 

mgmt = graph.openManagement()
if (mgmt.containsRelationType('name'))
name = mgmt.getPropertyKey('name')
mgmt.getRelationTypes(EdgeLabel.class)
mgmt.commit()

 

   

janusgraph的数据模型的更多相关文章

  1. JanusGraph入门,schema及数据模型

    5.Schema和数据建模 每个JanusGraph都有一个schema,该schema由edge labels,property keys,和vertex组成.JanusGraph schema可以 ...

  2. 主流图库对比以及JanusGraph入门

    1.Overall Comparison Name Neo4j JanusGraph Giraph Jena 1.Compute Framework Yes Yes Yes 2.External Co ...

  3. JanusGraph : 图和图数据库的简介

    JanusGraph:图数据库系统简介 图(graph)是<数据结构>课中第一次接触到的一个概念,它是一种用来描述现实世界中个体和个体之间网络关系的数据结构. 为了在计算机中存储图,< ...

  4. JaunsGraph数据模型

    JanusGraph采用邻接表(adjacency list)的方式存储图,也即图以顶点(vertex)和其邻接表组成.邻接表中保存某个顶点的所有入射边(incident edges). 通过将图采用 ...

  5. JanusGraph的schema及数据建模

    每个JanusGraph都有一个schema,该schema由edge labels, property keys和vertex labels组成.JanusGraph的schema可以显式或隐式创建 ...

  6. MongoDB学习笔记~数据模型属性为集合时应该为它初始化

    回到目录 今天要说一下技术点,我们在设计mongodb的数据模型时,如果属性是数组或者集合类型,我们在模型初始化时,需要为它们初始化一下,否则在数据库里将会被存储为NULL,当被存储为NULL时,我们 ...

  7. 从零自学Hadoop(20):HBase数据模型相关操作上

    阅读目录 序 介绍 命名空间 表 系列索引 本文版权归mephisto和博客园共有,欢迎转载,但须保留此段声明,并给出原文链接,谢谢合作. 文章是哥(mephisto)写的,SourceLink 序 ...

  8. Entity Framework 教程——创建实体数据模型

    创建实体数据模型: 本文将带你创建实体数据模型(EDM)SchoolDB数据库和理解基础建设模块. 实体数据模型(EDM)是用于描述实体之间关系的一种模型,以下将使用Visual Studio 201 ...

  9. ZooKeeper:数据模型

    ZooKeeper数据模型 ZNode ZNode 分类 Stat Watcher Watcher工作原理 Watcher事件说明 Watcher注册 事件发布 示例 ZooKeeper 数据模型 整 ...

随机推荐

  1. AtCoder Grand Contest 036 简要题解

    从这里开始 比赛目录 Problem A Triangle 考虑把三角形移到和坐标轴相交,即 然后能够用坐标比较简单地计算面积,简单构造一下就行了. Code #include <bits/st ...

  2. web版聊天功能简单实现

    一.问题 核心点:如何找到要发送的人? 要完成一个功能我觉得首先要分析该功能的逻辑及技术难点,而不是盲目的直接就撸代码,这样非常浪费时间.个人觉得web版聊天功能没什么实际应用场景,以前看过中国移动好 ...

  3. cefsharp参考笔记

    https://blog.csdn.net/yh0503/article/details/86678115 https://blog.csdn.net/qq_17351077/article/deta ...

  4. 【转】python 调用super()初始化报错“TypeError: super() takes at least 1 argument”

    一.实验环境 1.Windows7x64_SP1 2.Anaconda2.5.0 + python2.7(anaconda集成,不需单独安装) 二.实验步骤 2.1 在python中有如下代码: cl ...

  5. docker命令集合

    #docker安装yum -y install docker-iodocker --version #启动Docker进程systemctl start dockersystemctl status ...

  6. SQLServer查看分区表详细信息

    SQL查看分区内记录个数,常规方法需要知道分区函数然后再显示,网上看到一个一句话显示的方法 ), ps.name ) as partition_scheme, p.partition_number, ...

  7. goang学习笔记---struct

    什么是结构体 结构体(struct)是用户自定义的类型,它代表若干字段的集合,可以用于描述一个实体对象,类似java中的class,是golang面向对象编程的基础类型. 如何定义一个结构体 type ...

  8. 【spring boot】加载同名Bean解决方法

    原文地址:https://blog.csdn.net/liuyueyi25/article/details/83280239 @SpringBootApplication @ComponentScan ...

  9. 2019-11-29-WPF-高速书写-StylusPlugIn-原理

    原文:2019-11-29-WPF-高速书写-StylusPlugIn-原理 title author date CreateTime categories WPF 高速书写 StylusPlugIn ...

  10. 安卓访问https错误,访问http可以,可能是nginx ssl证书配置有问题

    开发中遇到react-native生成的android访问UAT和开发环境的http api都可以,但是访问生产环境的https就报错,还有就是第三方webhook调用你https网站的api也可能会 ...