Cypher: ThisShouldNotHappenError: This execution plan should not exist - neo4j

What's wrong with the following query? [Neo4j 1.8.2, Embedded]
start merchant = node:merchants('id:10')
match (merchant)<-[:VALID_AT]-(offer)-[:TARGET_PINCODE]->(pincode)<-[:RESIDES_IN]-(customer) where (offer)-[:VALID_OFFER]->() and offer.endDate > 1
return count(offer)
Webadmin returns undefined
Java Exception:
org.neo4j.helpers.ThisShouldNotHappenError: Developer: Andres claims
that: This execution plan should not exist. at
org.neo4j.cypher.internal.commands.PathExpression$$anonfun$4.apply(PathExpression.scala:47)
at
org.neo4j.cypher.internal.commands.PathExpression$$anonfun$4.apply(PathExpression.scala:46)
at
scala.collection.LinearSeqOptimized$class.exists(LinearSeqOptimized.scala:79)
at scala.collection.immutable.List.exists(List.scala:45) at
org.neo4j.cypher.internal.commands.PathExpression.apply(PathExpression.scala:46)
at
org.neo4j.cypher.internal.commands.PathExpression.apply(PathExpression.scala:31)
at
org.neo4j.cypher.internal.commands.NonEmpty.isMatch(Predicate.scala:283)
at org.neo4j.cypher.internal.commands.And.isMatch(Predicate.scala:83)
at
org.neo4j.cypher.internal.pipes.matching.FilteringIterable$FilteringIterator.spoolToNextInLine(FilteringIterable.scala:55)
at
org.neo4j.cypher.internal.pipes.matching.FilteringIterable$FilteringIterator.(FilteringIterable.scala:34)
at
org.neo4j.cypher.internal.pipes.matching.FilteringIterable.iterator(FilteringIterable.scala:72)
at
org.neo4j.cypher.internal.pipes.matching.FilteringIterable.iterator(FilteringIterable.scala:27)
at
scala.collection.JavaConversions$IterableWrapperTrait$class.iterator(JavaConversions.scala:557)
at
scala.collection.JavaConversions$IterableWrapper.iterator(JavaConversions.scala:583)
at
scala.collection.JavaConversions$IterableWrapper.iterator(JavaConversions.scala:583)
at
org.neo4j.kernel.impl.traversal.TraversalBranchWithState.expandRelationshipsWithoutChecks(TraversalBranchWithState.java:70)
at
org.neo4j.kernel.impl.traversal.TraversalBranchImpl.expandRelationships(TraversalBranchImpl.java:104)
at
org.neo4j.kernel.impl.traversal.StartNodeTraversalBranch.next(StartNodeTraversalBranch.java:47)
at
org.neo4j.kernel.impl.traversal.AsOneStartBranch.next(AsOneStartBranch.java:100)
at
org.neo4j.kernel.PreorderDepthFirstSelector.next(PreorderDepthFirstSelector.java:52)
at
org.neo4j.kernel.impl.traversal.TraverserIterator.fetchNextOrNull(TraverserIterator.java:65)
at
org.neo4j.kernel.impl.traversal.TraverserIterator.fetchNextOrNull(TraverserIterator.java:34)
at
org.neo4j.helpers.collection.PrefetchingIterator.hasNext(PrefetchingIterator.java:55)
at
scala.collection.JavaConversions$JIteratorWrapper.hasNext(JavaConversions.scala:574)
at scala.collection.Iterator$$anon$21.hasNext(Iterator.scala:371) at
scala.collection.Iterator$$anon$21.hasNext(Iterator.scala:371) at
scala.collection.Iterator$$anon$22.hasNext(Iterator.scala:388) at
scala.collection.Iterator$class.foreach(Iterator.scala:660) at
scala.collection.Iterator$$anon$22.foreach(Iterator.scala:382) at
org.neo4j.cypher.internal.pipes.EagerAggregationPipe.createResults(EagerAggregationPipe.scala:76)
at
org.neo4j.cypher.internal.pipes.ColumnFilterPipe.createResults(ColumnFilterPipe.scala:37)
at
org.neo4j.cypher.internal.executionplan.ExecutionPlanImpl$$anonfun$6.apply(ExecutionPlanImpl.scala:127)
at
org.neo4j.cypher.internal.executionplan.ExecutionPlanImpl$$anonfun$6.apply(ExecutionPlanImpl.scala:125)
at
org.neo4j.cypher.internal.executionplan.ExecutionPlanImpl.execute(ExecutionPlanImpl.scala:33)
at org.neo4j.cypher.ExecutionEngine.execute(ExecutionEngine.scala:59)
at org.neo4j.cypher.ExecutionEngine.execute(ExecutionEngine.scala:63)
at
org.neo4j.cypher.javacompat.ExecutionEngine.execute(ExecutionEngine.java:79)
Note: return offer instead of return count(offer) works

