2016-09-30 5 views
1

그로 바이 스크립트 또는 tinkerpop 단계를 통해 gremlin 쿼리를 작성하는 가장 좋은 방법은 무엇입니까?gremly 쿼리를 작성하는 가장 좋은 방법은 groovy 스크립트 또는 tinkerpop 단계를 통해 무엇입니까?

예를 들어, 조인 날짜를 기준으로 Employee 레이블로 Vertices 세트를 정렬하려면 다음을 입력하십시오.

더 나은 검색 방법은 무엇입니까?

인가 그것을

g.V().hasLabel('Employee').sort{a,b->a.value('DateOfJoining')<=>b.value('DateOfJoining')} 

또는

g.V().hasLabel('Employee').order().by('DateOfJoining',incr) 
여기

내가 그루비 스크립트에서 나는 tinkerpop에 일반 주문 단계를 사용했습니다 두 번째에 <=> 연산자를 사용했습니다

. 기초 그래프 데이터베이스를 해석 할 수 있기 때문에,

모두 쿼리 놈아 콘솔에서 작동하지만 그들 중 어느 하나는 검색에 가장 적합하는 방법 놈아 콘솔은 모두 쿼리

답변

3

groovy collection methods을 피하기 위해 더 나은 해석 않습니다. 그들은 Traversal 밖에 존재합니다. 당신이 explain() 작업을 수행 할 때

gremlin> g.V().hasLabel("person").order().by('name',incr).explain() 
==>Traversal Explanation 
=============================================================================================================================== 
Original Traversal     [GraphStep(vertex,[]), HasStep([~label.eq(person)]), OrderGlobalStep([[value(name), incr]])] 

ConnectiveStrategy   [D] [GraphStep(vertex,[]), HasStep([~label.eq(person)]), OrderGlobalStep([[value(name), incr]])] 
RepeatUnrollStrategy   [O] [GraphStep(vertex,[]), HasStep([~label.eq(person)]), OrderGlobalStep([[value(name), incr]])] 
InlineFilterStrategy   [O] [GraphStep(vertex,[]), HasStep([~label.eq(person)]), OrderGlobalStep([[value(name), incr]])] 
MatchPredicateStrategy  [O] [GraphStep(vertex,[]), HasStep([~label.eq(person)]), OrderGlobalStep([[value(name), incr]])] 
PathRetractionStrategy  [O] [GraphStep(vertex,[]), HasStep([~label.eq(person)]), OrderGlobalStep([[value(name), incr]])] 
IncidentToAdjacentStrategy [O] [GraphStep(vertex,[]), HasStep([~label.eq(person)]), OrderGlobalStep([[value(name), incr]])] 
AdjacentToIncidentStrategy [O] [GraphStep(vertex,[]), HasStep([~label.eq(person)]), OrderGlobalStep([[value(name), incr]])] 
FilterRankingStrategy  [O] [GraphStep(vertex,[]), HasStep([~label.eq(person)]), OrderGlobalStep([[value(name), incr]])] 
RangeByIsCountStrategy  [O] [GraphStep(vertex,[]), HasStep([~label.eq(person)]), OrderGlobalStep([[value(name), incr]])] 
TinkerGraphStepStrategy  [P] [TinkerGraphStep(vertex,[~label.eq(person)]), OrderGlobalStep([[value(name), incr]])] 
ProfileStrategy    [F] [TinkerGraphStep(vertex,[~label.eq(person)]), OrderGlobalStep([[value(name), incr]])] 
StandardVerificationStrategy [V] [TinkerGraphStep(vertex,[~label.eq(person)]), OrderGlobalStep([[value(name), incr]])] 

Final Traversal     [TinkerGraphStep(vertex,[~label.eq(person)]), OrderGlobalStep([[value(name), incr]])] 

, 당신은 Traversal이 기본 그래프 데이터베이스에 어떻게 보이는지 볼 수 있습니다 : 당신처럼이 예를 생각해 보자. 이 경우 데이터베이스가 order()에서 최적화 할 수 있다면이를 활용하여 더욱 효율적으로 사용할 수 있습니다. 단순히 g.V().hasLabel("person")을 제출하고 그루비 수집 방법으로 전환했다면, 기본 데이터베이스는 "사람"정점 목록을 얻으 려하고 자신을 주문하려고했는지 알지 못합니다. 그루비의 사용 sort).