Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to build a traversal dynamically with labelled steps #314

Open
aSapien opened this issue Oct 11, 2022 · 0 comments
Open

Unable to build a traversal dynamically with labelled steps #314

aSapien opened this issue Oct 11, 2022 · 0 comments

Comments

@aSapien
Copy link

aSapien commented Oct 11, 2022

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant