Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to include package into query?

This question is a continuation of How to identify all classes implementing a specific interface that do NOT extend some base class?.

The accepted answer there suggests to use:

MATCH 
   (i:Interface {name:'Action'}  )<-[:IMPLEMENTS|EXTENDS*1..10]- (class), 
   (abstractAction:Class {name:'AbstractAction'}) 
   where not (class)-->(abstractAction)   
RETURN class

That works nicely, and gives a list of classes matching that condition.

The only problem I have: the name of that interface Action is (surprise) ambiguous. The absolute class name com.whatever.foo.bar.Action would be. But when I change the query to use {name:'com.whatever.foo.bar.Action'} I get an empty result.

I then tried {package:'com.whatever.foo.bar' name:'Action'}, but that doesn't work:

One of the property names in your query is not available in the database, make sure you didn't misspell it or that the label is available when you run this statement in your application (the missing property name is: package)

Is there a way reduce the search result to that Action interface I really care about?

like image 283
GhostCat Avatar asked Jul 12 '26 11:07

GhostCat


1 Answers

There is a fqn node property - full qualified name.

So the correct query would be:

MATCH 
   (i:Interface {fqn:'com.whatever.foo.bar.Action'}  )<-[:IMPLEMENTS|EXTENDS*1..10]- (class), 
   (abstractAction:Class {fqn:'com.whatever.foo.bar.AbstractAction'}) 
   where not (class)-->(abstractAction)   
RETURN class

This query produces a cartesian produckt which means that it's not very performant.

The following image shows the execution plan of that query for one of my projects: enter image description here

This questions deals with that problem in more detail: Why does neo4j warn: "This query builds a cartesian product between disconnected patterns"?

Since this query is just for analysis purposes and not executed against a production system, I would ignore that hint.

like image 100
Peter Avatar answered Jul 14 '26 01:07

Peter



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!