JanusGraph给Label添加载字段属性时报org.janusgraph.core.SchemaViolationException异常

14 篇文章 1 订阅
14 篇文章 1 订阅

经过

janusgraph没有表的概念,但有类似表的schema的定义,称为label。如:我们可以通过graph.openManagement().makeVertexLabel().make()方法来创建顶点label。那么存在了类似表的label,是否就有类似表字段类似的定义,答案是肯定的。janusgraph中用propertykey的定义来替代常用表的属性作为解决方案。
但是和关系型数据库不一样的是,janusgraph的字段是统一维护在一个中。可以简单地把这个理解为一个集合,而这个集合,维护了该图的所有label的字段属性。
我们可以通过执行如下代码,打印这个图的维护的所有字段。

StandardJanusGraph graph = GraphUtil.getStandardGraphFactory();
JanusGraphManagement mgt = graph.openManagement();
String s4 = mgt.printPropertyKeys();
System.out.println(s4);

打印信息如下:
在这里插入图片描述
然后我们可以通过执行如下语句,给该 label进行属性添加。

@Test
public void testInsertDateData() {
      StandardJanusGraph standardGraphFactory = GraphUtil.getStandardGraphFactory();
      JanusGraphManagement mgmt = standardGraphFactory.openManagement();
      VertexLabel person = mgmt.makeVertexLabel("person").make();
      PropertyKey name = mgmt.makePropertyKey("name4").dataType(String.class).cardinality(Cardinality.SET).make();
      PropertyKey birthDate = mgmt.makePropertyKey("birthDate").dataType(Date.class).cardinality(Cardinality.SINGLE).make();
      mgmt.addProperties(person, name, birthDate);
      mgmt.commit();

  }

不过在执行的时候,报异常了。

异常信息

org.janusgraph.core.SchemaViolationException: Adding this property for key [~T$SchemaName] and value [rtname4] violates a uniqueness constraint [SystemIndex#~T$SchemaName]

	at org.janusgraph.graphdb.transaction.StandardJanusGraphTx.addProperty(StandardJanusGraphTx.java:817)
	at org.janusgraph.graphdb.transaction.StandardJanusGraphTx.addProperty(StandardJanusGraphTx.java:745)
	at org.janusgraph.graphdb.transaction.StandardJanusGraphTx.makeSchemaVertex(StandardJanusGraphTx.java:873)
	at org.janusgraph.graphdb.transaction.StandardJanusGraphTx.makePropertyKey(StandardJanusGraphTx.java:893)
	at org.janusgraph.graphdb.types.StandardPropertyKeyMaker.make(StandardPropertyKeyMaker.java:98)
	at cn.haizhi.bigdata.graph.client.DataInsertTest.testInsertDateData(DataInsertTest.java:48)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
	at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)

问题排查

如上,我们已经知道,在janusgraph的该图中的中,已经有name4这个字段了,所以会报异常。

结论

  • 同一个字段,只能被建立一次,即使是不同的label下创建。
  • janusgraph中,图一个图下(在存储上表现为hbase的表,不同的图用的是不同的hbase表),只维护一份propertyKey的列表。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值