Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow UPSERT of Edges #4436

Closed
Bandes opened this issue Jun 23, 2015 · 34 comments
Closed

Allow UPSERT of Edges #4436

Bandes opened this issue Jun 23, 2015 · 34 comments
Assignees
Milestone

Comments

@Bandes
Copy link

Bandes commented Jun 23, 2015

Currently, UPSERT can only handle vertices. For my purposes, I would like/need to be able to upsert edges as well.

@wolf4ood wolf4ood self-assigned this Jun 23, 2015
@bomgar
Copy link

bomgar commented Sep 21, 2015

👍 would also like to see this

parkan referenced this issue in mediachain/L-SPACE Apr 7, 2016
several changes here:
- addImageBlob and addPerson now return the  `Vertex` for the added
  blob and the added `Canonical`, wrapped in a case class called
  `AddBlobResult` (could use a rename).

  This is needed because just returning the `Canonical` would require
  querying for the canonical's `Vertex` if we want to reference it,
  and that query will fail if the transaction is uncommitted.

- uses of `Vertex.lift` are wrapped in try/catch blocks to catch the
  `OStorageException` that will be thrown if the vertex does not
  already exist.

- The `addPerson` and `addImageBlob` both call through to a generic
  `addMetadataBlob` function, which will query for existing blob
  and canonical, or add blob & create canonical if none exists
@justinkillen
Copy link

+1

3 similar comments
@amyth
Copy link

amyth commented May 23, 2016

+1

@kubz
Copy link

kubz commented Jun 28, 2016

+1

@strohni
Copy link

strohni commented Oct 7, 2016

+1

@suyogdilipkale
Copy link

I am able to upsert for edge class with following syntax:

UPDATE LikeComment SET out = #21:21, in = #20:20 UPSERT WHERE out = #21:21 and in = #20:20

But When I select source vertex like SELECT FROM #21:21 it does not show me that out edge in result.

@karolmie1
Copy link

This, if implemented, would support queries like this (multiple edges creation):

UPDATE EDGE hasAssignee FROM ( SELECT FROM Project WHERE id=:id ) TO ( SELECT FROM User WHERE login in :login ) UPSERT

Am I right?

@xSpoooK
Copy link

xSpoooK commented Apr 21, 2017

+1

@zeeshan2709
Copy link

hey,
I am using
update has SET out=#20:16, in=#14:18 UPSERT WHERE out = #14:18 and in = #20:16
It does not create the edge if not present. Is this feature not yet implemented. If not, can you suggest any workaround for this.
usecase is to create edge only if it does not exist.

@karolmie1
Copy link

I guess in meantime the good ol' if statement have to suffice

@grindhold
Copy link

+1

@lvca lvca added this to the 3.1 milestone Aug 3, 2017
@lightjiao
Copy link

+1

@undecided2013
Copy link

+1, this would be great

@micha-heigl
Copy link

+1

@thenerdnest
Copy link

+1

5 similar comments
@timobanion
Copy link

+1

@gauravssFlipkart
Copy link

+1

@triketora
Copy link

+1

@WalterInSH
Copy link

+1

@feiYH
Copy link

feiYH commented Mar 5, 2018

+1

@grzegorz-aniol
Copy link

+1
I'm really surprised this feature is not available yet in orientdb. How people deal with this problem during cyclic update/import data??

@bernierm
Copy link

bernierm commented Mar 9, 2018

Going on three years now. I personally dealt with this by using something instead of OrientDb.

@david-sitsky
Copy link

+1. This is a really important feature for us if OrientDB is to be used in a real-world / real-time mass graph database application.

Can't you give us users any indication if this is being considered? Otherwise we'll keep moving to other options.

@karolmie1
Copy link

I mean this is open source, everybody can make a pull request, you know 😁

@luigidellaquila
Copy link
Member

Hi guys,

Let me give some context here.
We consider this as an important feature, we really would like to have an easy and performant way to implement it, but unfortunately we still don't have one.

A consistent UPSERT is based on the assumption that you have a way to detect duplicates. Now, we have unique indexes for this in OrientDB, so we could define a unique index on E(out, in).

There are a few problems in this approach though:

  1. an index requires a schema, right now E class does not have a schema for the properties out and in. There is a good reason for this: in some cases you need your edges to define out and in as links to a specific type (eg. you want FriendOf.out to be LINK Person, just to avoid creation of friendship relationships that point to something other than people). Many of our customers and OSS users already rely on edge schema, so we cannot break it
  2. as long as you have a uniqueness violation mechanism in place, using it in TX is easy, but implementing it in NoTx is a bit more complex and requires some time and patience.
  3. having an additional index on edges by default will result in a slowdown at insertion time, that is not reasonable in general, especially for use cases where you don't need UPSERT at all

Of course this is an open discussion, so if you have any ideas or suggestions on how to implement it in a different ways, we are open to take it into consideration (and we would appreciate it a lot)

Thanks

Luigi

@lvca
Copy link
Member

lvca commented Mar 22, 2018

I have a simple and quick solution to this: without breaking anything, what if we create the UPSERT EDGE command, but it throws an exception if there is no unique index? In this way, users that want the UPSERT EDGE must create an index first. We can put this in documentation and in the exception.

WDYT?

@luigidellaquila
Copy link
Member

Well... why not? We can definitely go with this approach

Thanks

Luigi

@bjornarl
Copy link

bjornarl commented Mar 22, 2018

Thank you both for the additional details on this topic.
I believe Luca's suggestion would work for us -- I was going to ask about that possibility, as we already have an added edge column that has a unique index. It would be great if it could work in a NoTx scenario, though I understand from Luigi's point 2 that that might be more involved to handle.

@david-sitsky
Copy link

That approach sounds perfect - thank you!

@v1nsai
Copy link

v1nsai commented Apr 17, 2018

+1 This would really improve the system as I think preventing creation of duplicates is one of the more basic functions we're all going to deal with. We can use multiple queries but this quickly creates lots of extra overhead.

@luigidellaquila
Copy link
Member

Hi all,

I just implemented this feature and pushed the enhancement to develop branch. This will be released with v 3.0.1.

I think this is the most voted enhancement in the history of OrientDB, thank you all for helping to find the best solution for this.

Thanks

Luigi

@luigidellaquila
Copy link
Member

Little note: as discussed above, for new the UPSERT only works in the case you have a UNIQUE index on EdgeClass[out,in]

Thanks

Luigi

@luigidellaquila luigidellaquila modified the milestones: 3.1, 3.0.1 May 8, 2018
@gtadudeps
Copy link

gtadudeps commented Jul 16, 2018

Hi I am trying to implement this new upsert edge feature available with v3.0.3 but getting exception com.orientechnologies.orient.core.exception.OCommandExecutionException: Error updating edge: 'out' is not a vertex. I have created a class Person with Name field as unique index and Friend with field id as unique index. Command issued : update edge Friend set in = (select from Person where Name = 'name1' ) , out = ( select from Person where Name = 'name2') , id = 'f1' upsert where id = 'f1'. Please let me know if I am using this correctly. Thanks!

@mebibou
Copy link

mebibou commented May 21, 2020

@luigidellaquila could it be documented anywhere how to create a unique index on EdgeClass[out,in] for the UPSERT to work? I've been at this for days and still can't find a way to do this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests