-
Notifications
You must be signed in to change notification settings - Fork 76
Description
We are using gremlin-scala v-3.3.3.4. We use JanusGraph and have the following data model w.r.t case classes. For each vertex, we have two case classes one for writing to the database and one for reading from the database. The only difference is that the case class which is used for writing to the database has the id as Option[id]
whereas in the case class which used for reading from database the Id is not an Option
.
For example, we have the user vertex as follows:
@label("user") final case class UserDB(@id id: Option[Long], name: String, createdAt: Long)
@label("user") final case class UserVertex(@id id: Long, name: String, createdAt: Long)
// UserDB is used when the vertex is created
val user = graph + userDB
// UserVertex is when we convert the vertex in to the case class
val userVertex = user.toCC[UserVertex]
The reason why we have a different case class during the read is because we are sure that the Id is going to be there when we read from the Database and we can avoid matching on the Option[id]
to get the Id. Upgrading to the latest version of gremlin-scala is giving the following errors for the all case classes which doesn't have Id as Option
.
[error] java.lang.AssertionError: assertion failed: @id parameter *must* be of type `Option[A]`. In the context of Marshallable, we have to let the graph assign an id
[error] at scala.Predef$.assert(Predef.scala:219)
[error] at gremlin.scala.Marshallable$.handleId$1(Marshallable.scala:142)
[error] at gremlin.scala.Marshallable$.$anonfun$materializeMappableImpl$1(Marshallable.scala:163)
[error] at scala.collection.TraversableOnce.$anonfun$foldLeft$1(TraversableOnce.scala:156)
[error] at scala.collection.TraversableOnce.$anonfun$foldLeft$1$adapted(TraversableOnce.scala:156)
[error] at scala.reflect.internal.Scopes$Scope.foreach(Scopes.scala:408)
[error] at scala.collection.TraversableOnce.foldLeft(TraversableOnce.scala:156)
[error] at scala.collection.TraversableOnce.foldLeft$(TraversableOnce.scala:154)
[error] at scala.reflect.internal.Scopes$Scope.foldLeft(Scopes.scala:60)
[error] at gremlin.scala.Marshallable$.materializeMappableImpl(Marshallable.scala:28)
[error] .map(_.toCC[UserVertex])
We understand the error message we have to let the graph assign an id
which is only when adding the vertex to the database, but why is this enforced on toCC[UserVertex]
?