Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Gremlin-如果超出限制,则添加新顶点_Gremlin_Tinkerpop - Fatal编程技术网

Gremlin-如果超出限制,则添加新顶点

Gremlin-如果超出限制,则添加新顶点,gremlin,tinkerpop,Gremlin,Tinkerpop,样本数据: 我有两个顶点的名称,用户点 首先为vertex用户添加数据 g.addV('User').property('id',1). addV('User').property('id',2). addV('User').property('id',3).iterate() 现在添加点顶点,并将添加点从用户到点 g.V().hasLabel('User').has('id',1).as('curUser1'). V().hasLabel('User').has('id',2).

样本数据:

我有两个顶点的名称,用户点

首先为vertex用户添加数据

g.addV('User').property('id',1).
  addV('User').property('id',2).
  addV('User').property('id',3).iterate()
现在添加顶点,并将添加点用户

g.V().hasLabel('User').has('id',1).as('curUser1').
  V().hasLabel('User').has('id',2).as('curUser2').
  V().hasLabel('User').has('id',3).as('curUser3').
  addV('Points').property('totalPoints',0).property('userPoints',0).
  property('createDate',1560316666).property('name','user1').
  addE('addingPoints').from('curUser1').
  addV('Points').property('totalPoints',0).property('userPoints',0).
  property('createDate',1560318666).property('name','user2').
  addE('addingPoints').from('curUser2').
  addV('Points').property('totalPoints',0).property('userPoints',0).
  property('createDate',1560318657).property('name','user3').
  addE('addingPoints').from('curUser3').iterate()
现在每个用户至少有一个顶点

现在我想将10(或)20(或)30点随机添加到id为1的用户的totalPoints属性中

在添加这些要点时,我有三种情况:

1.如果totalPoints是lt500,那么我只需要更新id为1的用户的Points顶点的totalPoints属性

2.如果totalPoints是eq500,那么我应该创建新的顶点,并将点添加到totalPoints属性中,该属性是id为1的用户的点顶点

3.如果总积分为490,则不是eq500而是lt500。但是现在如果我需要向totalPoints属性添加30个点 然后,我需要在id为1的用户的旧顶点上添加10个点,我应该在id为1的用户的新顶点上添加剩余的20个点

我怎样才能做到这一点

多谢各位

  • 选择用户的
    顶点,该顶点具有最低的
    总点
  • 总点数
    与新点数相加
  • 如果总和超过500,则将
    totalPoints
    属性值设置为500,并添加一个新的
    Points
    顶点,其
    totalPoints
    值为
    sum-500
  • 如果总和不超过500,则将其设置为新的
    totalPoints
    属性值
  • 这4个步骤转化为遍历:

    g.withSack(points).
      V().has('User','id',user).as('u').
        out('addingPoints').
        order().
          by('totalPoints').
        limit(1).
        sack(sum).
          by('totalPoints').
        choose(sack().is(gt(maxPoints)),
                 sack(minus).
                   by(constant(maxPoints)).
                 property('totalPoints', maxPoints).
                 addV('Points').
                 sideEffect(addE('addingPoints').
                              from('u'))).
        property('totalPoints', sack())
    
    还有一个小控制台示例(我用
    totalPoints=400
    初始化了第一个
    顶点,用
    totalPoints=480
    初始化了第二个
    顶点):

  • 选择用户的
    顶点,该顶点具有最低的
    总点
  • 总点数
    与新点数相加
  • 如果总和超过500,则将
    totalPoints
    属性值设置为500,并添加一个新的
    Points
    顶点,其
    totalPoints
    值为
    sum-500
  • 如果总和不超过500,则将其设置为新的
    totalPoints
    属性值
  • 这4个步骤转化为遍历:

    g.withSack(points).
      V().has('User','id',user).as('u').
        out('addingPoints').
        order().
          by('totalPoints').
        limit(1).
        sack(sum).
          by('totalPoints').
        choose(sack().is(gt(maxPoints)),
                 sack(minus).
                   by(constant(maxPoints)).
                 property('totalPoints', maxPoints).
                 addV('Points').
                 sideEffect(addE('addingPoints').
                              from('u'))).
        property('totalPoints', sack())
    
    还有一个小控制台示例(我用
    totalPoints=400
    初始化了第一个
    顶点,用
    totalPoints=480
    初始化了第二个
    顶点):