Assuring Label Validity

Assuring a Label's "integrity"

Hi,
I am looking for a Best Practice to solve the follwing case:
Assume I have a graph with student nodes, each with the ususal attributes (name,birth date,gender,height...).
Some of the students have an attribute "plays", which has the value of the musical instrument (Assume ONE) he/she plays.
I add a Label "Musician" by running

match (a: Student) where a.plays <> "" set a:Musician

Now I can perform queries on musicians only:

match (a:Musician) return avg(a.height)

Nice and good - at the point in time this statement is run.

NOW!

Assume a non-musician took up an instrument, or a new student comes to school - a Node should be either added or upadated.
I will have to assure the test for "plays", and the validity of the "Musician" label, is done.
How can I GUARANTEE it?
I can have an adminstrative rule that updates are done only through a single procedure - but then I may be at the mercy of the worst "I am in a hurry" privileged user.
What can I do so the modification/update ALWAYS performs the test (in SQL, you would do that with a Trigger) ?

Thanks,

Shalom Elkin
I S R A E L

Hi @shalom.elkin,

If you are good to update existing nodes and only worrying new insertion then I suggest to methods.
Single query: Try Conditionally create or merge a node

Multiple Query: LOAD CSV WITH HEADERS Relationship

Vivek, Hi
This was very Fast...

Thanks for the answer. Alas, it shows a way to preserve the integrity of the label, but not how to guarantee it (again, think SQL triggers). If somebody just does a CREATE STUDENT , or large LOAD CSV, without knowing about the "musician" label - integrity is gone: I will have (multiple?) students that are, indeed, musicians - without the Label.
I will keep looking.

Thanks again,

Shalom Elkin

Hi Shalom,

Sorry I did not understand your concern.
When you are ingesting new records you need to check your CSV (if it has column header for musician). If it has value then add the code under two labels else just under Student.
It will be good if you show us snippet of your ingestion data. and explain with example.

Regards
Vivek

Vivek, Hi

Thanks for your interest.

Of course I could do

create (x: student : Musician {Name:Tom,plays:”flute”};

The trivial students and Musician scenario is just a simplification I made up to illustrate a point that “hurts” me in a real-life system.

This assumes I , and only I, am in complete control of the data store and its changes.

For a play store like the one I presented, this is ok.

I am speaking about a data store that is the basis for an enterprise application, with many people doing – not just queries, but updates. I can’t rely on

“If you do not use this procedure, I’ll fire you” , and hope everybody behaves. I am talking DEFENSIVE PROGRAMMING.

Again and again, think SQL triggers.

Assume you have a relational DB (Assume Oracle) for inventory, and you attach to a table a trigger that says : “When quantity_on_hand goes below reorder_quantity , run the repurchase stored procedure”.

A programmer that writes an application, or a DBA that modifies a record from the SQLPLUS command line, that modifies the Database does not have to even KNOW about the reorder. If the business rules change, The reorder procedure could be modified – in ONE PLACE only –and everything goes on smoothly.

You do not depend on responsible, rule-obeying employees – you AUTOMATE the procedure.

My question is – Does NEO4J have the capability to attach a piece of code to “data” [I can’t be specific here..] So I , as the person who designs the “musician” concept, can be sure the label is automatically attached on update/insert?

Thanks !

Shalom Elkin

Hi Shalom,

Although I feel you might already have visited to the link for triggers in Neo4j which are implemented using apoc, however in case you missed then Please visit http://neo4j-contrib.github.io/neo4j-apoc-procedures/3.5/operational/triggers/.

Regards
Vivek

Vivek, Hi

BRAVO!

This looks as if it is exactly what I was looking for. I Never met it, and was not aware NEO4J had triggers. I hope I will not be disappointed after exploring the topic. Thank you very very much !

Shalom Elkin

Israel

Welcome Sir,

I wish this will resolve your need related to triggers.

Regards
Vivek