HashMap as a property value

1,257 views
Skip to first unread message

John

unread,
Jun 18, 2015, 9:38:51 AM6/18/15
to aureliu...@googlegroups.com
Hello,

Titan version:  Titan 0.9.0-M2.

I'm trying to add a hash map as a property-value to one one of the edges in my titan graph. But 0.9.0-M2 is not allowing me to do so.

Code: 
gremlin> e = g.V(40964272).outE('follows').next()
gremlin> e.property('map', ['0':'1','2':'3'])
Property value [{0=1, 2=3}] is of type class java.util.LinkedHashMap is not supported
Display stack trace? [yN] y
java.lang.IllegalArgumentException: Property value [{0=1, 2=3}] is of type class java.util.LinkedHashMap is not supported
        at org.apache.tinkerpop.gremlin.structure.Property$Exceptions.dataTypeOfPropertyValueNotSupported(Property.java:159)
        at com.thinkaurelius.titan.graphdb.transaction.StandardTitanTx.verifyAttribute(StandardTitanTx.java:563)
        at com.thinkaurelius.titan.graphdb.relations.AbstractTypedRelation.property(AbstractTypedRelation.java:106)
        at com.thinkaurelius.titan.core.TitanElement$property.call(Unknown Source)
        at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)

Just to inform, this is the same with Date, ArrayList and HashMap. I have tried to add values of those datatypes and also along with the dataType as  "Object.class" and I failed.  

I was able to do this in Titan 0.5.2 and i'm guessing this is a bug in the latest version. ( I may be wrong but I dug into the code and saw that that ArrayList,HashMap are not registered/handled)

If anyone faced this kind of issue, please kindly help me out. 

Thanks.


Matthias Broecheler

unread,
Jun 19, 2015, 8:41:21 PM6/19/15
to aureliu...@googlegroups.com
Hello John,

actually, this is not a bug. We are tightening up the serialization system in Titan 1.0 by only allowing a certain set of classes as property values and requiring users to register serializers for everything else.

Earlier version of Titan allowed users to pretty much serialize anything into the graph but that turned into a huge maintenance headache.

HTH,
Matthias

--
You received this message because you are subscribed to the Google Groups "Aurelius" group.
To unsubscribe from this group and stop receiving emails from it, send an email to aureliusgraph...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/aureliusgraphs/65cabc51-a625-4144-961e-d536dfd5060c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Matthias Broecheler

unread,
Jun 19, 2015, 8:42:43 PM6/19/15
to aureliu...@googlegroups.com
It should support Date and Instant though. Can you double check those and file a bug if discovered otherwise?

John

unread,
Jun 22, 2015, 12:56:29 PM6/22/15
to aureliu...@googlegroups.com
Hello Matthias,

Thanks for reply. The fact that your are allowing only a few classes as property values makes sense. 

-So the only way to use custom classes is by writing your serializer and then register it or do you have plans of allowing some more classes in Titan 1.0?

- I'll check the Date and Instant properties again and update.

Thanks.

Matthias Broecheler

unread,
Jun 22, 2015, 2:24:21 PM6/22/15
to aureliu...@googlegroups.com
We currently plan to go with the classes that are supported at this point into Titan 1.0 unless there are specific popular needs that we have failed to address so far.
However, in particular collection classes won't be supported since that causes big issues in serializing (due to arbitrary contained objects).

John

unread,
Jun 23, 2015, 9:28:01 PM6/23/15
to aureliu...@googlegroups.com
Hello Matthais,

Regarding the Date class:

- I was able to create a property with the datatype as "Date.class" and I could add the property as shown below.

gremlin> e.property('timeStamp',new Date('Sun Dec 14 18:11:59 +0000 2014'))
==>p[timeStamp->Sun Dec 14 13:11:59 ]
gremlin> g.tx().commit()
==>null
gremlin> e.values('timeStamp')
==>Sun Dec 14 13:11:59 EST 2014

