全部产品
Search
文档中心

:Steps U-Z

更新时间:Jul 18, 2023

unfold

  • 功能:(map)将list<object>展开为objects

  • 备注:fold()是相反的操作,可将objects聚合为list

g("thinkerpop").V("1;2;3;4;5;6").hasLabel("person").aggregate("x").by("name").cap("x").unfold()
==> "josh"
==> "marko"
==> "peter"
==> "vadas"

g("thinkerpop").V("1;2;3;4;5;6").hasLabel("person").values("name").fold().unfold()
==> "marko"
==> "josh"
==> "vadas"
==> "peter"

unoin

  • 功能:(branch)合并子遍历的结果

  • 备注:单步串行地计算每个子遍历,故性能较差。

g("thinkerpop").V("1;2;3;4;5;6").hasLabel("person").union(outE("knows"),outE("created"))
==> {"label""knows","pk":"1","sk":"4","weight":1.0}
==> {"label""knows","pk":"1","sk":"2","weight":0.5}
==> {"label""created","pk":"1","sk":"3","weight":0.4}
==> {"label""created","pk":"4","sk":"3","weight":0.4}
==> {"label""created","pk":"4","sk":"5","weight":1.0}
==> {"label""created","pk":"6","sk":"3","weight":0.2}

until

  • 功能:(修饰符)指定循环遍历的终止条件

  • 备注:需要与repeat()联合使用

V

  • 功能:(实体)查询顶点的信息。

  • 格式:不同的pkey字符串用;分割

  • 备注:

    • 图访问方式:通过hasLabel()指定要访问的顶点对应的图label

g("thinkerpop").V("1;2;3;4;5;6").hasLabel("person")
==> {"label":"person","age":29,"name":"marko","pk":"1"}
==> {"label":"person","age":32,"name":"josh","pk":"4"}
==> {"label":"person","age":27,"name":"vadas","pk":"2"}
==> {"label":"person","age":35,"name":"peter","pk":"6"}

values

  • 功能:(map)返回字段值

  • 备注:

    • 支持指定返回,默认返回所有

    • properties()支持返回字段名和字段值

g("thinkerpop").V("1;2").hasLabel("person").values()
==> 29
==> "marko"
==> "1"
==> 27
==> "vadas"
==> "2"

g("thinkerpop").V("1;2").hasLabel("person").values("name","age")
==> 29
==> "marko"
==> 27
==> "vadas"

where

  • 功能:(filter)过滤

  • 备注:单步支持P作为过滤条件

g("thinkerpop").V("1;2;3;4;5;6").hasLabel("person").values("name").where(is("marko"))
==> "marko"

g("thinkerpop").V("1;2;3;4;5;6").hasLabel("person").where(values("name").is("marko"))
==> {"label""person","age":29,"name":"marko","pk":"1"}

// 查找人4创造的软件,并且联合作者不是人1
// 对实体进行遍历
g("thinkerpop").E("1").hasLabel("created").inV().aggregate("x").fold().E("4").hasLabel("created").inV().where(P.without("x"))
==> {"label":"software","lang":"java","name":"ripple","pk":"5"}
// 等同于
g("thinkerpop").E("1").hasLabel("created").inV().aggregate("x").fold().E("4").hasLabel("created").inV().as("y").where("y",P.without("x"))

withSack

  • 功能:(修饰符)为实体的sack值定义初始值、分裂规则和合并规则。

  • 语法:withSack(initialValueSupplier[,Splitter][,mergeOperator])

  • 此单步与开源Gremlin不完全一致

    • initialValueSupplier:指定sack的初始值。

      • 支持下列三种初始化方法:

        • kv:为每个顶点单独指定sack初始值

        • kkv:为每条边单独指定sack初始值

        • normal:为实体(顶点/边)指定相同的sack初始值。

      • 支持为每个实体指定多种sack。

      • 用JSON描述sack的初始值。

        • 由于双引号存在解析冲突,JSON中的双引号需要转义。

        • kv中,JSON最外层的key对应于顶点的pkey。

        • kkv中,JSON最外层的key对应于边的pkey,第二层的key对应于边的skey

    • Splitter:指定sack的分裂规则,支持下列三种方法:

      • Splitter.identity:适用于数值或者string类型。性能优。

      • Splitter.fastclone:适用于迭代器类型(list、map)。性能优、风险低,推荐使用。

        • 仅在必要情况保证sack值唯一

      • Splitter.clone:适用于上述两种Splitter不适用的情况。性能良,无风险

        • 保证sack值唯一

    • mergeOperator:指定barrier()时sack的合并规则,支持下列方法:

      • Operator.sum:sack值相加

      • Operator.assign:为sack重新赋值

      • Operator.mult:sack值相乘

      • Operator.div:sack值相除

      • Operator.minus:sack值取最小值

      • Operator.addall :保留所有sack值

  • 备注:

    • 如果没有指定mergeOperatorbarrier()不会合并相同的objects。

    • 浮点类型的sack存在精度问题

    • __SACK__ 作为内置关键字代表当前sack值,是的sack值可以通过表达式参与复杂计算。

    • sack()返回sack值

    • withSack()返回实体和sack值

