[ 
https://issues.apache.org/jira/browse/TINKERPOP-479?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16061050#comment-16061050
 ] 

Robert Dale commented on TINKERPOP-479:
---------------------------------------

Just for fun, I benchmarked the two and coalesce has a slight edge due to the 
fewer steps required.

Where vertex doesn't exist:
{noformat}
gremlin> clock(100000) {g.V().drop().iterate(); 
g.V().inject(1).coalesce(__.V().has('person','name','stephen'), 
__.addV('person').property('name','stephen')).iterate()}
==>0.03069627463

gremlin> clock(100000) {g.V().drop().iterate(); 
g.V().has('person','name','stephen').aggregate('a').count().choose(__.is(gt(0)),__.cap('a').unfold(),__.addV('person').property('name','stephen')).iterate()}
==>0.05333916768
{noformat}

Where vertex exists:
{noformat}
gremlin> clock(100000) 
{g.V().inject(1).coalesce(__.V().has('person','name','stephen'), 
__.addV('person').property('name','stephen')).iterate()}
==>0.02449548905

gremlin> clock(100000) 
{g.V().has('person','name','stephen').store('a').count().choose(__.is(gt(0)),__.cap('a').unfold(),__.addV('person').property('name','stephen')).iterate()}
==>0.04565527429
{noformat}



> Consider Providing "getOrCreate" Functionality
> ----------------------------------------------
>
>                 Key: TINKERPOP-479
>                 URL: https://issues.apache.org/jira/browse/TINKERPOP-479
>             Project: TinkerPop
>          Issue Type: Improvement
>          Components: structure
>    Affects Versions: 3.0.2-incubating
>            Reporter: stephen mallette
>
> One of the most commonly written functions used is good ol' "getOrCreate" 
> where you want to get a {{Vertex}} if it exists or create it with supplied 
> properties if it does not.  We currently have a "helper" function for this on 
> {{ElementHelper}} 
> https://github.com/tinkerpop/tinkerpop3/blob/6d0f00865f673cb0739f6f310e1868425f732924/gremlin-core/src/main/java/com/tinkerpop/gremlin/structure/util/ElementHelper.java#L62
> but perhaps it is time to treat this issue as a first class citizen as part 
> of the Graph API.  I think that some vendors might actually be able to 
> optimize this function as well.  
> Another aspect of "getOrCreate" is "upsert" as well as options to ensure 
> uniqueness.  All of these things we've at some point or another built 
> variations of outside of TinkerPop for applications, data loading, etc.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to