Skip to content

Unable to build a traversal dynamically with labelled steps #314

@aSapien

Description

@aSapien

There is a compilation error when building a traversal dynamically.

In my use case, I need to create a chain of Vertices from a dynamic-length list, and avoid creating existing chains (hence the coalesce steps)

Example:

  private def createChain(pathInGraph: List[String]) = {
    val Property = Key[String]("value")
    val Link = "Link"
    val Label = "PathComponent"

    val start = g.V.hasLabel(Label).property(Property -> pathInGraph.head).fold.coalesce(
      _.unfold[Vertex],
      _.addV(Label).property(Property -> pathInGraph.head)
    )

    pathInGraph.tail.foldLeft(start) {
      case (anchor, pathComponentValue) =>
        val step = StepLabel[Vertex]()

        anchor.as(step).coalesce(
          _.out(Link).hasLabel(Label).property(Property -> pathComponentValue),
          _.addV(Label).property(Property -> pathComponentValue).addE(Link).from(step).inV
        )
    }
  }

However, the above code fails to compile with error:

 error: type mismatch;
 found   : gremlin.scala.GremlinScala[org.apache.tinkerpop.gremlin.structure.Vertex]{type Labels = org.apache.tinkerpop.gremlin.structure.Vertex :: shapeless.HNil}
 required: gremlin.scala.GremlinScala[org.apache.tinkerpop.gremlin.structure.Vertex]{type Labels = shapeless.HNil}
        anchor.as(step).coalesce(
                                ^

If I remove the labelling step .as(label) it compiles, but then I'm unable to create Edges between the dynamically created chain Vertices.

I'm no expert in Shapeless so it's quite difficult for me to debug and come up with a solution.

Any ideas how I can overcome this error?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions