Wolfgang-Schuetzelhofer / jcypher

Java access to Neo4J graph databases at multiple levels of abstraction
Apache License 2.0
86 stars 15 forks source link

RETURN.DISTINCT() maybe should be RTerminal? #42

Open DonCziken opened 6 years ago

DonCziken commented 6 years ago

Hi Wolfgang,

I am wondering if RETURN.DISTINCT() shouldn't be actually a RTerminal. The reasons behind such logic are following:

  1. What is there currently kinda suggests that distinction would apply only to one given return value i.e.

    RETURN.DISTINCT().value(n.id()).AS(id),
    RETURN.value(n.property("name")).AS(name),
    RETURN.value(m.labels()).AS(labels)

    but in fact it does apply to all records which are returned from neo4j, which are than translated into jcypher collections.

  2. Another case is that in case of building cypher queries dynamically in some cases it could be usefull to do:

    clasuses.add(RETURN.DISTINCT());
    if(some_condition) {
    clasuses.add(RETURN.value(m.id()).AS(id));
    }
    clasuses.add(RETURN.value(n.id()).AS(id));

    instead of:

    if(some_condition) {
    clasuses.add(RETURN.DISTINCT().value(m.id()).AS(id));
    clasuses.add(RETURN.value(n.id()).AS(id));
    } else {
    clasuses.add(RETURN.value(n.id()).AS(id));
    }
Wolfgang-Schuetzelhofer commented 6 years ago

Hi Krzysztof,

if you do the following:

RETURN.DISTINCT().value(n.id()).AS(id),
SEPARATE.nextClause(),
RETURN.value(n.property("name")).AS(name),
RETURN.value(m.labels()).AS(labels)

two returns are created, only the first with distinct like:

RETURN DISTINCT id(n) AS id
RETURN n.name AS name, labels(m) AS labels

Generally, JCypher combines two ore more successive clauses of the same type into one cypher clause. Like two or more successive JCypher RETURN clauses are combined to one cypher RETURN statement.

If you don't want this behaviour, you can use a

SEPARATE.nextClause(),

in between (like shown above).

I hope that helps, best regards, Wolfgang

DonCziken commented 6 years ago

Hi Wolfgang,

thanks for reply, my question was a bit more about considering of being able to do:

RETURN.DISTINCT(),
RETURN.value(n.property("name")).AS(name),
RETURN.value(m.labels()).AS(labels)

also using this thread for slight off top:

Generally, JCypher combines two ore more successive clauses of the same type into one cypher clause.

Is there any reason that such approach is not applied to WHERE so i.e. anding following WHERE defined in give clauses list.

cheers, Krzysztof