mpollmeier / gremlin-scala-examples

Examples for different graph dbs
Apache License 2.0
67 stars 34 forks source link

Titandb - scala map doesn't persist #14

Open sheshmantha opened 8 years ago

sheshmantha commented 8 years ago

hi, I've got a case class that has a scala Map. When I persist it in tinkergraph it works fine. When I persist in Titan, I get an error java.lang.IllegalArgumentException: Property value [Map(blah -> blah)] is of type class scala.collection.immutable.Map$Map1 is not supported.

Here is a spec for reproducing it using the InMemoryConnect.

@label("flight")
case class Flight(carrier: String, number: String)`

@label("segment")
case class Segment(duration: Int, origin: String, destination: String, data: Option[Map[String,String]])

with the following added to SimpleSpec.scala

"Gremlin-Scala in Titan" should "serialize nested class as properties" in {

    val graph = connect().asScala
    val flight = Flight("AA", "123")
    val seg = Segment(12, "ORD", "BOS", Some(Map("blah" -> "blah-blah")))
    val flightVertex = graph + flight // addVertex(flight)
    val segVertex = graph + seg

    flightVertex <-- "has" --- segVertex
    flightVertex --- "belongsTo" --> segVertex
    flightVertex.out("belongsTo").head() shouldBe segVertex
    graph.V(segVertex.id).out("has").head shouldBe flightVertex
    graph.close
  }

Do I need a marshaller ?

sheshmantha commented 8 years ago

I also tried the "use @label and @id annotations" from Marshallable.spec of gremlin-scala w/w/o the @id annotation and the Map definitely fails in same manner.

Property value [Map(key1 -> value1, key2 -> value2)] is of type class scala.collection.immutable.Map$Map2 is not supported
java.lang.IllegalArgumentException: Property value [Map(key1 -> value1, key2 -> value2)] is of type class scala.collection.immutable.Map$Map2 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:564)
    at com.thinkaurelius.titan.graphdb.transaction.StandardTitanTx.addProperty(StandardTitanTx.java:716)
    at com.thinkaurelius.titan.graphdb.transaction.StandardTitanTx.addProperty(StandardTitanTx.java:706)
    at com.thinkaurelius.titan.graphdb.vertices.AbstractVertex.property(AbstractVertex.java:135)
    at com.thinkaurelius.titan.core.TitanVertex.property(TitanVertex.java:58)
    at com.thinkaurelius.titan.graphdb.util.ElementHelper.attachProperties(ElementHelper.java:66)
    at com.thinkaurelius.titan.graphdb.tinkerpop.TitanBlueprintsTransaction.addVertex(TitanBlueprintsTransaction.java:110)
    at com.thinkaurelius.titan.graphdb.tinkerpop.TitanBlueprintsGraph.addVertex(TitanBlueprintsGraph.java:115)
    at com.thinkaurelius.titan.graphdb.tinkerpop.TitanBlueprintsGraph.addVertex(TitanBlueprintsGraph.java:33)
    at gremlin.scala.ScalaGraph.addVertex(ScalaGraph.scala:43)
    at gremlin.scala.ScalaGraph.$plus(ScalaGraph.scala:46)
    at SimpleSpec$$anonfun$3.apply$mcV$sp(SimpleSpec.scala:76)
sheshmantha commented 8 years ago

oops -- sorry -- recognized that it's Titan and that I need a Serializer... researching. will post answer when I find it.