cancel
Showing results for 
Search instead for 
Did you mean: 

Help using apoc.case in Neodash report

AndrewF
Node

Hello! I'm trying to use apoc.case to include some conditional logic for a results table in a Neodash app. Code looks like this:

CALL apoc.case(
[$neodash__settings_oracle_depth_value = 'Schema' ,
"MATCH (n:TABLE{owner: '" + $neodash_table_owner + "'}) CALL apoc.path.subgraphNodes(n, {relationshipFilter:'<'}) YIELD node RETURN node.owner AS Schema, COUNT(node) AS Count",
$neodash__settings_oracle_depth_value = 'Table' ,
"MATCH (n:TABLE{owner: '" + $neodash_table_owner + "', name: '" + $neodash_table_name + "'}) CALL apoc.path.subgraphNodes(n, {relationshipFilter:'<'}) YIELD node RETURN node.owner AS Schema, COUNT(node) AS Count",
$neodash__settings_oracle_depth_value = 'Column' ,
"MATCH (n:COLUMN{owner: '" + $neodash_table_owner + "', object_name: '" + $neodash_table_name + "', name: '"+ $neodash_column_name + "'}) CALL apoc.path.subgraphNodes(n,{relationshipFilter:'<'}) YIELD node RETURN node.owner AS Schema, COUNT(node) AS Count"
]
)

Each of the queries works fine individually but when I use them with apoc.case the results come out looking like this in a single column:

{"Schema":"CIS","Count":{"low":1465,"high":0}}

etc

Anyone got any ideas what I'm doing wrong here?

Thanks!

3 REPLIES 3

glilienfield
Ninja
Ninja

From the docs, it looks like apoc.case returns a map of the results; therefore, you are receiving a map with 'Schema' and 'Count' as keys. I don't understand where the value of 'Count' is getting compute as another map with both a 'high' and 'low' value is coming from.  What output do you want?

One thing you can do to have more control over the output is to remove the 'CALL apoc.path.subgraphNodes' call to outside the apoc.case, as all are the same for each case statement. Instead, your 'case' statement returns 'n' in a map, which you can extract and pass to the 'path' call. You can them format the data as you require it.

Fortunately I've managed to figure this out!

1) The "high" and "low" weirdness is apparently something to due with Javascript not doing 64bit numbers. I won't even pretend to care about that because actually when solved it doesn't matter.

2) All I had to do was add YIELD value RETURN value.Schema, value.Count after the apoc.casefunction call.

This would be a case (pun not intended) where having some actual meaningful code snippets in the documentation would be useful to understand how a function actually works. Given there's little to zero community discussion (at least findable on google) about specific functions and their usage it certainly would be nice to see some non-trivial code snippets added to documentation.

Yes, the reason ‘yield value return value.schema, value.count’ works is because ‘value’ is a map with properties ‘schema’ and ‘ count’ in your case.  You can access map values with dot notation, as you figured out. 

I agree that the apoc documentation can be lacking, or event confusing at times. 

Nodes 2022
Nodes
NODES 2022, Neo4j Online Education Summit

All the sessions of the conference are now available online