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.

Java put quotes in cypher query

pavloN
Node Clone

Tried to put quotes in a query. Because I use one procedure inside another, I need to use quotes with variable fileName.

There is the error:
"Failed to invoke procedure apoc.periodic.iterate: Caused by: org.neo4j.cypher.ParameterNotFoundException: Expected parameter(s): fileName"

The query:

@Query("CALL apoc.periodic.iterate('\n" +
            "    CALL apoc.load.json(\\\"{fileName}\\\") YIELD value as v RETURN v'\n" +
            "    ,'\n" +
            "    FOREACH ( i in CASE WHEN v.cat=true THEN [1] ELSE [] END | MERGE (c:C{id:v.id, version: {version}}))\n" +
            "    FOREACH ( i in CASE WHEN v.dog=true THEN [1] ELSE [] END | MERGE (c:Ca{id:v.id, version: {version}}))\n" +
            "    WITH v\n" +
		...
    void p(@Param("fileName") String fileName, @Param("version") String version);

I have tried several options:
{fileName}
\"{fileName}\"
"{fileName}"

But they don't work. How could I fix it?

This query works and parameter fileName is correct:
    @Query("CALL apoc.load.json({fileName} ) YIELD value as v \n" +
            "MERGE(c:C{name:v.id})\n" +
            "RETURN v.id")
    void p(@Param("fileName") String fileName);
1 REPLY 1

Using apoc.periodic.iterate you have to externally passing in a map of params, as shown at the end of the second last line. The following example works for me:

@Query(
    "CALL apoc.periodic.iterate('\n" +
    "    CALL apoc.load.csv({ url }) yield map as row return row\n" +
    "','\n" +
    "    CREATE (record:Record) SET record = row\n" +
    "', {batchSize:10000, iterateList:true, parallel:true, params:{url:{url}}});\n")
void loadCsvData(@Param("url") String url);