You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tinkerpop.apache.org by "Daniel Kuppitz (JIRA)" <ji...@apache.org> on 2016/01/19 16:38:39 UTC
[jira] [Commented] (TINKERPOP-1089) Order.shuffle implementation is
too fragile
[ https://issues.apache.org/jira/browse/TINKERPOP-1089?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15106881#comment-15106881 ]
Daniel Kuppitz commented on TINKERPOP-1089:
-------------------------------------------
I gave it a try and it's an easy fix for {{OrderLocalStep}}:
{code}
...
private static <A> List<A> sortCollection(final Collection<A> collection, final Comparator<?> comparator) {
final List<A> list = collection instanceof List ? (List<A>) collection : new ArrayList<>(collection);
if (Order.shuffle.equals(comparator)) { // special handling for Order.shuffle
Collections.shuffle(list);
} else {
Collections.sort(list, (Comparator) comparator);
}
return list;
}
private static <K, V> Map<K, V> sortMap(final Map<K, V> map, final Comparator<?> comparator) {
final List<Map.Entry<K, V>> entries = sortCollection(new ArrayList<>(map.entrySet()), comparator); // reuse existing code
final LinkedHashMap<K, V> sortedMap = new LinkedHashMap<>();
entries.forEach(entry -> sortedMap.put(entry.getKey(), entry.getValue()));
return sortedMap;
}
{code}
However, {{OrderGlobalStep}} seems to be a lot more tricky as it uses {{ChainedComparator}}.
> Order.shuffle implementation is too fragile
> -------------------------------------------
>
> Key: TINKERPOP-1089
> URL: https://issues.apache.org/jira/browse/TINKERPOP-1089
> Project: TinkerPop
> Issue Type: Bug
> Components: process
> Affects Versions: 3.0.2-incubating
> Reporter: Daniel Kuppitz
> Assignee: Marko A. Rodriguez
> Fix For: 3.1.1-incubating
>
>
> {code}
> __((1..100).toList()).order(local).by(shuffle)
> {code}
> Try that query often enough and it will fail. You can increase the likeliness of a failure by increasing the size of the list. An explanation of why that happens is given here:
> http://stackoverflow.com/questions/19325256/java-lang-illegalargumentexception-comparison-method-violates-its-general-contr
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)