Custom P predicate to remote TinkerPop instance

312 views
Skip to first unread message

Gareth Jones

unread,
Nov 16, 2018, 1:20:40 PM11/16/18
to Gremlin-users
Hello,

I am currently somewhat stuck on getting a custom P predicate to work nicely - I'm wondering if I may have gone down a rabbit hole.

We are working using Java-Gremlin. We have a need to be able to use a String.contains(), String.startsWith() and String.endsWith() to filter vertices by properties. Having had a good read of various pieces of documentation it seemed that implementing a simple custom BiPredicates was a sensible way to go i.e.:

public class ContainsPredicate implements Serializable, BiPredicate<Object, Object> {


   
@Override
   
public boolean test( Object first, Object second ) {
       
boolean result;
       
if ( isNotNullOrEmpty( first ) && isNotNullOrEmpty( second ) ) {
            result
= first.toString().contains( second.toString() );
       
} else {
            result
= false;
       
}
       
return result;
   
}


   
private boolean isNotNullOrEmpty( Object o ) {
       
return o != null && !o.toString().isEmpty();
   
}
   
   
public static P<Object> contains( Object value ) {
       
BiPredicate<Object, Object> pred = new ContainsPredicate();
       
return new P<>( pred, value );
   
}
}

This has worked fine for me with unit tests run against a local tinker graph, where the gremlin query is something like:

g.V().hasLabel("person").has( "name", ContainsPredicate.contains( "sh" ) ).values().toList()


Would get me the values for the vertex for Josh from the Modern toy graph.

So far so good.

The sticking point has been talking to a remote TinkerPop instance - I am not sure how to get the remote TinkerPop server to have my class available. I have tried: adding a plugins line
org.apache.tinkerpop.gremlin.jsr223.ImportGremlinPlugin: {classImports: [com.predicates.ContainsPredicate], methodImports: [com.service.predicates.ContainsPredicate#*]},

and / or putting an import statement in the startup script (generate-empty.groovy):
import com.predicates.*

and setting the serializeToString option to false. I believe I have Wildfly configured correctly to make my class available on the classpath (i.e. the calling code can see it, it's the test remote that can't - both in the same Wildfly instance)

I am consistently getting the error: Request [PooledUnsafeDirectByteBuf(ridx: 245, widx: 245, cap: 279)] could not be deserialized by org.apache.tinkerpop.gremlin.driver.ser.AbstractGryoMessageSerializerV3d0.: java.lang.IllegalStateException: org.apache.tinkerpop.gremlin.process.traversal.P.com.predicates.ContainsPredicate@2aa0e166(java.lang.Object)

Which is caused by: java.lang.NoSuchMethodException: org.apache.tinkerpop.gremlin.process.traversal.P.com.predicates.ContainsPredicate@2aa0e166(java.lang.Object)

I've attached the relevant log fragment.

Not sure what the correct way to proceed would be: am I barking up the wrong tree completely, have I missed something obvious or would I need to think about putting together a TinkerPop plugin to make it available?

Any help gratefully received,

Gareth Jones

logFragment.txt

Stephen Mallette

unread,
Nov 19, 2018, 9:24:39 AM11/19/18
to gremli...@googlegroups.com
It's a serialization problem. The gryo serializer doesn't know how to deal with your custom P. You need to add a custom serializer for your `P` then make Gryo know about it on the server and the client via IoRegistry. Before you go worrying about that though, is it possible for you to use 3.4.0-SNAPSHOT? it already has those predicates built in....

--
You received this message because you are subscribed to the Google Groups "Gremlin-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/c434e388-2573-4de5-a13b-9ccf5ba5ebac%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Gareth Jones

unread,
Nov 19, 2018, 9:39:41 AM11/19/18
to Gremlin-users
Thankyou Stephen :)

I had been looking through the TinkerPop source this morning and had realised that the PSerializer had no way to know what to do with my class, I had been trying to work my way through the IO registry code to understand how to come up with something that works. 3.4.0-SNAPSHOT may be an option, I'll need to have a play.

Much appreciated,

Gareth
Reply all
Reply to author
Forward
0 new messages