首页 > 解决方案 > Gremlin 忽略存储价值

问题描述

我是 gremlin 的新手并尝试查询,但我观察到存储值总是被忽略

我试过了storeaggregate也试过了,as但都给了我错误的价值观。

g.V().has('__typeName','avro_schema').where(local(out('__avro_record.fields').as('xm').local(out('classifiedAs').has('__typeName', 'DataClassification').count().is(eq(1))).count().is(eq(select('xm').size()))))

这给出了'xm'一如既往的大小 0

我希望 size 的值'xm'等于每个avro_schema边缘标签的传出边缘的数量'__avro_record.fields'

正如所指出的,将查询更改为:

g.V().has('__typeName','avro_schema').where(local(out('__avro_record.fields').local(out('classifiedAs').has('__typeName', 'DataClassification').count().is(eq(1))).count().is(count(local))))

现在得到空结果。

编辑 :

我也对将动态值打印为 sideEffect 有疑问

g.V().has('__typeName','avro_schema').where(local(out('__avro_record.fields').local(out('classifiedAs').has('__typeName', 'DataClassification').count().is(eq(1))).count().sideEffect{ println count(local) }.is(count(local))))

输出:

[CountLocalStep]

我期望 count(local) 的实际值在哪里。调试 gremlin 查询的最佳实践是什么?

标签: databasegroovygraphgremlin

解决方案


在您的遍历中,有些事情是行不通的。首先,.size()不是 Gremlin 步骤,您可能正在寻找.count(local). 接下来,eq()不采用动态值,它仅适用于常量值。阅读文档where()了解如何与动态值进行比较。

更新

要比较这两个count()值,您可以执行以下操作:

g.V().has('__typeName','avro_schema').filter(
    out('__avro_record.fields').fold().as('x').
    map(unfold().
        out('classifiedAs').has('__typeName', 'DataClassification').fold()).as('y').
    where('x', eq('y')).
      by(count(local)))

推荐阅读