"Cannot extract single value from Iterable" with collect() function

199 views
Skip to first unread message

Gwendal Mousset

unread,
Jan 8, 2014, 7:47:18 AM1/8/14
to ne...@googlegroups.com
Hello,

I have an issue with cypher request using collect() function.
I'm using spring-data-neo4j 3.0.0-M1 and Neo4j 2.0.0-M06.

In my data model i have Category nodes.
Each category can have subcategories. 
I want to retrieve the top categories list with the associated subcategories.

 Categ3 -- IS_SUBCATEGORY_OF --> Categ1 <-- IS_SUBCATEGORY_OF -- Categ2

My request:

MATCH (cat:Category)
WITH cat
MATCH
(cat)<-[?:IS_SUBCATEGORY_OF]-(subCat:Category)
WHERE NOT cat
-[:IS_SUBCATEGORY_OF]->()
RETURN cat
as category, collect(subCat) as subCategories


The query result is exactly what i expect in the console:

+--------------------------------------------------------------------------------------------------------------------------------------------------------+
| category                                         | subCategories                                                                                       |
+--------------------------------------------------------------------------------------------------------------------------------------------------------+
| Node[128]{id:"e9c27555f46c4acdb29c8d0e89814467"} | []                                                                                                  |
| Node[176]{id:"78f7c907068c4e1abd018fe560c2c03a"} | []                                                                                                  |
| Node[134]{id:"e362b9c05a8f41f0aee877f914f2658f"} | []                                                                                                  |
| Node[136]{id:"7b3d58a89ebd4010964004d58e962526"} | []                                                                                                  |
| Node[118]{id:"3378af0b1f54405fb7ab2970cba5bff3"} | [Node[34]{id:"d10cc4418c914c1281f7183da8109a4f"},Node[46]{id:"b3012831db924c22829a0335df2e90d1"}]   |
| Node[130]{id:"e3e290b4d2c648b3a6a7d0fe8da461ef"} | []                                                                                                  |
| Node[138]{id:"eb828c120cb248c2a5baa92734e39b91"} | []                                                                                                  |
| Node[132]{id:"057aeb6913474454a329571b9a266305"} | []                                                                                                  |
| Node[126]{id:"2671039fa6f24f5b806df682c238d1c4"} | [Node[120]{id:"48bc7f2b34db49bfb40936864a7a4a80"},Node[122]{id:"373d94527286482fb8c807aee90d7f5e"}] |
+--------------------------------------------------------------------------------------------------------------------------------------------------------+


My QueryResult interface:

@QueryResult
public interface CategoryWithSubCategories {


 
/**
   *
   * @return    A category.
   */

 
@ResultColumn("category")
 
CategoryDAO getCategory();
 
 
/**
   *
   * @return    The subcategories.
   */

 
@ResultColumn("subCategories")
 
Iterable<CategoryDAO> getSubCategories();
}

My Query: 

 @Query("MATCH (cat:Category) "
     
+ "WITH cat "
     
+ "MATCH (cat)<-[?:IS_SUBCATEGORY_OF]-(subCat:Category) "
     
+ "WHERE NOT cat-[:IS_SUBCATEGORY_OF]->() "
     
+ "RETURN distinct cat as category, collect(subCat) as subCategories")
 
Iterable<CategoryDAO> getAll();

When i call this method, i get an exception:

java.lang.RuntimeException: Cannot extract single value from Iterable with more than one elements.
 at org
.springframework.data.neo4j.conversion.DefaultConverter.extractSingle(DefaultConverter.java:60)
 at org
.springframework.data.neo4j.conversion.DefaultConverter.extractValue(DefaultConverter.java:51)
 at org
.springframework.data.neo4j.conversion.DefaultConverter.convert(DefaultConverter.java:40)
 at org
.springframework.data.neo4j.support.conversion.EntityResultConverter.convert(EntityResultConverter.java:165)
 at org
.springframework.data.neo4j.conversion.DefaultConverter.convert(DefaultConverter.java:36)
 at org
.springframework.data.neo4j.rest.SpringRestGraphDatabase$SpringResultConverter.convert(SpringRestGraphDatabase.java:148)
 at org
.neo4j.rest.graphdb.util.QueryResultBuilder$1$1.underlyingObjectToObject(QueryResultBuilder.java:98)
 at org
.neo4j.helpers.collection.IteratorWrapper.next(IteratorWrapper.java:47)
 
...
 
...



Please could you tell me what i'm doing wrong ?

Tank you


pulkit sogani

unread,
Jan 8, 2014, 10:03:34 AM1/8/14
to ne...@googlegroups.com
a

Gwendal Mousset

unread,
Jan 9, 2014, 3:13:24 AM1/9/14
to ne...@googlegroups.com
A precision i missed, the exception is not thrown when i execute the request but when i try accessing to Iterable<CategoryDAO> getSubCategories().

Michael Hunger

unread,
Jan 10, 2014, 3:26:46 AM1/10/14
to ne...@googlegroups.com
Hi,

its a bug in SDN, I fixed it here, in case you want to patch locally.


        if (returnType.isCollectionLike()) {
             QueryResultBuilder qrb = new QueryResultBuilder((Iterable)columnValue, converter);
             return qrb.to(returnType.getActualType().getType()).as(returnType.getType());
        } else
           return converter.convert(columnValue, returnType.getType(), mappingPolicy);
    }

It will be part of the next release, thanks again for reporting it.

Cheers

Michael

--
You received this message because you are subscribed to the Google Groups "Neo4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email to neo4j+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Gwendal Mousset

unread,
Jan 10, 2014, 4:23:27 AM1/10/14
to ne...@googlegroups.com
Thank you very much Michael for your work and your reactivity !

Gwendal Mousset

unread,
Jan 20, 2014, 10:33:43 AM1/20/14
to ne...@googlegroups.com
Hi, 

Michael, your patch works well with embedded database but not with neo4j server.
Thanks for your help

Gwendal

Michael Hunger

unread,
Jan 20, 2014, 11:53:33 AM1/20/14
to ne...@googlegroups.com
Good point, I should check the same thing in the java-rest-binding.

Michael

Gwendal Mousset

unread,
Jan 20, 2014, 1:57:54 PM1/20/14
to ne...@googlegroups.com
Thanks :-)
Gwendal Mousset

Gwendal Mousset

unread,
Feb 5, 2014, 6:27:56 AM2/5/14
to ne...@googlegroups.com
Hi Michael,

We have switched to neo4j-2.0.1 with SDN 3.0.0-RC1 and I found that this bug is fixed with embedded database but not with server.
Do you think it will be fixed in next RC ?
Could you provide a patch waiting for the next release ?

Thanks

On Monday, January 20, 2014 7:57:54 PM UTC+1, Gwendal Mousset wrote:
Thanks :-)


To unsubscribe from this group and stop receiving emails from it, send an email to neo4j+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to the Google Groups "Neo4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email to neo4j+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.



--
Gwendal Mousset

Michael Hunger

unread,
Feb 5, 2014, 6:30:03 AM2/5/14
to ne...@googlegroups.com
I couldn't reproduce it with server, I ran exactly the same test that failed against server and it worked for me.

Let me see if we can figure out a test-case against server that shows it.

Michael
Reply all
Reply to author
Forward
0 new messages