Gremlin:获取按父顶点分组的顶点属性键

Gremlin:获取按父顶点分组的顶点属性键,gremlin,Gremlin,样本数据: g.addV('organisation').property('id', 1).property('name', 'org-1').as('org1'). addV('cloud-service-provider').property('id', 1).property('name', 'AWS').as('aws'). addV('cloud-service-provider').property('id', 2).property('name', 'Azure').as

样本数据:

    g.addV('organisation').property('id', 1).property('name', 'org-1').as('org1').
addV('cloud-service-provider').property('id', 1).property('name', 'AWS').as('aws').
addV('cloud-service-provider').property('id', 2).property('name', 'Azure').as('azure').
addV('account').property('id', 1).property('name', 'aws-account-11').as('aws-account').
addV('account').property('id', 2).property('name', 'azure-account-22').as('azure-account').
addV('region').property('id', 1).property('name', 'us-east-1').as('aws-region-us-east-1').
addV('region').property('id', 1).property('name', 'us-west-2').as('azure-region-us-west-2').
addV('region').property('id', 2).property('name', 'us-west-2').as('aws-region-us-west-2').
addV('sql-server').property('id', 1).property('name', 'my-sql-server').property('version', 'v1').as('sql-server').
addV('security-group').property('id', 1).property('name', 'sg-1').as('sg-1').
addV('inbound-rule').property('id', 1).property('fromPort', 1).property('toPort', 65636).as('inbound-rule-1').
addV('inbound-rule').property('id', 2).property('fromPort', 5).property('toPort', 8001).as('inbound-rule-2').
addV('outbound-rule').property('id', 1).property('fromPort', 100).property('toPort', 200).as('outbound-rule-1').
addV('user-id-group-pair').property('id', 1).property('groupId', 'group-1').property('groupName', 'my-group').property('user-id', 'u-1').as('user-id-group-pair').
addE('uses').from('org1').to('aws').
addE('uses').from('org1').to('azure').
addE('has').from('aws').to('aws-account').
addE('has').from('azure').to('azure-account').
addE('has').from('aws-account').to('aws-region-us-east-1').
addE('has').from('aws-account').to('aws-region-us-west-2').
addE('has').from('azure-account').to('azure-region-us-west-2').
addE('has').from('azure-region-us-west-2').to('sql-server').
addE('has').from('aws-region-us-east-1').to('sg-1').
addE('has_property').from('sg-1').to('inbound-rule-1').
addE('has_property').from('sg-1').to('inbound-rule-2').
addE('has_property').from('sg-1').to('outbound-rule-1').
addE('has_property').from('inbound-rule-1').to('user-id-group-pair').
iterate();
我想获得所有属性键按顶级顶点“云服务提供商”分组

g.V().group().by(T.label).by(__.properties().label().dedup().fold()).toList()
提供属性键,但我也想在父顶点上应用分组

p、 在示例图中,有一个特殊的边标签-“has_property”

复杂的顶点属性,如列表和贴图(在java中),使用此边标签进行建模

预期产出

例如

对于Azure->预期输出为:

[account.id,
account.name,
region.id,
region.name,
sql-server.id,
sql-server.version]
[account.id,
account.name,
region.id,
region.name,
security_group.id,
security_group.name,
security_group.inbound_rule.fromPort(inbound_rule is a property of security_group),
security_group.inbound_rule.toPort,
security_group.inbound_rule.id,
security_group.outbound_rule.fromPort,
security_group.outbound_rule.toPort,
security_group.outbound_rule.id,
security_group.inbound_rule.user-id-group-pair.groupId(user-id-group-pair is a property of inbound_rule),
security_group.inbound_rule.user-id-group-pair.groupName,
security_group.inbound_rule.user-id-group-pair.userId,
security_group.inbound_rule.user-id-group-pair.id]
对于aws->预期输出为:

[account.id,
account.name,
region.id,
region.name,
sql-server.id,
sql-server.version]
[account.id,
account.name,
region.id,
region.name,
security_group.id,
security_group.name,
security_group.inbound_rule.fromPort(inbound_rule is a property of security_group),
security_group.inbound_rule.toPort,
security_group.inbound_rule.id,
security_group.outbound_rule.fromPort,
security_group.outbound_rule.toPort,
security_group.outbound_rule.id,
security_group.inbound_rule.user-id-group-pair.groupId(user-id-group-pair is a property of inbound_rule),
security_group.inbound_rule.user-id-group-pair.groupName,
security_group.inbound_rule.user-id-group-pair.userId,
security_group.inbound_rule.user-id-group-pair.id]

你能用小精灵做到这一点真是太神奇了:

g.V().out("uses").project("csp","props")
.by("name")
.by(
    repeat(out("has")).emit().as("a")
    .emit().repeat(out("has_property"))
    .properties().path().by(label).from("a")
    .select(values).dedup()
    .fold()
)
输出将是服务提供者的数组,每个服务提供者都有一个名称和一个属性列表。 每个属性都是一个数组,您应该将其与(.)联接以获得最终结果


你可以试试。

嘿,肯菲尔!感谢您使用Gremlify分享您的知识并传播有关Gremlin的信息。希望你觉得它有用。如果你有任何反馈,那就太好了。