bitnine-oss / agensgraph

AgensGraph, a transactional graph database based on PostgreSQL
http://www.agensgraph.org
Other
1.34k stars 148 forks source link

questions about agensgraph #256

Closed candysmurf closed 6 years ago

candysmurf commented 7 years ago

Only a couple of questions now and I'll have more questions to follow. thanks.

johnberzy-bazinga commented 6 years ago

@candysmurf

The following query works for me :

CREATE VLABEL Person;

MERGE (p:Person {email : 'john@example.com'})
ON CREATE SET p.created = true
ON MATCH SET p.merged = true
RETURN p.email, p.created, p.merged;

Also, if you need to ensure no duplicates, you can add a unique property index CREATE UNIQUE PROPERTY INDEX ON Person (email);

candysmurf commented 6 years ago

@johnberzy-bazinga, thanks for the quick response. What I found is that if all properties for a person is identical, MERGE won't create a new one, when one of the properties is different, MERGE creates a new one although the Java object equal method only specified ID is the determining fact of two objects equality.

If I create the unique index, will it throw an exception if the same ID used with different property value? I would like the intelligence of agensgraph to know if ID exists, update it, otherwise create it. Is it possible?

johnberzy-bazinga commented 6 years ago

@candysmurf I don't think it works like that. If I'm not mistaken, you'll need to set the non-unique properties in the ON CREATE/MATCH SET clauses.

candysmurf commented 6 years ago

@johnberzy-bazinga, do you have an update operation example? If I have many properties, do I need to set all of them one by one? Why can agensgraph just update the node?

Did you mean that I need to make multiple DB calls? first is to find if it exists, if it exists, update, otherwise create?

johnberzy-bazinga commented 6 years ago

Did you mean that I need to make multiple DB calls? first is to find if it exists, if it exists, update, otherwise create?

No, because that would defeat the purpose of Merge.

You could do something like this I think :

MERGE (p:Person {id : 'john@example.com'})
SET p += {age : 23}
RETURN p; 
candysmurf commented 6 years ago

@johnberzy-bazinga, the input is an object. I don't know which field/property is changed unless I get the one inside DB out and compare them. Any other way to do an object update?

If I add the ID unique constraint, will MERGE does what I want?

johnberzy-bazinga commented 6 years ago

@candysmurf

If I understand you correctly, what you want to do is merge based on the unique id, and append all the additional properties of your input object, correct? In that case, what I sent should work. I'm not sure what driver you're using, but you should be able to parameterize the query to accept the input object. i.e.

MERGE (p:Person {id : 'john@example.com'})
SET p += ?
RETURN p; 
candysmurf commented 6 years ago

@johnberzy-bazinga, not necessarily adding a new property but update a few existing properties, example query, please. thanks

candysmurf commented 6 years ago

@johnberzy-bazinga, yes the query you gave worked except I removed the + sign. Than you very much for your help!

johnberzy-bazinga commented 6 years ago

@candysmurf Without the += operator you'll completely replace the existing properties instead of merging them.

candysmurf commented 6 years ago

@johnberzy-bazinga, ah, you meant the merge is a better operation. Thanks for the tip. I'm using += operation now.

candysmurf commented 6 years ago

@gtyun & @johnberzy-bazinga, thanks for all your help. Our demo went very well. Everything worked nicely. I'm going to close this issue and open a new one to a couple more questions.

pratikpparikh commented 6 years ago

@candysmurf did you create a docker swarm configuration for your experiment? If so can you please share?