Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to know an apoc procedure output name

I am using some of the awesome apoc.refactor procedures. I noticed that in the documentation there is no mention of the output variables names that one can use with YIELDS.

I figured out that refactor.mergeNodes outputs node (as the new merged node), but I can't figure out what is the output name of refactor.to or refactor.from. I tried rel and newRel with no success. I am not a java programmer, but inspecting the code (especially RelationshipRefactorResult.java) I thought 'rel' was the one to go.

This is the query I am trying:

MATCH ()-[r]->(), (n)
WHERE id(r) = 16 AND id(n) = 4
CALL apoc.refactor.from(r,n) YIELD rel
RETURN rel

And this is the output message:

Unknown procedure output: `rel` (line 3, column 36 (offset: 96))
"RETURN rel"
like image 982
miro marchi Avatar asked Sep 06 '16 08:09

miro marchi


2 Answers

Sorry that's a shortcoming of the current docs.

We want to automate / improve that.

You can see the output types if you CALL dbms.procedures()

CALL dbms.procedures() YIELD name, signature
WITH * WHERE name STARTS WITH 'apoc.refactor'
RETURN name, signature

The signature is always name :: TYPE e.g. in your case:

apoc.refactor.to(relationship :: RELATIONSHIP?, newNode :: NODE?) :: (input :: INTEGER?, output :: RELATIONSHIP?, error :: STRING?)

Parameters:

  • Name: relationship, Type: Relationship
  • Name: newNode, Type: Node

Output Columns:

  • Name: input, Type: Integer
  • Name: output, Type Relationship
  • Name: error, Type: String
like image 105
Michael Hunger Avatar answered Oct 23 '22 08:10

Michael Hunger


Building on the answer of Michael, here is a little tool. Just a query that builds tidy documentation for these. :) Maybe it can be adapted to work for others procedures too.

//EXPOSED YIELD PARAMETERS OUTPUT FROM  apoc.periodic...
CALL dbms.procedures() YIELD name, signature
WITH * WHERE name STARTS WITH 'apoc.periodic'
RETURN name AS procedure, 'YIELD', 
      tail(
        apoc.text.split( 
          toString(apoc.text.split(signature, '\\)')[1])
        , '[^a-z]+[^a-zA-Z]*[^a-z]')
      ) AS exposed_parameters
like image 44
mojo2go Avatar answered Oct 23 '22 08:10

mojo2go