2013-01-15 146 views
2

我在使用嵌入式Java API的Cypher查詢中使用IN運算符時遇到問題。看起來,您無法使用IN運營商的標識符而不是start條款中檢索到的實體。Neo4J IN運算符

例如,這裏是我的查詢:

start n=node(someLongNodeId) 
match n--m 
where m.gnid? IN [\"someStringId\",\"otherStringId\"] 
return m 

上的n屬性過濾時,我可以利用IN操作符,但它失敗,出現以下異常,當我執行上面的查詢,並嘗試調用hasNext()IteratorcolumnAs("m")返回:

Exception in thread "main" java.lang.RuntimeException 
    at org.neo4j.cypher.internal.pipes.matching.MiniMap.newWith(ExpanderStep.scala:172) 
    at org.neo4j.cypher.internal.pipes.matching.MiniMap.newWith(ExpanderStep.scala:155) 
    at org.neo4j.cypher.internal.commands.InCollection$$anonfun$isMatch$1.apply(InCollection.scala:39) 
    at org.neo4j.cypher.internal.commands.InCollection$$anonfun$isMatch$1.apply(InCollection.scala:38) 
    at scala.collection.LinearSeqOptimized$class.exists(LinearSeqOptimized.scala:79) 
    at scala.collection.immutable.List.exists(List.scala:45) 
    at org.neo4j.cypher.internal.commands.AnyInCollection$$anonfun$seqMethod$2.apply(InCollection.scala:71) 
    at org.neo4j.cypher.internal.commands.AnyInCollection$$anonfun$seqMethod$2.apply(InCollection.scala:71) 
    at org.neo4j.cypher.internal.commands.InCollection.isMatch(InCollection.scala:38) 
    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.<init>(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$$anon$19.hasNext(Iterator.scala:334) 
    at scala.collection.Iterator$$anon$19.hasNext(Iterator.scala:334) 
    at org.neo4j.cypher.PipeExecutionResult.hasNext(PipeExecutionResult.scala:138) 
    at scala.collection.Iterator$$anon$19.hasNext(Iterator.scala:334) 
    at scala.collection.Iterator$$anon$19.hasNext(Iterator.scala:334) 
    at scala.collection.JavaConversions$IteratorWrapper.hasNext(JavaConversions.scala:562) 
    at com.awesomecompany.data.neo.NeoTestDriver.performBidirectionalQuery(NeoTestDriver.java:122) 
    at com.awesomecompany.data.neo.NeoTestDriver.main(NeoTestDriver.java:44) 

我是正確的我的假設,你不能使用IN操作符上比以外的東西在我的例子中?這是一個錯誤,還是由設計?

回答

2

我想回答我自己的問題,以防其他人有類似的問題。有跡象表明,我想引用ADRESS在上面的例子中有兩件事情:

this discussion在Neo4j的谷歌集團論壇

  • 我增加了HAS()函數在WHERE子句
  • 我也改變了數組值使用單引號(')而不是以前的雙引號

所以我的新例子查詢看起來是這樣的:

start n=node(someLongNodeId) 
match n--m 
where HAS(m.gnid) AND m.gnid IN ['someStringId','otherStringId'] 
return m 

這按預期工作。

完成上述編輯之後,我將查詢轉換爲使用參數(如果JDBC教會了我什麼,是執行此類查詢的正確方法)。該查詢看起來像這樣:

start n=node({nodeId}) 
match n--m 
where HAS(m.gnid) AND m.gnid IN {otherIds} 
return m 

這也正常工作。

IN運算符目前沒有非常好的記錄,這是可以理解的,因爲它對neo4j項目來說是相當新穎的,但我想確保在其他人遇到類似問題的情況下回答這個問題。

+0

一個很小的示例數據庫沒有'HAS()':http://console.neo4j.org/?id = qnatzd –

+0

你是對的,但只有在你的start子句中使用'*'運算符。再次嘗試使用特定的節點ID。 – rmlan

+0

我現在看到了。感謝您的研究,這是一個艱難的... –