However, the usage of the "new Date(String s)" constructor is deprecated and I'm not sure if I have to add the property this way. Plz kindly comment on this.

Then, I have tried to add the property the following way:

gremlin> e.property('timeStamp',new SimpleDateFormat("E dd MMM yyyy hh:mm:ss ZZZZZ").parse("Mon 22 Jun 2015 20:32:21 +0000"))
groovysh_evaluate: 3: unable to resolve class SimpleDateFormat
 @ line 3, column 24.
   e.property('timeStamp',new SimpleDateFormat("E dd MMM yyyy hh:mm:ss ZZZZZ").parse("Mon 22 Jun 2015 20:32:21 +0000"))
                          ^

1 error
Display stack trace? [yN] y

- Error: unable to resolve class SimpleDateFormat

I have tried a simpler example also but faced the same error:

gremlin> Date date = new SimpleDateFormat("ddMMyyyy").parse("28101978");
groovysh_evaluate: 3: unable to resolve class SimpleDateFormat
 @ line 3, column 13.
   Date date = new SimpleDateFormat("ddMMyyyy").parse("28101978");
               ^

1 error
Display stack trace? [yN] y

- I have attached the stack trace for the above errors. Please take a look at them.

Thanks.
dateClass-stacktrace.txt

Daniel Kuppitz

unread,
Jun 24, 2015, 8:02:17 AM6/24/15
to aureliu...@googlegroups.com
gremlin> import java.text.SimpleDataFormat
...

Cheers,
Daniel


John

unread,
Jun 24, 2015, 9:20:11 AM6/24/15
to aureliu...@googlegroups.com
Thanks Daniel.

JK

unread,
Jul 1, 2015, 1:11:28 PM7/1/15
to aureliu...@googlegroups.com
Hi John,

Could you possibly point us at any resources about building our own serialiser and how we can incorporate it within the system at large. It would be good to know if there are any limitations around using our own serialiser too... i.e. will we be able to use gremlin methods to filter/search against these objects.

We're trying to port some data which is in TP2 graphson format, and the legacy reader is spitting our errors:
java.io.IOException: java.lang.IllegalArgumentException: Property value <its a map> is of type class java.util.HashMap is not supported
We may have to implement our own loading method as much of our legacy graphson data will not make it through the legacy reader method.

-------------------------
The information in this message is private and confidential and may be legally privileged. If you have received this message in error, please notify us and remove it from your system. If you are not the intended recipient, any disclosure, copying, distribution or any action taken or omitted to be taken in reliance on it, is prohibited and may be unlawful.

For more information:
     Twitter: @semblent1
     LinkedIn: https://www.linkedin.com/company/semblent
     The Internet: www.semblent.com





-------------------------
The information in this message is private and confidential and may be legally privileged. If you have received this message in error, please notify us and remove it from your system. If you are not the intended recipient, any disclosure, copying, distribution or any action taken or omitted to be taken in reliance on it, is prohibited and may be unlawful.

For more information:
     Twitter: @semblent1
     LinkedIn: https://www.linkedin.com/company/semblent
     The Internet: www.semblent.com




John

unread,
Jul 21, 2015, 10:32:33 PM7/21/15
to Aurelius
Hello All,

Titan version: 0.9.0.M2

I'm trying to implement a custom serializer for using a HashMap as a property value. I have written my class according to the instructions provided in here. It implemets AttributeSerializer,has an equals method, and finally a no argument constructor. 

I have set my configuration options as follows:
  attributes.custom.attribute10.attribute-class = java.util.HashMap
 attributes.custom.attribute10.serializer-class = com.graph.HashMapSerializer

I have packaged the serializer into a jar and placed in the lib folder of the Titan distribution. I have tried to start Titan but see the error  'Need to set configuration value: root.attributes.custom.serializer-class' and also 'Could not instantiate configured serializer class'  in the 'gremlin-server'  logs. I have tried a bunch of options including changing the attribute number and placing in the jar in couple of different places but with no success.

