You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tinkerpop.apache.org by Marko Rodriguez <ok...@gmail.com> on 2016/04/08 15:38:01 UTC

Fwd: Comparators in 3.2

Hi everyone,

Matthias is upgrading DSEGraph to work with TinkerPop 3.2.0 and noted one of the breaking changes in the ComparatorHolder API. He emailed to ask about how he needs to upgrade his code to account for it.

I thought I gave a nice explanation that other providers might find useful who have TraversalStrategies introspecting on OrderGlobalStep.

Good luck,
Marko.

http://markorodriguez.com

Begin forwarded message:

> Hello Matthias,
> 
> Yes, that changed. And for good reason.
> 
> 	http://tinkerpop.apache.org/docs/3.2.0-SNAPSHOT/upgrade/#_graph_system_providers
> 
> The new method signature is:
> 
> 	public List<Pair<Traversal.Admin<S, C>, Comparator<C>>> getComparators();
> 
> What does this mean?
> 
> 	Traversal.Admin<S,C> can simply be identity and Comparator Order.decr
> 		- order().by(decr)
> 	Traversal.Admin<S,C> can be ElementValueTraversal and Comparator Order.incr
> 		- order().by("name",incr)
> 	Traversal.Admin<S,C> can be an anonymous traversal and a closure comparator.
> 		- order().by(outE().count(), (a,b) -> a*10 > b)
> 
> 
> Its a List<Pair<Traversal,Comparator>> and that is the order of sorts -- secondary, tertiary, etc.
> 	order().by("name",decr).by("age",incr).by….
> 
> Given your code block in your email:
> 
> 	traversal = pair.getValue0();
> 	comparator = pair.getValue1();
> 	if(!(traversal instanceof ElementValueTraversal)) return false;
> 	ElementValueTraversal evt = (ElementValueTraversal) traversal;
> 	if(!comparator instance of Order)) return false;
> 
> 	evt.getPropertyKey()
> 	….
> 
> Not too much to change and I hope you see how this is much cleaner. I was able to gut an insane amount of code and in 3.2.1, the expressivity of OrderStep in OLAP will increase.
> 
> Marko.
> 
> 
> On Apr 7, 2016, at 11:11 PM, Matthias Broecheler <ma...@datastax.com> wrote:
> 
>> Hey Marko,
>> 
>> step.getComparators()
>> used to return a list of comparators but now it seems to return a list of pairs. What do those pairs represent and what do I need to do in DSE Graph to process this?
>> 
>> Are there any other internal changes like this I should know about?
>> Thanks,
>> Matthias
>> 
>> ==== FYI: this is the relevant code block
>> 
>> for (Comparator comp : (List<Comparator>) ostep.getComparators()) {
>>     if (!(comp instanceof ElementValueComparator)) return false;
>>     ElementValueComparator evc = (ElementValueComparator) comp;
>>     if (!(evc.getValueComparator() instanceof Order)) return false;
>> 
>>     DsegTransaction tx = DsegTraversalUtil.getTx(rootTraversal.asAdmin());
>>     String key = evc.getPropertyKey();
>>     PropertyKeyInternal pkey = tx.schemaModel().propertyKey(key);
>>     if (pkey == null || !pkey.dataType().isComparable()) return false;
>>     if (isVertexOrder && pkey.cardinality() != Cardinality.Single) return false;
>> }
>> return true;
>