在Titan图形数据库中使用List基数更新顶点属性的整个值
我将更新列表属性的整个值,并为Titan 1.0中的值设置一个新值,对于单基数,我可以使用vertex.property("single_property",new_value)
,并覆盖整个值,但是对于类型为List的基数,新值将被添加到属性中(不会覆盖整个值).而且,如果我删除该属性并添加一个新值,那么在同一笔交易中,Titan似乎将忽略整个操作!因此,我的问题是如何以适当的方式更新list属性的整个值?
I am going to update entire value of list property and set a new value for that in Titan 1.0, for single cardinality I can use vertex.property("single_property",new_value)
,and overwrite the whole value but for the cardinality of type List, the new value will be added to the property (it will not overwrite the whole value). Moreover, if I remove the property and add a new value, in the same transaction it seems that the whole operation will be ignored by Titan! Therefore, my question would be how can I update the whole value of list property in an appropriate way?
关于phani提供的解决方案,以下代码对我不起作用,插入部分起作用,而删除部分无效.
Regarding the solution provided by phani, the following code did not work for me, the insertion part worked, but the deletion part did not.
keywords = keywordExtractor.getKeywords(getId(nextVertex))
if (keywords.size() > 0) {
nextVertex.property(VertexProperty.Cardinality.single, "post_keyword", keywords.get(0));
keywords.remove(0);
for (String keyword : keywords) {
nextVertex.property(VertexProperty.Cardinality.list, "post_keyword", keyword);
}
}
nextVertex.graph().tx().commit();
下面提供的Jason提供的解决方案也不起作用.问题出在删除部分.
Also the solution provide by Jason which is provided in the following did not work either. The problem was in the deletion part.
keywords = keywordExtractor.getKeywords(getId(nextVertex))
if (keywords.size() > 0) {
nextVertex.graph().traversal().V(nextVertex).properties("post_keyword").drop().iterate();
for (String keyword : keywords) {
nextVertex.property("post_keyword", keyword);
}
}
nextVertex.graph().tx().commit();
我也研究了以下解决方案;也不起作用.
I also did investigate the following solution; did not work either.
keywords = keywordExtractor.getKeywords(getId(nextVertex))
if (keywords.size() > 0) {
Iterator<VertexProperty<Object>> iter = nextVertex.properties("post_keyword");
while(iter.hasNext()){
iter.next().remove();
}
for (String keyword : keywords) {
nextVertex.property("post_keyword", keyword);
}
}
nextVertex.graph().tx().commit();
在主要问题上提出的所有提供的方法都可以用作更新列表/集合基数属性整体值的解决方案.但是,有一个实际的解决方案应该被考虑在内.
All the approaches provided which are presented at the main question can be used as a solution of updating the list/set cardinality property whole value. However, there is fact that should be taken into consideration to have a working solution.
在Titan 1.0中,当您在单个事务中使用后端索引(例如ES或Solr)时,将对所有添加和删除进行调查,以查找不必要的删除操作.不知何故,删除一个属性并添加相同的属性将合并到Titan突变类中,因此删除操作将被忽略.对于单基数,这种无知不是问题,因为在索引后端通过加法覆盖了整个值,但是对于列表/集合基数,这将导致后端索引数据不一致.
In Titan 1.0 when you use backend indexing (such as ES or Solr) in a single transaction all addition and deletion will be investigated to find the unnecessary deleting operations. Somehow, deleting one property and adding the same property will be consolidated in Titan mutation class, and consequently the deletion operation will be ignored. For single cardinality such ignorance is not a problem because of overwriting the whole value by addition at the indexing backend, but for List/Set cardinality this will cause an inconsistency in backend indexing data.
假设单个titan事务中的List/Set基数属性具有一个属性删除和相同的属性添加.提交部件后,gremlin查询显示覆盖整个属性有效,但是如果您检查索引后端,则会发现新属性已添加到旧属性中.从Titan的角度来看,remove属性操作已合并以删除不必要的删除!有两种方法可以解决此问题,或者从Titan中的Mutation
类中删除consolidation
方法(这将在单基数情况下导致不必要的操作),或者将多个事务用于添加和删除操作.我选择了第二个解决方案.
Suppose there is one property deletion and same property addition for the List/Set cardinality property in the single titan transaction. After committing part, gremlin query shows that the overwriting whole property works, but if you check the indexing backend you will find out that the new property is added to the old property. From the Titan perspective, the remove property operation is consolidated to remove the unnecessary deletion! There are two solutions for this problem, either remove the consolidation
method from the Mutation
class in Titan (this will cause an unnecessary operation in single cardinality situation), or use multiple transaction for addition and deletion operations. I chose the second solution.