Upgraded to Neo4j 1.9 RC1 and the problem no longer exists

Related

<ActiveRecord::QueryMethods::WhereChain error on a scope that was working

I've been running a piece of code for a while with success but it has just started throwing an error - we've altered the way data is going into the database but believe it's more likely a programming issue or I've altered it by mistake, but can't see where.
The issue appears to be caused form a scope, we're running Rails 4.2.2
The complete error is
undefined method `call' for
ActiveRecord::QueryMethods::WhereChain:0x007feb8f5c49f0> Did you mean? caller
app/controllers/orders_controller.rb:158:in `weekly_sales_report'
in my orders_controller line 158
#sales_this_week_bysales = Order.select("COUNT(order_id) AS nosales, AVG(net_amount) AS avgsale,SUM(sale_cost) AS sale_cost, SUM(net_amount) AS weeklysalestotal, owner_id AS salesman").sales.where.(date_of_sale: (#startdate .. #enddate)).with_salesman.group(:owner_id)
in my orders.rb model I have the following used scopes
scope :with_salesman, -> { joins(:pipe_records).where(pipe_records: {pipe_part_id: 1}).where.not(pipe_records: {owner_id: nil}) }
scope :sales, -> {where ("orders.order_ref <>'' and date_of_sale IS NOT NULL ")}
I re-wrote the scope to the below but still got the same error
scope :with_salesman, -> { joins(" INNER JOIN pipe_records ON pipe_records.order_id = orders.id WHERE pipe_records.pipe_part_id =1 AND pipe_records.owner_id <>'' ") }
I also removed the WHERE startdate criteria from the sales.where on 158 which returned a different error, but it appears the scope isn't passing correctly anymore or returning an error due to bad records??
I'm now unsure what is happening, I went back to my remotes and took a copy of the code from a couple of days ago and this also threw the same error, but it was working correctly. We've put a lot of new records in recently through a new form which bypasses and alters created at dates which may be to blame. I would appreciate any suggestions or fresh eyes.
Just remove the period between where and the parenthesis.
where.(date_of_sale: (#startdate..#enddate))
In ruby
receiver.()
is short hand for receiver.call() thus the error you are receiving
You probably want to remove that period after where:
where.(date_of_sale: (#startdate .. #enddate))

Wrong result when query has more filters

MATCH (prs:Issue)-[:REPORTED_BY]-(custs)
MATCH (prs)-[:CLOSED_ON]-(cls:IssueClosedDate)
MATCH (prs)-[:REPORTED_BY]->(custNode:Customer)
MATCH (prs)-[:APP_FUN_CAT]-(afc:AppFunCat)
MATCH (prs)-[:REPORTED_IN]-(release:Release)
WHERE afc.func STARTS WITH 'WEB' AND NOT(cls.closedDate = '' ) AND afc.appName STARTS WITH 'SOCKET'
AND apoc.date.parse(cls.closedDate,'s', 'MM/dd/yyyy') >= apoc.date.parse('01/01/2014','s', 'MM/dd/yyyy')
AND apoc.date.parse(cls.closedDate,'s', 'MM/dd/yyyy') <= apoc.date.parse('06/13/2017','s', 'MM/dd/yyyy')
AND afc.cat IN ["ALL","NEW","SOFTWARE","UNDETERMINED"]
RETURN prs.prId AS prList, custs.customerName AS customer, afc.cat AS category, cls.closedDate AS prClosedDate, release.relName as releaseName `
The above query gives me result shown below:
 "prList"  "funName"  "year"  "afc.appName"  "afc.cat"  "cls.closedDate"  
7371322  "WEB"   "2015"  "SOCKET"   "SOFTWARE"  "4/27/2015"  
8277662  "WEB"   "2015"  "SOCKET"   "SOFTWARE"  "9/24/2015"  
7513015  "WEB"   "2015"  "SOCKET"   "SOFTWARE"  "9/24/2015"
This result is not correct if I check with data base. It should have given more number of list than this.
It is found that if I remove either of the filter
afc.appName STARTS WITH 'SOCKET' or
apoc.date.parse(cls.closedDate,'s', 'MM/dd/yyyy') <= apoc.date.parse('06/13/2017','s', 'MM/dd/yyyy') or
fc.cat IN ["ALL","NEW","SOFTWARE","UNDETERMINED"]
the result I get is correct. So I can say that the database is build properly. Though the above query is showing the three result there are more number of columns.
Is there any limitation from neo4j database that we cannot do this?
Can anybody suggest how can I resolve this problem?
As said by InverseFalcon in comment, version might be the issue. We updated the version as mention below:
Neo4j Browser version: 3.0.1 to 3.2.8
Neo4j Server version: 3.2.0 to 3.4.8 (community)
apoc-3.2.3.5-all.exe to apoc-3.4.0.3-all.exe
Now all the filters are working good. Problem is solved.

Numeric sort in Manual (Legacy) index in Neo4j 3 is not working correctly

I'm using Legacy indexing (now called Manual indexing). After migration from Neo4j 2 to version 3 I have some problems with numeric sorting.
Example of correct statement in Neo4j 2:
queryContext.sort(new Sort(new SortField(AGE, SortField.INT, false)));
This stament should be changed for Neo4j 3 (Lucene 5):
queryContext.sort(new Sort(new SortField(AGE, SortField.Type.INT, false)));
But if you use this sort statement you will get an exception:
java.lang.IllegalStateException: unexpected docvalues type SORTED_SET for field 'firstName' (expected=SORTED). Use UninvertingReader or index with docvalues.
at org.apache.lucene.index.DocValues.checkField(DocValues.java:208)
at org.apache.lucene.index.DocValues.getSorted(DocValues.java:264)
at org.apache.lucene.search.FieldComparator$TermOrdValComparator.getSortedDocValues(FieldComparator.java:762)
at org.apache.lucene.search.FieldComparator$TermOrdValComparator.getLeafComparator(FieldComparator.java:767)
at org.apache.lucene.search.FieldValueHitQueue.getComparators(FieldValueHitQueue.java:183)
at org.apache.lucene.search.TopFieldCollector$SimpleFieldCollector.getLeafCollector(TopFieldCollector.java:164)
at org.neo4j.kernel.api.impl.index.collector.DocValuesCollector.replayTo(DocValuesCollector.java:297)
at org.neo4j.kernel.api.impl.index.collector.DocValuesCollector.getTopDocs(DocValuesCollector.java:275)
at org.neo4j.kernel.api.impl.index.collector.DocValuesCollector.getIndexHits(DocValuesCollector.java:150)
at org.neo4j.index.impl.lucene.legacy.LuceneLegacyIndex.search(LuceneLegacyIndex.java:346)
at org.neo4j.index.impl.lucene.legacy.LuceneLegacyIndex.query(LuceneLegacyIndex.java:261)
at org.neo4j.index.impl.lucene.legacy.LuceneLegacyIndex.query(LuceneLegacyIndex.java:205)
at org.neo4j.index.impl.lucene.legacy.LuceneLegacyIndex.query(LuceneLegacyIndex.java:217)
at org.neo4j.kernel.impl.api.StateHandlingStatementOperations.nodeLegacyIndexQuery(StateHandlingStatementOperations.java:1440)
at org.neo4j.kernel.impl.api.OperationsFacade.nodeLegacyIndexQuery(OperationsFacade.java:1162)
at org.neo4j.kernel.impl.coreapi.LegacyIndexProxy$Type$1.query(LegacyIndexProxy.java:83)
at org.neo4j.kernel.impl.coreapi.LegacyIndexProxy.query(LegacyIndexProxy.java:365)
I think this is caused by new added statement in Neo4j indexer class (Neo4j is indexing field for sorting automatically now?). See in:
org.neo4j.index.impl.lucene.legacy.IndexType CustomType addToDocument( Document document, String key, Object value )
new line:
document.add( instantiateSortField( key, value ) );
and method instantiateSortField is creating SortedSetDocValuesField
So I changed my code to:
queryContext.sort(new Sort(new SortedSetSortField(AGE, false)));
This runs OK but sorting is not working because numbers are sorted as string. I see that "value" parameter is String every time in method "addToDocument". I think the root cause is explained it this old comment:
see comment in class org.neo4j.index.impl.lucene.legacy.IndexType CustomType
// TODO We should honor ValueContext instead of doing value.toString() here.
// if changing it, also change #get to honor ValueContext.
Am I missing some new way how to index, search and sort data in Neo4j 3 or this is really problem that values are indexed as string in Neo4j?
Simple unit test for Neo4j 2 and Neo4j 3 can be downloaded
Solution added by MishaDemianenko at GH issue

allShortestPaths: Unknown Identifier

Im currently writing a query to return a VIRTUEALSUITE with its belonging PRODUCT_VERSIONS and their children (recursively).
Here is my current query:
MATCH (vs: VIRTUALSUITE {NAME: "Test VS Copy"})-[:INCLUDES_VERSION]->(productVersion: PRODUCT_VERSION)
MATCH allShortestPaths((productVersion)-[:IS_BOMPARENT_OF*..]->(child: PRODUCT_VERSION))
RETURN vs, productVersion, child
I need the "allShortestPaths" function. Otherwise queries like this take an infinite time.
But as a result of this query i just get the error message:
Unknown identifier `child`
Unknown identifier `vs`.
Unknown identifier `productVersion`.
Unknown identifier `child`.
As u will probably notice, I'm quite new to this. Would be very nice, if you could help me out! :)
Thanks a lot and Greetings
Schakron
It appears you are using version 2.0 of neo4j. Your Cypher query should work in versions 2.1 and above.
See this console. You can change the version used by the console by clicking the Options button at the top.
Also, I believe you would want to return the shortest paths:
MATCH (vs: VIRTUALSUITE {NAME: "Test VS Copy"})-[:INCLUDES_VERSION]->(productVersion: PRODUCT_VERSION)
MATCH p = allShortestPaths((productVersion)-[:IS_BOMPARENT_OF*..]->(child: PRODUCT_VERSION))
RETURN vs, productVersion, child, p

Error while forcing index in cypher query

I am using version 2.0.1 of Neo4j.
I have a label named as prod and a property as id.
My doubt is as follows:
The following query return results very fast:
profile match (p:PROD) where p.id="111" return p;
SchemaIndex(identifier="n", _db_hits=0, _rows=2, label="Prod", query="Literal(111)", property="id")
But when i use a list using IN and force index usage:
profile match (p:PROD) USING INDEX p:PROD(id) where p.id IN ["111","222"] return p;
It shows the following error:
IndexHintException: Cannot use index hint in this context. The label and property comparison must be specified on a non-optional node
Label: `prod`
Property name: `id`
Why can't i use the USE INDEX method to specify the index.? What am i doing wrong? How should i correct it?
WHERE conditions using the IN operator do not use indexes in Neo4j 2.0.x. Please upgrade to 2.1.3 which supports this operation.

Resources