Titan 1.0.0 Serialization/Deserialization

362 views
Skip to first unread message

b...@siftsec.com

unread,
Dec 15, 2015, 1:37:30 PM12/15/15
to Aurelius
Is there an example of using Titan's Serializers/Deserializers, without using TinkerPop? It sounds like Titan supports containers like ArrayList and HashMap, whereas TinkerPop does not. It looks like the API calls for a JsonParser and a Context? Is there a canonical way to produce these for I/O? Is this format interchangable with TinkerPop's GraphSON?

Jason Plurad

unread,
Dec 15, 2015, 2:48:27 PM12/15/15
to Aurelius
The thing you have to watch out for when serializing to GraphSON with custom attribute serializers in Titan is that you'll need to configure the mapper to embedTypes into the GraphSON so that they aren't lost.

Here's an example gremlin console run using your repo:

1. Build and export a graph with the custom attribute serializers

$ rm -rf ./db/ && ./bin/gremlin.sh
gremlin
> graph = TitanFactory.open('./conf/attr-titan-berkeleyje.properties')
==>standardtitangraph[berkeleyje:/Users/pluradj/src/github/laxatives/titan-1.0.0-hadoop1/./conf/../db/berkeley]
gremlin
> v = graph.addVertex()
==>v[4200]
gremlin
> v.property('hello', new StringBuffer('world'))
==>vp[hello->world]
gremlin
> m = [] as HashMap
gremlin
> m.name = 'rdu'; m.lat = 35.880; m.lon = -78.788
==>-78.788
gremlin
> v.property('poi', m)
==>vp[poi->{name=rdu, lon=-78.7]
gremlin
> l = [] as ArrayList
gremlin
> l.add('one'); l.add(2); l.add(3.0d);
==>true
gremlin
> v.property('nums', l)
==>vp[nums->[one, 2, 3.0]]
gremlin
> graph.tx().commit()
==>null
gremlin
> f = new FileOutputStream('/tmp/ser.json')
==>java.io.FileOutputStream@ccf91df
gremlin
> mapper = graph.io(graphson()).mapper().embedTypes(true).create()
==>org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONMapper@2100d047
gremlin
> graph.io(graphson()).writer().mapper(mapper).create().writeGraph(f, graph)
==>null
gremlin
> :q


2. Read back in the serialized GraphSON

$ rm -rf ./db/ && ./bin/gremlin.sh
gremlin
> graph = TitanFactory.open('./conf/attr-titan-berkeleyje.properties')
==>standardtitangraph[berkeleyje:/Users/pluradj/src/github/laxatives/titan-1.0.0-hadoop1/./conf/../db/berkeley]
gremlin
> f = new FileInputStream('/tmp/ser.json')
==>java.io.FileInputStream@608bc8f8
gremlin
> mapper = graph.io(graphson()).mapper().embedTypes(true).create()
==>org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONMapper@496a31da
gremlin
> graph.io(graphson()).reader().mapper(mapper).create().readGraph(f, graph)
==>null
gremlin
> v = graph.traversal().V().next()
14:42:30 WARN  com.thinkaurelius.titan.graphdb.transaction.StandardTitanTx  - Query requires iterating over all vertices [()]. For better performance, use indexes
==>v[4152]
gremlin
> v.values('hello').next().getClass()
==>class java.lang.StringBuffer
gremlin
> v.values('poi').next().getClass()
==>class java.util.HashMap
gremlin
> v.values('nums').next().getClass()
==>class java.util.ArrayList


-- Jason

b...@siftsec.com

unread,
Dec 15, 2015, 5:06:52 PM12/15/15
to Aurelius
Ah, right I think I've been getting a bit mixed up with the use cases for the the custom attribute serializers. It seems like they are absolutely necessary for translating GraphSON from TinkerPop2.5, with embedTypes=true. Can I discard them from Reading/Writing graphs to and from TinkerPop3 if I only need ArrayList and HashMap serializers? I'm under the impression that Titan already supports these formats.

Jason Plurad

unread,
Dec 16, 2015, 11:35:50 AM12/16/15
to Aurelius
Titan does not handle serialization of ArrayList and HashMap properties natively. The 1.0.0 documentation is incorrect, and a PR has been pushed to fix that. Out of the box, Titan serializes the types defined in StandardSerializer.java.

John

unread,
Feb 17, 2016, 2:38:28 PM2/17/16
to Aurelius

Hello,

I'm trying to load/import a graph into Titan(1.0.0). The graph is in the "extended"/"typed" GraphSON format. 

How can we specify "embedTypes()" option while using BulkLoaderVertexProgram?

Thanks.

Daniel Kuppitz

unread,
Feb 18, 2016, 5:05:13 AM2/18/16
to aureliu...@googlegroups.com
Already answered in another discussion, but again, this is not possible.
What you can do though, is to use ScriptInputFormat and parse each line manually.

Cheers,
Daniel


--
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/af9618d6-670e-4970-ac1c-7a23dc7fb316%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Tommy

unread,
Jun 16, 2016, 12:31:22 AM6/16/16
to Aurelius
Hi, Jason, I run this example in gremlin console and get errors:

This is my config:
attributes.custom.attribute1.attribute-class=java.lang.StringBuffer
attributes.custom.attribute1.serializer-class=pluradj.titan.graphdb.database.serialize.attribute.StringBufferSerializer
attributes.custom.attribute2.attribute-class=java.util.HashMap
attributes.custom.attribute2.serializer-class=pluradj.titan.graphdb.database.serialize.attribute.HashMapSerializer

By the way, I want to store data in Map and List dataType, is there any docs about this?
Thanks!


在 2015年12月16日星期三 UTC+8上午3:48:27,Jason Plurad写道:

Jason Plurad

unread,
Jun 16, 2016, 11:29:02 AM6/16/16
to Aurelius
Hi Tommy,

It looks like you need to make sure that the attributes.custom.attribute* classes when you first initialize the graph. In your screenshot, it looks like you opened titan-hbase-es.properties successfully followed by titan-hbase.properties -- and I'm guessing that they're both using the same storage.hbase.table name (titan is the default if you didn't set one). So I'd suggest you try dropping the existing titan table, then connect with the properties file you want to use and make sure it has the attributes defined in the file.

Docs on storing data as Map and List? No, there's nothing substantial. You could consider using TinkerPop meta-properties/multi-properties as an alternative http://tinkerpop.apache.org/docs/3.0.1-incubating/#vertex-properties

-- Jason

Tommy

unread,
Jun 17, 2016, 5:23:10 AM6/17/16
to Aurelius
Using TinkerPop meta-properties/multi-properties as an alternative is a good idea.
Thank you, Jason.

在 2016年6月16日星期四 UTC+8下午11:29:02,Jason Plurad写道:
Reply all
Reply to author
Forward
0 new messages