Repository: thinkaurelius/titan

Issue #1169: NPE when using repeat step with query.batch=true
Created: 2015-10-12T15:13:15Z
Version: Titan 1.0.0
This query works without issue with query.batch off.
Steps to reproduce using toy data with the relevant portion of the exception.
gremlin> graph = TitanFactory.open('./conf/titan-cassandra.properties')
==>standardtitangraph[cassandrathrift:[127.0.0.1]]
gremlin> g = graph.traversal()
==>graphtraversalsource[standardtitangraph[cassandrathrift:[127.0.0.1]], standard]
gremlin> v1 = graph.addVertex('id', 1)
==>v[4192]
gremlin> v2 = graph.addVertex('id', 2)
==>v[4096]
gremlin> v1.addEdge('knows', v2)
==>e[170-38g-28lx-35s][4192-knows->4096]
gremlin> g.tx().commit()
gremlin> g.V().has('id', 1).emit().repeat(out('knows'))
10:10:49 WARN  com.thinkaurelius.titan.graphdb.transaction.StandardTitanTx  - Query requires iterating over all vertices [(id = 1)]. For better performance, use indexes
==>v[4192]
java.lang.NullPointerException
Display stack trace? [yN] y
java.lang.NullPointerException
    at com.thinkaurelius.titan.graphdb.tinkerpop.optimize.TitanVertexStep.flatMap(TitanVertexStep.java:95)
    at org.apache.tinkerpop.gremlin.process.traversal.step.map.FlatMapStep.processNextStart(FlatMapStep.java:47)
    at com.thinkaurelius.titan.graphdb.tinkerpop.optimize.TitanVertexStep.processNextStart(TitanVertexStep.java:88)
    at org.apache.tinkerpop.gremlin.process.traversal.step.util.AbstractStep.hasNext(AbstractStep.java:140)
    at org.apache.tinkerpop.gremlin.process.traversal.step.util.ExpandableStepIterator.next(ExpandableStepIterator.java:54)
    at org.apache.tinkerpop.gremlin.process.traversal.step.branch.RepeatStep$RepeatEndStep.standardAlgorithm(RepeatStep.java:230)
    at org.apache.tinkerpop.gremlin.process.traversal.step.util.ComputerAwareStep.processNextStart(ComputerAwareStep.java:47)
    at org.apache.tinkerpop.gremlin.process.traversal.step.util.AbstractStep.hasNext(AbstractStep.java:140)
    at org.apache.tinkerpop.gremlin.process.traversal.step.branch.RepeatStep.standardAlgorithm(RepeatStep.java:143)
    at org.apache.tinkerpop.gremlin.process.traversal.step.util.ComputerAwareStep.processNextStart(ComputerAwareStep.java:47)
    at org.apache.tinkerpop.gremlin.process.traversal.step.util.AbstractStep.hasNext(AbstractStep.java:140)
    at org.apache.tinkerpop.gremlin.process.traversal.util.DefaultTraversal.hasNext(DefaultTraversal.java:117)

Duplicate issue #1243: Titan1.0.0, repeat().until() with Cassandra/multiQuery gives an NPE
Created: 2016-01-16T09:28:31Z
A query such as:
g.V().has("person", "name", "bob").repeat(.out("knows")).untilWithTraverser(!.get.outE("knows).traversal.hasNext).toList()
gives an NPE in TitanVertexStep at:
protected Iterator<E> flatMap(final Traverser.Admin<Vertex> traverser) {
    if (useMultiQuery) {
        assert multiQueryResults != null;
        return (Iterator<E>) multiQueryResults.get(traverser.get()).iterator();

while executing, multiQueryResults is null.
Looking into what happens, TitanLocalQueryOptimizerStrategy appears to do a fold on the until traversal.
        if (TitanTraversalUtil.isEdgeReturnStep(vstep)) {
            HasStepFolder.foldInHasContainer(vstep, traversal);
            //We cannot fold in orders or ranges since they are not local
        }

However, this causes TitanVertexStep to not create its multiQueryResults as at shortcuts initialisation at:
if (useMultiQuery) {
if (!starts.hasNext()) throw FastNoSuchElementException.instance();
which now gives the NPE during execution.

Closing comment (2016-02-06T00:33:03Z): It looks like this duplicates #1169.