Bringing together the Apache Cassandra experts from the community and DataStax.

Want to learn? Have a question? Want to share your expertise? You are in the right place!

Not sure where to begin? Getting Started

 

question

rohansurana2810_190538 avatar image
rohansurana2810_190538 asked ·

Why is tokenRegex() returning a NullPointerException in a Graph traversal?

Hi,

I was trying out the tokenRegex() for searching one of the fields. It was working fine in the studio but in Java, it gave null pointer exception.

Ask Schema =>

schema.vertexLabel('Ask').
        ifNotExists().
        partitionBy('tenantId', Ascii).
        clusterBy('domainId', Ascii).
        property('askScope', Text).
        create()

Data==>

g.addV("Ask").property("tenantId", "t1").property("domainId", "d1").property("askScope","check")

Search Index =>

schema.vertexLabel('Ask').searchIndex().ifNotExists().by('askScope').asText().create()

In datastax studio =>

g.V().hasLabel("Ask").has("askScope",tokenRegex("check"))

output:

{
  "id": "dseg:/Ask/t1/d1",
  "label": "Ask",
  "type": "vertex",
  "properties": {}
}

These are the pom.xml dependencies

<dependency>
    <groupId>com.datastax.oss</groupId>
    <artifactId>java-driver-core</artifactId>
    <version>4.7.2</version>
</dependency>
<dependency>
    <groupId>org.apache.tinkerpop</groupId>
    <artifactId>gremlin-driver</artifactId>
    <version>3.4.5</version>
</dependency>
<dependency>
    <groupId>org.apache.tinkerpop</groupId>
    <artifactId>gremlin-core</artifactId>
    <version>3.4.5</version>
</dependency>

In java =>

GraphTraversal<Vertex, Vertex> vertex = g.V().hasLabel("Ask").has("askScope", Search.tokenRegex("check")).next();

Exception :

java.lang.NullPointerException: null
at java.util.concurrent.ConcurrentHashMap.get(ConcurrentHashMap.java:936)
at org.apache.tinkerpop.gremlin.driver.Handler$GremlinResponseHandler.channelRead0(Handler.java:221)
at org.apache.tinkerpop.gremlin.driver.Handler$GremlinResponseHandler.channelRead0(Handler.java:198)
at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:374)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:360)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:352)
at org.apache.tinkerpop.gremlin.driver.Handler$GremlinSaslAuthenticationHandler.channelRead0(Handler.java:124)
at org.apache.tinkerpop.gremlin.driver.Handler$GremlinSaslAuthenticationHandler.channelRead0(Handler.java:68)


On the server: /var/log/cassandra/gremlin.log

stack trace ==>

WARN  2020-06-29 22:12:11,484 DseOpSelectorHandler.java:115 - Invalid OpProcessor requested [null]
org.apache.tinkerpop.gremlin.server.op.OpProcessorException: Invalid OpProcessor requested [null]
at com.datastax.bdp.graph.plugin.DseOpSelectorHandler.decode(DseOpSelectorHandler.java:109)
at com.datastax.bdp.graph.plugin.DseOpSelectorHandler.decode(DseOpSelectorHandler.java:43)
at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:88)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)
at com.datastax.bdp.graph.plugin.GremlinServerGraphHandler.handleRequestMessage(GremlinServerGraphHandler.java:47)
at com.datastax.bdp.graph.plugin.AbstractRequestMessageHandler.channelRead(AbstractRequestMessageHandler.java:63)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)
at com.datastax.bdp.cassandra.audit.GremlinServerAuditLogRequestHandler.handleRequestMessage(GremlinServerAuditLogRequestHandler.java:37)
at com.datastax.bdp.graph.plugin.AbstractRequestMessageHandler.channelRead(AbstractRequestMessageHandler.java:63)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)
at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102)


On the server: /var/log/cassandra/system.log

stack trace ==>

WARN  [gremlin-server-worker-1] 2020-06-30 07:30:57,571  AbstractGryoMessageSerializerV3d0.java:211 - Request [PooledUnsafeDirectByteBuf(ridx: 150, widx: 150, cap: 184)] could not be deserialized by org.apache.tinkerpop.gremlin.driver.ser.AbstractGryoMessageSerializerV3d0.
java.lang.IllegalStateException: org.apache.tinkerpop.gremlin.process.traversal.P.tokenRegex(java.lang.Object)
at org.apache.tinkerpop.gremlin.structure.io.gryo.GryoSerializersV3d0$PSerializer.read(GryoSerializersV3d0.java:343)
at org.apache.tinkerpop.gremlin.structure.io.gryo.GryoSerializersV3d0$PSerializer.read(GryoSerializersV3d0.java:291)
at org.apache.tinkerpop.gremlin.structure.io.gryo.kryoshim.shaded.ShadedSerializerAdapter.read(ShadedSerializerAdapter.java:52)
at org.apache.tinkerpop.shaded.kryo.Kryo.readObject(Kryo.java:708)
at org.apache.tinkerpop.shaded.kryo.serializers.DefaultArraySerializers$ObjectArraySerializer.read(DefaultArraySerializers.java:396)
at org.apache.tinkerpop.shaded.kryo.serializers.DefaultArraySerializers$ObjectArraySerializer.read(DefaultArraySerializers.java:307)
at org.apache.tinkerpop.shaded.kryo.Kryo.readObject(Kryo.java:686)
at org.apache.tinkerpop.gremlin.structure.io.gryo.kryoshim.shaded.ShadedKryoAdapter.r...........
SingleThreadEventExecutor.java:884)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NoSuchMethodException: org.apache.tinkerpop.gremlin.process.traversal.P.tokenRegex(java.lang.Object)
at java.lang.Class.getMethod(Class.java:1786)
at org.apache.tinkerpop.gremlin.structure.io.gryo.GryoSerializersV3d0$PSerializer.read(GryoSerializersV3d0.java:341)
... 65 common frames omitted


