cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Invalid input '.': expected an identifier character, whitespace, '|', a length specification, a property map or ']'

Hello,

executing below query I'm receiving an error:

Query:

    @Query(   "call apoc.periodic.iterate("
            + "\"UNWIND $items as item return item\" , "
            + "\"MERGE (s1:s{id:item.customId}) "
            + "WITH s1 "
            + "MERGE (e1:e{id:item.customId}) "
            + "MERGE (s1)-[r:item.type]->(e1) "
            + "SET r.id=item.customId, r.name=item.name\", "
            + "{batchSize:5, parallel:true, iterateList:true,params:{items:$itemss}})")
    Result saveAll2(@Param("itemss") List<OrchestraRelationship> items);

Error:

Invalid input '.': expected an identifier character, whitespace, '|', a length specification, a property map or ']' (line 1, column 140 (offset: 139))
"UNWIND $_batch AS _batch WITH _batch.item AS item  MERGE (s1:s{id:item.customId}) WITH s1 MERGE (e1:e{id:item.customId}) MERGE (s1)-[r:item.type]->(e1) SET r.id=item.customId, r.name=item.name"
                                                                                                                                            ^

The relation type should come from a parameter because I'm building lots of relations, i.e. dynamic relation type.
Said that I tried to put a static relation name but received also an error:

Query:

    @Query(   "call apoc.periodic.iterate("
            + "\"UNWIND $items as item return item\" , "
            + "\"MERGE (s1:s{id:item.customId}) "
            + "WITH s1 "
            + "MERGE (e1:e{id:item.customId}) "
            + "MERGE (s1)-[r:BORA]->(e1) "
            + "SET r.id=item.customId, r.name=item.name\", "
            + "{batchSize:5, parallel:true, iterateList:true,params:{items:$itemss}})")
    Result saveAll2(@Param("itemss") List<OrchestraRelationship> items);

Error:

                                                                                                                                            Variable `item` not defined (line 1, column 106 (offset: 105))
"UNWIND $_batch AS _batch WITH _batch.item AS item  MERGE (s1:s{id:item.customId}) WITH s1 MERGE (e1:e{id:item.customId}) MERGE (s1)-[r:BORA]->(e1) SET r.id=item.customId, r.name=item.name"
                                                                                                          ^ -> {Long@9015} 1

Hope someone can advise regards.

Thanks,
Boris

1 ACCEPTED SOLUTION

Oh sorry, it's YIELD rel rather than YIELD relationship

View solution in original post

5 REPLIES 5

You can't create a relationship with a dynamic type in plain cypher. To do this you'll have to use apoc.merge.relationship instead.

@Query(   "call apoc.periodic.iterate("
            + "\"UNWIND $items as item return item\" , "
            + "\"MERGE (s1:s{id:item.customId}) "
            + "WITH s1 "
            + "MERGE (e1:e{id:item.customId}) "
            + "CALL apoc.merge.relationship(s1, item.type, {id: item.customId, name: item.name}, {}, e1) YIELD relationship AS r RETURN *\", "
            + "{batchSize:5, parallel:true, iterateList:true,params:{items:$itemss}})")

Hi @adam.cowley,
first of all, thanks for the answer.

I modified the query to be as follows:

    @Query(   "call apoc.periodic.iterate("
            + "\"UNWIND $items as item return item\" , "
            + "\"MERGE (s1:s{id:item.customId}) "
            + "WITH s1, item "
            + "MERGE (e1:e{id:item.customId}) "
            + "WITH s1, e1, item "
            + "CALL apoc.merge.relationship(s1, item.type, {id: item.customId, name: item.name}, {}, e1) YIELD relationship AS r RETURN *\", "
            + "{batchSize:5, parallel:true, iterateList:true,params:{items:$itemss}})")
    Result saveAll4(@Param("itemss") List<?> items);

But I'm experiencing the following error:

