【问题标题】:Gremlin on CosmosDB - Drop and recreate the properties of a vertex without deleting the vertexCosmosDB 上的 Gremlin - 在不删除顶点的情况下删除并重新创建顶点的属性
【发布时间】:2018-05-14 12:20:28
【问题描述】:

我正在尝试在 分区 CosmosDB 图中的顶点上设置属性。 如果顶点之前有任何属性,我希望它们被清理并替换为新的属性集。

即使是删除也有点棘手,因为“分区键”是作为不可删除的属性公开的。

g.V('nodeId').has('partitionKey','xx').properties().drop()

->“Gremlin 查询执行错误:无法删除分区属性。”

幸运的是,分区键属性的id是可预测的,可以用来过滤掉它:

g.V('nodeId').has('partitionKey','xx')
.properties().not(has('id', 'nodeId|partitionKey'))
.drop()

现在我一直在尝试添加新属性。我试过了:

g.V('nodeId').has('partitionKey','xx')
.properties().not(has('id', 'nodeId|partitionKey'))
.drop()
.property('a','valA')
.property('b','valB')

但看起来我将property() 步骤应用于(空)属性列表,而不是顶点。 该错误不是很有帮助:

Gremlin Query Compilation Error: Column reference R_200324["_value"] cannot be located in the raw records in the current execution pipeline.

我尝试使用将property() 步骤应用于顶点(通过select-ing 它),但我一定做错了什么:

g.V('nodeId').has('partitionKey','xx')
.as('v') 
.properties().not(has('id', 'nodeId|partitionKey'))
.drop()
.select('v')
.property('a','valA')
.property('b','valB')

这给出了与上面相同的错误。

我也尝试使用 .back('v') 代替 .select('v'),但 CosmosDB 似乎不支持 back

有什么建议吗?

【问题讨论】:

  • TinkerPop 3.x 中没有 back() 步骤 - 这是 2.x 中的旧语法

标签: azure-cosmosdb graph-databases gremlin tinkerpop3


【解决方案1】:

我认为您遇到了与this S.O. answer 中描述的相同的问题。

基本上,.drop() 将所有内容过滤出遍历并阻止以下任何代码执行任何操作。

您可以像这样使用.sideEffect() 来解决这个问题

g.V('nodeId').has('partitionKey','xx')
.sideEffect(properties().not(has('id', 'nodeId|partitionKey')).drop())
.property('a','valA')
.property('b','valB')

【讨论】:

    猜你喜欢
    • 2019-01-03
    • 1970-01-01
    • 2022-12-03
    • 1970-01-01
    • 2016-09-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-03
    相关资源
    最近更新 更多