cancel
Showing results for 
Search instead for 
Did you mean: 

Query seems to not execute properly. Is it an issue?

mv59_grid
Node Link

Hello there,

I am executing queries which seems to behave weird.
The queries i am executing is this one : 

 

MATCH(nodea0:HypoComplexe:DOPLER:Maquette:ImportXML{id:'62c6df857aeb04026be826069df0faa67236a7d7d10a6b848fc66acf4b7ab7ab'})
CALL apoc.periodic.iterate(
  " WITH $matchchilds AS matchchilds UNWIND matchchilds as matchchild RETURN matchchild",
  " MATCH(nodeb:Hypothese:DOPLER:Maquette:ImportXML{id:matchchild.params1_id})  
    MERGE (nodea0)-[rel0:CONTAINS]->(nodeb) ",
{batchSize:1000, parallel:false,params:{matchchilds: $matchchilds}}
) 
YIELD batch, operations  
RETURN batch ,operations , nodea0

 

The query runs fine  with this output :

 

[
    Record {
      keys: [ 'batch', 'operations', 'nodea0' ],
      length: 3,
      _fields: [
        {
          total: Integer { low: 6, high: 0 },
          committed: Integer { low: 6, high: 0 },
          failed: Integer { low: 0, high: 0 },
          errors: {}
        },
        {
          total: Integer { low: 5732, high: 0 },
          committed: Integer { low: 5732, high: 0 },
          failed: Integer { low: 0, high: 0 },
          errors: {}
        },
        Node {
          identity: Integer { low: 173480, high: 0 },
          labels: [ 'DOPLER', 'Maquette', 'ImportXML', 'HypoComplexe' ],
          properties: {
            Attr_dtCreation: "'13/10/2022 14:14'",
            Attr_description: "''",
            nameUser: "''",
            Attr_createur: "'gsradm'",
            name: "'Etat 9'",
            Attr_nom: "'Etat '",
            id: '62c6df857aeb04026be826069df0faa67236a7d7d10a6b848fc66acf4b7ab7ab',
            Attr_type: "'20'",
            Attr_dtModif: "'13/10/2022 14:14'",
            Attr_xmlns: "'http://www.*****.com/gsr'",
            Attr_xmlns_xsi: "'http://www.w3.org/2001/XMLSchema-instance'"
          },
          elementId: '4:15b97476-e1db-4513-8d0c-610cb672c8ca:173480'
        }
      ],
      _fieldLookup: { batch: 0, operations: 1, nodea0: 2 }
    }
]

 

So nodea0 seems to have been found becaue it is returned in the result. The query has just to MERGE the relation between nodea1 and nodeb list.
nodeb variable is matched through a parameter list with 5732 values.
But in my graph, i am left with an empty node like this linked to each nodeb (it seems that variable nodea1 contains void at execution time) :

mv59_grid_1-1674569369977.png

Expected output is more like : 

mv59_grid_0-1674570258462.png

 