// 初始设置sack=1.0。未指定合并规则,遇到barrier()时不做合并,sack保持初始值不变。
g("thinkerpop").withSack(supplier(normal, float,"1.0")).E("1;2;3;4;5;6").hasLabel("created").inV().barrier().sack()
==> 1.0
==> 1.0
==> 1.0
==> 1.0
// 返回结果前展开合并的结果
g("thinkerpop").withSack(supplier(normal, float,"1.0")).E("1;2;3;4;5;6").hasLabel("created").inV().hasLabel("software").barrier().withSack()
==> {"label""software","lang":"java","name":"lop","pk":"3"},1.0,
==> {"label""software","lang":"java","name":"lop","pk":"3"},1.0,
==> {"label""software","lang":"java","name":"lop","pk":"3"},1.0,
==> {"label""software","lang":"java","name":"ripple","pk":"5"},1.0

// 初始设置sack=1.0。barrier()按照Operator.sum规则合并sack值
g("thinkerpop").withSack(supplier(normal, float,"1.0"),Splitter.identity,Operator.sum).E("1;2;3;4;5;6").hasLabel("created").inV().barrier().sack()
==> 3.0
==> 3.0
==> 3.0
==> 1.0
// 返回结果前展开合并的结果
g("thinkerpop").withSack(supplier(normal, float,"1.0"),Splitter.identity,Operator.sum).E("1;2;3;4;5;6").hasLabel("created").inV().barrier().withSack()
==> {"label""software","lang":"java","name":"lop","pk":"3"},3.0,
==> {"label""software","lang":"java","name":"lop","pk":"3"},3.0,
==> {"label""software","lang":"java","name":"lop","pk":"3"},3.0,
==> {"label""software","lang":"java","name":"ripple","pk":"5"},1.0

// 初始设置sack=1.0。访问created时,执行sack=sack*weight操作
g("thinkerpop").withSack(supplier(normal, float,"1.0"),Splitter.identity,Operator.sum).E("1;4;6").hasLabel("created").sack(Operator.mult).by("weight").withSack()
==> {"data":[{"label""created","pk":"1","sk":"3","weight":0.4},0.4
==> {"label""created","pk":"4","sk":"3","weight":0.4},0.4
==> {"label""created","pk":"4","sk":"5","weight":1.0},1.0
==> {"label""created","pk":"6","sk":"3","weight":0.2},0.2
// 等同于
g("thinkerpop").withSack(supplier(normal, float,"1.0"),Splitter.identity,Operator.sum).E("1;2;3;4;5;6").hasLabel("created").sack(Operator.assign).by("weight*__SACK__").withSack()

// 为每个顶点指定不同的sack初始值
g("thinkerpop").withSack(supplier(kv,"{\"1\":0.3,\"4\":0.7,\"6\":0.4}"),Splitter.identity,Operator.sum).E("1;4;6").hasLabel("created").sack(Operator.mult).by("weight").withSack()
==> {"label""created","pk":"1","sk":"3","weight":0.4},0.12
==> {"label""created","pk":"4","sk":"3","weight":0.4},0.27999999999999999
==> {"label""created","pk":"4","sk":"5","weight":1.0},0.7
==> {"label""created","pk":"6","sk":"3","weight":0.2},0.08000000000000002

// 为每个顶点指定多种sack,每种sack定义不同的修改规则
g("thinkerpop").withSack(supplier(normal,"{\"k1\":[\"abc\"],\"k2\":1}"),Splitter.fastclone,"{\"k1\":\"Operator.addall\",\"k2\":\"Operator.sum\"}").V("1;2;3;4;5;6").hasLabel("person").sack("k2",Operator.sum).by("to_int(age)").sack("k1",Operator.addall).by(__.values("name").fold()).sack()
==> {"\"k1\"":["abc","marko"],"\"k2\"":30}
==> {"\"k1\"":["abc","josh"],"\"k2\"":33}
==> {"\"k1\"":["abc","vadas"],"\"k2\"":28}
==> {"\"k1\"":["abc","peter"],"\"k2\"":36}

withStrategies

  • 功能:(策略)为遍历添加定制化策略

  • 备注:目前支持下列策略

  • 此单步与开源Gremlin不完全一致

    • PathRecordStrategy:支持定制path()记录的信息类型

    • PushDownStrategy:定制获取sideEffect的单步的执行位置