Unknown procedure output: `relationship` (line 1, column 258 (offset: 257))
"UNWIND $_batch AS _batch WITH _batch.item AS item  MERGE (s1:s{id:item.customId}) WITH s1, item MERGE (e1:e{id:item.customId}) WITH s1, e1, item CALL apoc.merge.relationship(s1, item.type, {id: item.customId, name: item.name}, {}, e1) YIELD relationship AS r RETURN *"

I ran the command CALL dbms.procedures() and verified that apoc.merge.relationship exists.

What else can it be?

Oh sorry, it's YIELD rel rather than YIELD relationship

Thanks, @adam.cowley, this actually helped.
Maybe you can also help with this related thing:

Each time I'm executing the query

    @Query(   "call apoc.periodic.iterate("
            + "\"UNWIND $items as item return item\" , "
            + "\"MERGE (s1:s{id:item.startNode.customId}) "
            + "WITH s1, item "
            + "MERGE (e1:e{id:item.endNode.customId}) "
            + "WITH s1, e1, item "
            + "CALL apoc.merge.relationship(s1, item.type, {id: item.customId, name: item.name}, {}, e1) YIELD rel AS r RETURN *\", "
            + "{batchSize:5, parallel:true, iterateList:true,params:{items:$itemss}})")
    Result saveAll4(@Param("itemss") List<?> items);

It creates the desired relation but each time new nodes ((s) and (e)) are being created.
My flow is firstly inserted all the nodes, then create the relations according to some kind of mapping file between the nodes. If I want to write it as the simplest Cypher query (without apoc) then it'll look something like the following:

"MATCH (s),(e) " +
"WHERE s.id = '%s' AND e.id = '%s' " +
"CREATE UNIQUE (s)-[r:%s]->(e) " +
"SET r.id='%s', r.name='%s' ";

Therefore, I tried to modify the query to this:

    @Query(   "call apoc.periodic.iterate("
            + "\"UNWIND $items as item return item\" , "
            + "\"MERGE (s1:item.startNodeType.name{id:item.startNode.customId}) "
            + "WITH s1, item "
            + "MERGE (e1:item.endNodeType.name{id:item.endNode.customId}) "
            + "WITH s1, e1, item "
            + "CALL apoc.merge.relationship(s1, item.type, {id: item.customId, name: item.name}, {}, e1) YIELD rel AS r RETURN *\", "
            + "{batchSize:5, parallel:true, iterateList:true,params:{items:$itemss}})")
    Result saveAll4(@Param("itemss") List<?> items);

I.e. in order to prevent creating the same nodes each time, I'm specifying their type.
But this yield an error:

Invalid input '.': expected an identifier character, whitespace, NodeLabel, a property map, ')' or a relationship pattern (line 1, column 66 (offset: 65))
"UNWIND $_batch AS _batch WITH _batch.item AS item  MERGE (s1:item.startNodeType.name{id:item.startNode.customId}) WITH s1, item MERGE (e1:item.endNodeType.name{id:item.endNode.customId}) WITH s1, e1, item CALL apoc.merge.relationship(s1, item.type, {id: item.customId, name: item.name}, {}, e1) YIELD rel AS r RETURN *"
                                                                  ^ -> {Long@9064} 1

Note:
I tried to replace MERGE with MATCH but it doesn't work (even thought conceptually this what I desire it to do).

Any thoughts?

Never-mind, I managed to modify the query so it won't create each time the nodes (s),(e).
This is the query:

    @Query(   "call apoc.periodic.iterate("
            + "\"UNWIND $items as item return item\" , "
            + "\"MATCH (s) "
            + "WHERE s.id=item.startNode.customId "
            + "WITH s, item "
            + "MATCH (e) "
            + "WHERE e.id=item.endNode.customId "
            + "WITH s, e, item "
            + "CALL apoc.merge.relationship(s, item.type, {id: item.customId, name: item.name}, {}, e) YIELD rel AS r RETURN *\", "
            + "{batchSize:15, parallel:true, iterateList:true,params:{items:$itemss}})")
    Result saveAll4(@Param("itemss") List<?> items);