customized comparator in order().by()

38 views
Skip to first unread message

Zhang Jason

unread,
Jan 4, 2024, 4:07:07 AMJan 4
to Gremlin-users
how can I used a customized Java comparator inside by()?
a vertex has timestamp with this format Tue Oct 03 16:39:34 GMT 2023 I want use java comparator to sort it by UTC long value.
But got the follwoing exception
Caused by: io.grpc.StatusRuntimeException: INVALID_ARGUMENT: error in handleRequest(), message=Could not locate exact method given the supplied arguments: DefaultGraphTraversal.by(LinkedHashMap), code=ILLEGAL_INPUT
at io.grpc.Status.asRuntimeException(Status.java:535)
... 13 common frames omitted

my comparator is

Comparator<Vertex> timestampComparator2 = new Comparator<Vertex>() {

SimpleDateFormat dateFormat = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy");

@Override
public int compare(Vertex o1, Vertex o2) {
String timestampString1 = o1.values(P.TIMESTAMP).next().toString();
String timestampString2 = o2.values(P.TIMESTAMP).next().toString();
Date timestamp1 = null;
Date timestamp2 = null;
try {
timestamp1 = dateFormat.parse(timestampString1);
timestamp2 = dateFormat.parse(timestampString2);
return timestamp1.compareTo(timestamp2);
} catch (ParseException e) {
e.printStackTrace();
}

return 0;
}
};

Ken Hu

unread,
Jan 19, 2024, 7:22:05 PMJan 19
to Gremlin-users
This seems to be a duplicate of a later conversation (https://groups.google.com/g/gremlin-users/c/lyzWX8ynrv8) so I'll respond there instead.
Reply all
Reply to author
Forward
0 new messages