3

I am trying to create relationships in titan and trying to give an array with the properties at creation.

while (startNode.hasNext())
        {
            Vertex tempVertex = startNode.next();
            while (endNode.hasNext())
            {
                tempVertex.addEdge(storage.getId(), endNode.next(), keyValue);
            }
        }

But it's throwing the following error on edge creation.

int i = 0;
        for (Map.Entry<String, Object> entry : storage.getProperties().entrySet())
        {
            keyValue[i] = entry.getKey();
            keyValue[i + 1] = entry.getValue();
            i += 2;
        }

Normally the map should have the string at every even index already.

java.lang.IllegalArgumentException: The provided key/value array must have a String or T on even array indices
    at org.apache.tinkerpop.gremlin.structure.Element$Exceptions.providedKeyValuesMustHaveALegalKeyOnEvenIndices(Element.java:129)
    at org.apache.tinkerpop.gremlin.structure.util.ElementHelper.legalPropertyKeyValueArray(ElementHelper.java:117)
    at com.thinkaurelius.titan.graphdb.util.ElementHelper.attachProperties(ElementHelper.java:46)
    at com.thinkaurelius.titan.graphdb.vertices.AbstractVertex.addEdge(AbstractVertex.java:151)
    at com.thinkaurelius.titan.graphdb.vertices.AbstractVertex.addEdge(AbstractVertex.java:23)
    at main.java.com.bag.server.database.TitanDatabaseAccess.applyCreate(TitanDatabaseAccess.java:469)
    at main.java.com.bag.operations.CreateOperation.apply(CreateOperation.java:36)
    at main.java.com.bag.server.TestServer.executeCommit(TestServer.java:190)
    at main.java.com.bag.server.TestServer.appExecuteBatch(TestServer.java:138)
    at bftsmart.tom.server.defaultservices.DefaultRecoverable.executeBatch(DefaultRecoverable.java:87)
    at bftsmart.tom.server.defaultservices.DefaultRecoverable.executeBatch(DefaultRecoverable.java:68)
    at bftsmart.tom.ServiceReplica.receiveMessages(ServiceReplica.java:432)
    at bftsmart.tom.core.DeliveryThread.deliverMessages(DeliveryThread.java:293)
    at bftsmart.tom.core.DeliveryThread.run(DeliveryThread.java:225)
Jason Plurad
  • 6,682
  • 2
  • 18
  • 37
raycons
  • 735
  • 12
  • 26
  • What is the class type for `keyValue` in the second code block? You didn't show how it is being initialized. Is the code being run in Groovy or Java? – Jason Plurad Nov 22 '16 at 04:59
  • Do you have `null` values as keys at the end of the `keyValue` array? – Ralf Nov 22 '16 at 07:34
  • It's java code. keyValue is an Object[]. No I insert Strings and objects only. No null values. – raycons Nov 22 '16 at 09:55
  • 1
    Yes, but when you create the array you must initialize it to a certain length. If the length of the array is greater than `2 * storage.getProperties().entrySet().size()` then you end up with null values in the array. – Ralf Nov 22 '16 at 10:41
  • I'll edit the whole code. – raycons Nov 22 '16 at 10:44
  • 1
    Editing the code I found the error thanks, I inserted some null values. – raycons Nov 22 '16 at 10:45

0 Answers0