2

我正在使用图书馆gremlin-scala与 Janusgraph 进行交互。

使用 DSL,插入新顶点的一种方法是执行以下操作:

val Id = Key[Long]("id")
val Name = Key[String]("name")
graph + ("label", Id -> 42, Name -> "Mike")

我想把这部分变成一个函数("label", Id -> 42, Name -> "Mike")

case class VertexModel(id: Long, name: String) {
  def toVertex: (Label, KeyValue[Long], KeyValue[String]) = {
    val Id = Key[Long]("id")
    val Name = Key[String]("name")
    ("item", Id -> id, Name -> name)
  }
}

val model = VertexModel(1, "Bill")
graph + model.toVertex

这失败并出现以下错误:

Error:(26, 11) type mismatch;
 found   : T1
 required: gremlin.scala.Label
    (which expands to)  String
    graph + vertex
Error:(26, 11) type mismatch;
 found   : T2
 required: gremlin.scala.KeyValue[Long]
    graph + vertex
Error:(26, 11) type mismatch;
 found   : T3
 required: gremlin.scala.KeyValue[String]
    graph + vertex

不知道如何解决这个问题。

4

1 回答 1

2

为什么需要扩展方法toVertex

这不就像

import gremlin.scala._
import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph

object App {

  implicit val graph: ScalaGraph = TinkerGraph.open.asScala

  case class VertexModel(id: Long, name: String) 

  val model = VertexModel(1, "Bill")
  graph + model
}

?

构建.sbt

scalaVersion := "2.12.8"
libraryDependencies += "com.michaelpollmeier" %% "gremlin-scala" % "3.4.0.4"
libraryDependencies += "org.apache.tinkerpop" % "tinkergraph-gremlin" % "3.4.0"
于 2019-03-21T14:39:22.060 回答