[ 
https://issues.apache.org/jira/browse/JENA-506?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14315950#comment-14315950
 ] 

Rob Vesse commented on JENA-506:
--------------------------------

Should we just close this as won't fix, if someone really wants to {{ORDER BY 
RAND()}} in a safe way they can do so using the following pattern

{noformat}
SELECT ?var1 ?var2 # etc.
WHERE
{
  # Normal query patterns
  BIND(RAND() AS ?sortKey)
}
ORDER BY ?sortKey
{noformat}

This allows sorting at random while ensuring that the sort key is stable and 
won't violate Java comparison rules

> SPARQL "ORDER BY RAND()" may lead to a "Comparison method violates its 
> general contract!" exception 
> ----------------------------------------------------------------------------------------------------
>
>                 Key: JENA-506
>                 URL: https://issues.apache.org/jira/browse/JENA-506
>             Project: Apache Jena
>          Issue Type: Bug
>          Components: ARQ
>    Affects Versions: Jena 2.10.1
>         Environment: OpenJDK 1.7.0_21 (64)
>            Reporter: Pasquale Minervini
>
> It seems like the SPARQL "SELECT [..] ORDER BY RAND()" query construct can 
> cause troubles when retrieving results; here's a complete stacktrace 
> (Specifically, I've been querying the DBLP RDF dataset: 
> http://sw.deri.org/~aharth/2004/07/dblp/). I think the construct can be quite 
> useful for randomly sampling nodes from the RDF graph, that's the reason for 
> the 'Critical'.
> ARQ:        VERSION: 2.10.1
> ARQ:        BUILD_DATE: 2013-05-11T22:05:51+0100
> Exception in thread "main" java.lang.IllegalArgumentException: Comparison 
> method violates its general contract!
>         at java.util.TimSort.mergeLo(TimSort.java:747)
>         at java.util.TimSort.mergeAt(TimSort.java:483)
>         at java.util.TimSort.mergeCollapse(TimSort.java:408)
>         at java.util.TimSort.sort(TimSort.java:214)
>         at java.util.TimSort.sort(TimSort.java:173)
>         at java.util.Arrays.sort(Arrays.java:659)
>         at 
> org.apache.jena.atlas.data.SortedDataBag.iterator(SortedDataBag.java:204)
>         at 
> org.apache.jena.atlas.data.SortedDataBag.iterator(SortedDataBag.java:189)
>         at 
> com.hp.hpl.jena.sparql.engine.iterator.QueryIterSort$SortedBindingIterator.initializeIterator(QueryIterSort.java:99)
>         at 
> org.apache.jena.atlas.iterator.IteratorDelayedInitialization.init(IteratorDelayedInitialization.java:40)
>         at 
> org.apache.jena.atlas.iterator.IteratorDelayedInitialization.hasNext(IteratorDelayedInitialization.java:50)
>         at 
> com.hp.hpl.jena.sparql.engine.iterator.QueryIterPlainWrapper.hasNextBinding(QueryIterPlainWrapper.java:54)
>         at 
> com.hp.hpl.jena.sparql.engine.iterator.QueryIteratorBase.hasNext(QueryIteratorBase.java:112)
>         at 
> com.hp.hpl.jena.sparql.engine.iterator.QueryIterSlice.hasNextBinding(QueryIterSlice.java:76)
>         at 
> com.hp.hpl.jena.sparql.engine.iterator.QueryIteratorBase.hasNext(QueryIteratorBase.java:112)
>         at 
> com.hp.hpl.jena.sparql.engine.iterator.QueryIteratorWrapper.hasNextBinding(QueryIteratorWrapper.java:40)
>         at 
> com.hp.hpl.jena.sparql.engine.iterator.QueryIteratorBase.hasNext(QueryIteratorBase.java:112)
>         at 
> com.hp.hpl.jena.sparql.engine.iterator.QueryIteratorWrapper.hasNextBinding(QueryIteratorWrapper.java:40)
>         at 
> com.hp.hpl.jena.sparql.engine.iterator.QueryIteratorBase.hasNext(QueryIteratorBase.java:112)
>         at 
> com.hp.hpl.jena.sparql.engine.ResultSetStream.hasNext(ResultSetStream.java:75)
> I can easily provide a snippet if you really need it.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to