I tried many alternatives without success (i didn't get error though)  :

  • Subquery the apoc procedure with a with clause on nodea0

 

MATCH(nodea0:HypoComplexe:DOPLER:Maquette:ImportXML{id:'62c6df857aeb04026be826069df0faa67236a7d7d10a6b848fc66acf4b7ab7ab'})  
CALL { 
  WITH nodea0 
  CALL apoc.periodic.iterate(
     " WITH $matchchilds AS matchchilds UNWIND matchchilds as matchchild RETURN matchchild",
  " MATCH (nodeb:Hypothese:DOPLER:Maquette:ImportXML{id:matchchild.params1_id})
    MERGE (nodea0)-[rel0:CONTAINS]->(nodeb) ",
  {batchSize:1000, parallel:false,params:{matchchilds: $matchchilds}}
   ) 
   YIELD batch, operations  
   RETURN batch ,operations
} 
RETURN batch,operations, nodea0

 

  • add nodea0 as apoc procedure parameter :

 

MATCH(nodea0:HypoComplexe:DOPLER:Maquette:ImportXML{id:'62c6df857aeb04026be826069df0faa67236a7d7d10a6b848fc66acf4b7ab7ab'})  
CALL { 
   WITH nodea0 
   CALL apoc.periodic.iterate(
      " WITH $matchchilds AS matchchilds UNWIND matchchilds as matchchild RETURN matchchild",
      " MATCH (nodeb:Hypothese:DOPLER:Maquette:ImportXML{id:matchchild.params1_id})  
        MERGE (nodea0)-[rel0:CONTAINS]->(nodeb) ",
      {batchSize:1000, parallel:false,params:{matchchilds: $matchchilds, nodea0:nodea0}}
    ) 
    YIELD batch, operations 
    RETURN batch ,operations 
}
RETURN batch,operations, nodea0

 

What am i doing wrong?

Thank you for your help.

 

 

 

4 REPLIES 4

glilienfield
Ninja
Ninja

Yes, your issues is that you did not pass node nodea0 to the apoc procedure. The node is not available to the second apoc query otherwise. You also can not use a parameter as a node variable in a pattern, thus you need to use a 'with' statement to set the parameter to a variable. The following should work.

MATCH(nodea0:HypoComplexe:DOPLER:Maquette:ImportXML{id:'62c6df857aeb04026be826069df0faa67236a7d7d10a6b848fc66acf4b7ab7ab'})
CALL apoc.periodic.iterate(
  " UNWIND $matchchilds as matchchild 
    RETURN matchchild ",
  " WITH $nodea0 AS nodea0 
    MATCH(nodeb:Hypothese:DOPLER:Maquette:ImportXML{id:matchchild.params1_id})  
    MERGE (nodea0)-[rel0:CONTAINS]->(nodeb) ",
{batchSize:1000, parallel:false,params:{matchchilds: $matchchilds, nodea0: nodea0}}
) 
YIELD batch, operations  
RETURN batch ,operations , nodea0

I tried to modify the query ->

MATCH(nodea0:HypoComplexe:DOPLER:Maquette:ImportXML{id:'633635e8a432b6c6f87f36b93df207491942bb7a0714a791725c70d6d070a5bc'})  
   CALL apoc.periodic.iterate(
     "WITH $matchchilds AS matchchilds UNWIND matchchilds as matchchild RETURN matchchild",
     "WITH $nodea0 AS nodea0
      MATCH(nodeb:Hypothese:DOPLER:Maquette:ImportXML{id:matchchild.params1_id})  
      MERGE (nodea0)-[rel0:CONTAINS]->(nodeb) ",
    {batchSize:1000, parallel:false,params:{matchchilds: $matchchilds, nodea0:nodea0}}
    ) 
YIELD batch, operations
RETURN batch ,operations 


It seems to complain about parameters (query works fine (including parameters) without proposed modifications :

[
    Record {
      keys: [ 'batch', 'operations' ],
      length: 2,
      _fields: [
        {
          total: Integer { low: 6, high: 0 },
          committed: Integer { low: 0, high: 0 },
          failed: Integer { low: 6, high: 0 },
          errors: {
            'org.neo4j.graphdb.QueryExecutionException: Variable `matchchild` not defined (line 1, column 140 (offset: 139))\n"UNWIND $_batch AS _batch WITH _batch.matchchild AS matchchild   WITH $nodea0 AS nodea0 MATCH (nodeb:Hypothese:DOPLER:Maquette:ImportXML{id:matchchild.params1_id})  MERGE (nodea0)-[rel0:CONTAINS]->(nodeb)"\n                                                                                                                                            ^': Integer { low: 6, high: 0 }
          }
        },
        {
          total: Integer { low: 5732, high: 0 },
          committed: Integer { low: 0, high: 0 },
          failed: Integer { low: 5732, high: 0 },
          errors: {
            'Variable `matchchild` not defined (line 1, column 140 (offset: 139))\n"UNWIND $_batch AS _batch WITH _batch.matchchild AS matchchild   WITH $nodea0 AS nodea0 MATCH (nodeb:Hypothese:DOPLER:Maquette:ImportXML{id:matchchild.params1_id})  MERGE (nodea0)-[rel0:CONTAINS]->(nodeb)"\n                                                                                                                                            ^': Integer { low: 6, high: 0 }
          }
        }
      ],
      _fieldLookup: { batch: 0, operations: 1 }
    }
  ]

 Is there any error in my modified query?

Found the solution.
WITH must conflicts with first return value.

You must add matchchild in the second WITH clause.
Working solution : 

 

MATCH(nodea0:HypoComplexe:DOPLER:Maquette:ImportXML{id:'633635e8a432b6c6f87f36b93df207491942bb7a0714a791725c70d6d070a5bc'})  
CALL apoc.periodic.iterate(
   "WITH $matchchilds AS matchchilds UNWIND matchchilds as matchchild RETURN matchchild",
   "WITH $nodea0 AS nodea0, matchchild AS matchchild 
    MATCH(nodeb:Hypothese:DOPLER:Maquette:ImportXML{id:matchchild.params1_id})  
    MERGE (nodea0)-[rel0:CONTAINS]->(nodeb) ",
   {batchSize:1000, parallel:false,params:{matchchilds: $matchchilds, nodea0:nodea0}}
)
YIELD batch, operations
RETURN batch ,operations 

 

It was a tough one but now it works.

Thank you.

**bleep**, I left out 'matchchilds' on the 'with' on line 5.  Some of the apoc procedures provide a 'with' statement in the code to map each parameter to a variable with the same name as the parameters. apoc.periodic.iterate does not do this.

WITH $nodea0 AS nodea0, $matchchilds as matchchilds