2017-04-26 58 views
1

每個頂點和邊具有以下屬性:在TitanDB排序與的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),排序請求(rj1,rj2,rj4)基於submit_time並採取test_suite_id和序列。

最後,我需要打印test_suite_id,順序及相應的REQ_ID。請幫我解決這個問題。謝謝。

+0

你能否提供一些節點和預期結果的例子? –

+0

@cattani我已經更新了樣本數據的問題..你可以幫我解決這個問題。 – User12345

+1

遍歷似乎不適用於您的示例數據。 –

回答

1

它有助於標記步驟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_id 574測試開始,然後遍歷到其請求(標籤作爲r),命令由提交時間(標籤作爲st),橫向於序列(標籤作爲s)的請求,最後橫動到測試套件(標籤爲t)。

使用select()來準備結果輸出和by()來選擇屬性:測試套件,序列,請求和提交時間。