Thank you

dsegraph
10 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

1 Answer

bettina.swynnerton avatar image
bettina.swynnerton answered ·

Hi,

thanks for providing the schema and example data, this allowed me to run a quick test.

The following worked for me on DSE Graph 6.8.1, java driver version 4.7.2:

import com.datastax.dse.driver.api.core.graph.FluentGraphStatement;
import com.datastax.dse.driver.api.core.graph.GraphNode;
import com.datastax.dse.driver.api.core.graph.GraphResultSet;
import com.datastax.dse.driver.api.core.graph.predicates.Search;
import com.datastax.oss.driver.api.core.CqlSession;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
import org.apache.tinkerpop.gremlin.structure.Vertex;

import static com.datastax.dse.driver.api.core.graph.DseGraph.g;

public class Test {
    public static void main(String[] args) 

        try (CqlSession session = CqlSession.builder().build()) {

            GraphTraversal<Vertex, Vertex> traversal = g.V().hasLabel("Ask").has("askScope", Search.tokenRegex("check"));
            FluentGraphStatement statement2 = FluentGraphStatement.newInstance(traversal);

            GraphResultSet result2 = session.execute(statement2);
            for (GraphNode node : result2) {
                System.out.println(node.asVertex());
            }
        }
    }
}

To construct the GraphTraversal I had to remove the `next()` step from the traversal that you gave in your question. Let me have a more complete snippet of your java code, so I can see the context.

Cheers!

7 comments Share
10 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Thank you for the quick response, here is my code snippet,

import com.datastax.dse.driver.api.core.graph.predicates.Search;
import org.apache.tinkerpop.gremlin.driver.remote.DriverRemoteConnection;
import org.apache.tinkerpop.gremlin.process.traversal.AnonymousTraversalSource;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;

public class Test {
    public static void main(String[] args) throws Exception{

        GraphTraversalSource g = AnonymousTraversalSource.traversal().withRemote(DriverRemoteConnection.using(cluster, "withComment.g"))

        GraphTraversal<Vertex, Vertex> trav = g.V().hasLabel("Ask").has("askScope", Search.tokenRegex("check"));
        System.out.println(trav.valueMap().toList());

        g.close()
    }
}
0 Likes 0 · ·

Also,

On the server: /var/log/cassandra/system.log

stack trace ==>

WARN  [gremlin-server-worker-1] 2020-06-30 07:30:57,571  AbstractGryoMessageSerializerV3d0.java:211 - Request [PooledUnsafeDirectByteBuf(ridx: 150, widx: 150, cap: 184)] could not be deserialized by org.apache.tinkerpop.gremlin.driver.ser.AbstractGryoMessageSerializerV3d0.
java.lang.IllegalStateException: org.apache.tinkerpop.gremlin.process.traversal.P.tokenRegex(java.lang.Object)
at org.apache.tinkerpop.gremlin.structure.io.gryo.GryoSerializersV3d0$PSerializer.read(GryoSerializersV3d0.java:343.....
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NoSuchMethodException: org.apache.tinkerpop.gremlin.process.traversal.P.tokenRegex(java.lang.Object)
at java.lang.Class.getMethod(Class.java:1786)
at org.apache.tinkerpop.gremlin.structure.io.gryo.GryoSerializersV3d0$PSerializer.read(GryoSerializersV3d0.java:341)
... 65 common frames omitted
0 Likes 0 · ·

Hi @rohansurana2810_190538,

could you please confirm your versions for me? DSE version and driver version?

Thanks!

0 Likes 0 · ·
rohansurana2810_190538 avatar image rohansurana2810_190538 bettina.swynnerton ♦♦ ·

Sure, here it is

DSE version - 6.8.1

Java driver version - 4.7.2

Also other dependencies:

<dependency>
    <groupId>com.datastax.oss</groupId>
    <artifactId>java-driver-core</artifactId>
    <version>4.7.2</version>
</dependency>
<dependency>
    <groupId>org.apache.tinkerpop</groupId>
    <artifactId>gremlin-driver</artifactId>
    <version>3.4.5</version>
</dependency>
<dependency>
    <groupId>org.apache.tinkerpop</groupId>
    <artifactId>gremlin-core</artifactId>
    <version>3.4.5</version>
</dependency>


Thank you!

0 Likes 0 · ·
Show more comments