mpollmeier / gremlin-scala

[unmaintained] Scala wrapper for Apache TinkerPop 3 Graph DSL
Apache License 2.0
482 stars 76 forks source link

Unable to find the vertex which has multiple values when loading the graphson from file #229

Open JoeyKu opened 6 years ago

JoeyKu commented 6 years ago

Here is the source code:

// create graphson object and dump it to the file graphson.txt
  val g = TinkerGraph.open()
  val gScala = g.asScala
  val v = gScala.addVertex("Node", ("ip", "192.168.1.1"), ("ip", "192.168.1.2"), ("ip", "192.168.1.3"))
  val mapper = g.io(IoCore.graphson).mapper.normalize(true).version(GraphSONVersion.V2_0).create
  g.io(IoCore.graphson).writer.mapper(mapper).create.writeGraph(new FileOutputStream("./graphson.txt"), g)

  println(gScala.V().hasLabel("Node").has(Key[String]("ip"), "192.168.1.1").headOption())  // Some(v[0]) 
  println(gScala.V().hasLabel("Node").has(Key[String]("ip"), "192.168.1.2").headOption())  // Some(v[0])
  println(gScala.V().hasLabel("Node").has(Key[String]("ip"), "192.168.1.3").headOption())  // Some(v[0])

  // load it from file
  val gNew = TinkerGraph.open()
  val gScalaNew = gNew.asScala()

  val s: InputStream = new FileInputStream("./graphson.txt")
  gNew.io(IoCore.graphson()).reader().create().readGraph(s, gNew)

  // try to operate it
  println(gScalaNew.V().hasLabel("Node").has(Key[String]("ip"), "192.168.1.1").headOption())  // None (Why this is None?)
  println(gScalaNew.V().hasLabel("Node").has(Key[String]("ip"), "192.168.1.2").headOption())  // None (Why this is None?)
  println(gScalaNew.V().hasLabel("Node").has(Key[String]("ip"), "192.168.1.3").headOption())  // Some(v[0])
mpollmeier commented 6 years ago

you forgot to send the imports and key definition, I'm assume you're using this:

import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph
import gremlin.scala._
import scala.collection.JavaConverters._
import org.apache.tinkerpop.gremlin.structure.io.IoCore
import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONVersion
import java.io.FileOutputStream
import java.io.FileInputStream
import java.io.InputStream

val KeyString = Key[String]("ip")

When you switch to graphML you see what's wrong: g.io(IoCore.graphml).writeGraph("./graphml.xml") leads to: Multiple properties exist for the provided key, use Vertex.properties(ip) at org.apache.tinkerpop.gremlin.structure.Vertex$Exceptions.multiplePropertiesExistForProvidedKey(Vertex.java:179)

Looks like there's a problem with multi-properties and graph serialisation in gremlin-core. I've just tried it with gremlin-groovy which has the same problem:

graph = TinkerGraph.open()
g = graph.traversal()
v = g.addV().property('name','marko').property('name','marko a. rodriguez').next()
g.V(v).properties('name').count() //2

graph.io(IoCore.graphml()).writeGraph("multiprop.xml")
// error: Multiple properties exist for the provided key, use Vertex.properties(name)

In other words: it's not a gremlin-scala issue. Please ask on https://groups.google.com/forum/#!forum/gremlin-users about this and/or open an issue in jira: https://issues.apache.org/jira/projects/TINKERPOP/issues

aselamal commented 6 years ago

I just stumbled across this as well, and it seems like Tinkerpop won't support graphML export when List/Set cardinality is used.

https://issues.apache.org/jira/browse/TINKERPOP-1935