使用 Gremlin 在 TitanDB 中排序
Sorting in TitanDB with Gremlin
每个顶点和边具有以下属性:
Request [req_id: long, submit_time:long, priority:int, status:char]
Test_B [tb_id: long, tb_name: string]
TestSuite [suite_id: long, Suite_Status: char]
Edge-A [sequence_num: int]
Edge-B [ sequence_num: int, suite_status: char]
顶点与边的关系:
Request----EdgeA----Test-B
Request----EdgeB----TestSuite
TestSuite----EdgeC----Test-B
以下查询按升序排序(submit_time 来自请求)并将显示 TestSuite 详细信息:
g.V().order().by("submit_time",incr).outE("Edge-B").
has("suite_status","Q").inV().valueMap()
这是一个示例图:
rj1=graph.addVertex(label,"request","req_id",1138,"status","S","priority",3,"submit_time",1330647978000)
rj2=graph.addVertex(label,"request","req_id",1133,"status","S","priority",2,"submit_time",1330662012000)
rj3=graph.addVertex(label,"request","req_id",1136,"status","S","priority",1,"submit_time",1330652298000)
rj4=graph.addVertex(label,"request","req_id",1135,"status","S","priority",1,"submit_time",1330666768000)
ts1=graph.addVertex(label,"test_suite","test_suite_id",8713)
ts2=graph.addVertex(label,"test_suite","test_suite_id",8718)
ts3=graph.addVertex(label,"test_suite","test_suite_id",8688)
ts4=graph.addVertex(label,"test_suite","test_suite_id",8729)
tb1=graph.addVertex(label,"test_b","tb_id",574)
tb2=graph.addVertex(label,"test_b","tb_id",573)
tb3=graph.addVertex(label,"test_b","tb_id",577)
e1=rj1.addEdge("edgeB",ts1,"sequence",1,"job_suite_status","Q")
e2=rj1.addEdge("edgeB",ts2,"sequence",2,"job_suite_status","Q")
e1=rj2.addEdge("edgeB",ts1,"sequence",1,"job_suite_status","Q")
e2=rj2.addEdge("edgeB",ts3,"sequence",2,"job_suite_status","Q")
e1=rj3.addEdge("edgeB",ts4,"sequence",1,"job_suite_status","Q")
e2=rj3.addEdge("edgeB",ts2,"sequence",2,"job_suite_status","Q")
e1=rj4.addEdge("edgeB",ts3,"sequence",1,"job_suite_status","Q")
e2=rj4.addEdge("edgeB",ts4,"sequence",2,"job_suite_status","Q")
e1=rj1.addEdge("edgeA",tb1,"sequence",1)
e2=rj1.addEdge("edgeA",tb2,"sequence",2)
e3=rj2.addEdge("edgeA",tb1,"sequence",1)
e4=rj2.addEdge("edgeA",tb1,"sequence",2)
e5=rj3.addEdge("edgeA",tb2,"sequence",1)
e6=rj3.addEdge("edgeA",tb3,"sequence",2)
e7=rj4.addEdge("edgeA",tb3,"sequence",2)
e8=rj4.addEdge("edgeA",tb1,"sequence",1)
此处,rj1、rj2、rj4 连接到 tb1(edgeA):
因此,对于每个 test_b(例如:tb_id=574),根据 submit_time 对请求(rj1、rj2、rj4)进行排序,然后取 test_suite_id 和序列。
最后我需要打印test_suite_id,序列,以及对应的req_id。请帮我解决这个问题。谢谢
它有助于用 as()
标记步骤,然后使用 select()
准备结果。
g.V().has("tb_id", 574).
in("edgeA").dedup().as("r").
order().by("submit_time", Order.incr).as("st").
outE("edgeB").has("job_suite_status", "Q").as("s").
inV().as("t").
select("t", "s", "r", "st").
by("test_suite_id").by("sequence").by("req_id").by("submit_time")
从tb_id574的测试开始,然后遍历到它的requests(标记为r
),按提交时间排序(标记为st
),遍历到序列(标记为s
),最后遍历到测试套件(标记为t
)。
使用 select()
准备结果输出并使用 by()
选择属性:测试套件、序列、请求和提交时间。
每个顶点和边具有以下属性:
Request [req_id: long, submit_time:long, priority:int, status:char]
Test_B [tb_id: long, tb_name: string]
TestSuite [suite_id: long, Suite_Status: char]
Edge-A [sequence_num: int]
Edge-B [ sequence_num: int, suite_status: char]
顶点与边的关系:
Request----EdgeA----Test-B
Request----EdgeB----TestSuite
TestSuite----EdgeC----Test-B
以下查询按升序排序(submit_time 来自请求)并将显示 TestSuite 详细信息:
g.V().order().by("submit_time",incr).outE("Edge-B").
has("suite_status","Q").inV().valueMap()
这是一个示例图:
rj1=graph.addVertex(label,"request","req_id",1138,"status","S","priority",3,"submit_time",1330647978000)
rj2=graph.addVertex(label,"request","req_id",1133,"status","S","priority",2,"submit_time",1330662012000)
rj3=graph.addVertex(label,"request","req_id",1136,"status","S","priority",1,"submit_time",1330652298000)
rj4=graph.addVertex(label,"request","req_id",1135,"status","S","priority",1,"submit_time",1330666768000)
ts1=graph.addVertex(label,"test_suite","test_suite_id",8713)
ts2=graph.addVertex(label,"test_suite","test_suite_id",8718)
ts3=graph.addVertex(label,"test_suite","test_suite_id",8688)
ts4=graph.addVertex(label,"test_suite","test_suite_id",8729)
tb1=graph.addVertex(label,"test_b","tb_id",574)
tb2=graph.addVertex(label,"test_b","tb_id",573)
tb3=graph.addVertex(label,"test_b","tb_id",577)
e1=rj1.addEdge("edgeB",ts1,"sequence",1,"job_suite_status","Q")
e2=rj1.addEdge("edgeB",ts2,"sequence",2,"job_suite_status","Q")
e1=rj2.addEdge("edgeB",ts1,"sequence",1,"job_suite_status","Q")
e2=rj2.addEdge("edgeB",ts3,"sequence",2,"job_suite_status","Q")
e1=rj3.addEdge("edgeB",ts4,"sequence",1,"job_suite_status","Q")
e2=rj3.addEdge("edgeB",ts2,"sequence",2,"job_suite_status","Q")
e1=rj4.addEdge("edgeB",ts3,"sequence",1,"job_suite_status","Q")
e2=rj4.addEdge("edgeB",ts4,"sequence",2,"job_suite_status","Q")
e1=rj1.addEdge("edgeA",tb1,"sequence",1)
e2=rj1.addEdge("edgeA",tb2,"sequence",2)
e3=rj2.addEdge("edgeA",tb1,"sequence",1)
e4=rj2.addEdge("edgeA",tb1,"sequence",2)
e5=rj3.addEdge("edgeA",tb2,"sequence",1)
e6=rj3.addEdge("edgeA",tb3,"sequence",2)
e7=rj4.addEdge("edgeA",tb3,"sequence",2)
e8=rj4.addEdge("edgeA",tb1,"sequence",1)
此处,rj1、rj2、rj4 连接到 tb1(edgeA): 因此,对于每个 test_b(例如:tb_id=574),根据 submit_time 对请求(rj1、rj2、rj4)进行排序,然后取 test_suite_id 和序列。
最后我需要打印test_suite_id,序列,以及对应的req_id。请帮我解决这个问题。谢谢
它有助于用 as()
标记步骤,然后使用 select()
准备结果。
g.V().has("tb_id", 574).
in("edgeA").dedup().as("r").
order().by("submit_time", Order.incr).as("st").
outE("edgeB").has("job_suite_status", "Q").as("s").
inV().as("t").
select("t", "s", "r", "st").
by("test_suite_id").by("sequence").by("req_id").by("submit_time")
从tb_id574的测试开始,然后遍历到它的requests(标记为r
),按提交时间排序(标记为st
),遍历到序列(标记为s
),最后遍历到测试套件(标记为t
)。
使用 select()
准备结果输出并使用 by()
选择属性:测试套件、序列、请求和提交时间。