Please kindly comment on whether I am doing this the right way and also possible solutions please. I have read in a Titan related post that the configuration keys might change from version to version, can this be the reason somehow?

Also can anyone please comment on how to specify the full 'custom-class' name ,  'custom-serializer' name ans where exactly to place the jar?

I can attach the code if needed. 

Thanks.

Jason Plurad

unread,
Jul 22, 2015, 5:14:36 PM7/22/15
to Aurelius

John

unread,
Jul 23, 2015, 3:48:46 PM7/23/15
to Aurelius, plu...@gmail.com
Thanks Jason for the useful comments.

 I was finally able to configure my graph properly and add a HashMap as a property value. But the problem is still not solved. When I am trying to access the value that I added, I get the following error. 

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Required size [1] exceeds actual remaining size [0]

For testing purposes I am doing this in Eclipse. Here is how I am adding the property value:

        TitanFactory.Builder config = TitanFactory.build();
        config.set("storage.backend", "cassandra");
        config.set("storage.directory", "C:/XXXXXXXXX/titan-0.9.0-M2-hadoop1/db/cassandra/data/test"); 
        
        TitanGraph graph = config.open();
        TitanManagement  mgmt = graph.openManagement();

        mgmt.set("attributes.custom.attribute1.attribute-class", "java.util.HashMap");
        mgmt.set("attributes.custom.attribute1.serializer-class", "com.graph.HashMapSerializer");
        
         mgmt.commit();
         graph.tx().commit();
        TitanGraph graph1 = config.open();


        HashMap<String,Integer> m = new HashMap<String,Integer>();
        m.put("test", 45); // Tried with new Integer(45)
      
        graph1.addVertex("map", m);
        graph1.tx().commit();      
        GraphTraversalSource g = graph1.traversal();
        Vertex v = g.V().has("map").next();
        System.out.println(v);

All of the above stuff happens in the main() method. I can add the vertex and can see it being created. But when I try to retrieve it or see the value I added, I get the above mentioned error. 

In the debug mode, I can see the serialization works correctly where the HashMap value is being serialized and de-serialized back again. Also, I'm able to add other vertices with primitive datatypes as property values and they work fine.

Not knowing where I am going wrong. In one of the posts where someone encountered the same error for a different reason, a solution of cleaning the database ( removing the keyspace ) and trying again was suggested. I tried that also but with no success.

Please comment on whether I'm doing anything wrong or if my approach is right. I am attaching the source of my 'HashMapSerializer' class and my Test class along with the stack trace. Please kindly take a look at them and leave any useful comments.

Lastly, I even tried this in the gremlin REPL using the tools that come along with Titan to make sure there are no cassandra or other versioning issues. But still no success. 

Thanks for your time guys.
HashMapSerializer.java.docx
TestSerializer.java.docx
StackTrace.docx

Jason Plurad

unread,
Jul 25, 2015, 8:36:49 AM7/25/15
to Aurelius, sman...@gmail.com
`storage.directory` isn't a valid setting for Cassandra. My guess is that you still had old attributes defined from previous attempts in your graph. Try dropping the titan keyspace in Cassandra and start with a fresh graph.

I've coded up a full example.
https://github.com/pluradj/titan-attribute-serializer

John

unread,
Jul 27, 2015, 10:08:19 AM7/27/15
to Aurelius, plu...@gmail.com
Hello Jason,

Thanks for the reply and thanks for your time. :)

In your example, the idea of using Titan's already existing byte array serializer , appears to do trick for me. I have used the byte array serializer from your example and it worked fine. Thanks for the detailed example.

However, like I mentioned before- a) I have tried dropping the keyspaces, b) can see the serialization happen properly but for some reason it was throwing the error. (Probably something wrong with my approach)

Anyways, I am going to chase it down in my free time and if at all anyone has seen my snippets and feel that something is not right, please feel free to comment.

Thanks Jason. Thanks guys.
Reply all
Reply to author
Forward
0 new messages