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

How to use filter in comparing two strings #245

Closed
TitiHl opened this issue Jun 26, 2018 · 2 comments
Closed

How to use filter in comparing two strings #245

TitiHl opened this issue Jun 26, 2018 · 2 comments

Comments

@TitiHl
Copy link

TitiHl commented Jun 26, 2018

Hi,

Wanna ask how to convert following gremlin console code using gremlin-scala:
g.V().has("uuid", "someUuid").as("a").inE().as("e").outV().as("b").select("a", "b").by("uuid").filter{it.get().get("b").contains(it.get().get("a"))}.select("e").outV().valueMap("name")

This is a similar query from:
https://stackoverflow.com/questions/36045141/comparing-vertex-properties-in-gremlin-groovy

Thanks,
Alex

@mpollmeier
Copy link
Owner

mpollmeier commented Jun 30, 2018

select-by isn't supported in a typesafe way yet, there's #241 by @jeremysears to add this
However, since you're using lambdas anyway, you can do the following:

// your schema - define once globally somewhere
val uuid = Key[String]("uuid")
val name = Key[String]("name")
val a = StepLabel[Vertex]()
val b = StepLabel[Vertex]()
val e = StepLabel[Edge]()

val gs = g.V.has(uuid, "someUuid").as(a).inE.as(e).outV.as(b)
gs.select((a, b)).filterOnEnd { case (a, b) => b.value2(uuid) == a.value2(uuid)}
  .select(e).outV.value("name")

Note that I only checked that it compiles, since I don't have a test graph to verify it.

@TitiHl
Copy link
Author

TitiHl commented Jul 2, 2018

This looks cool. cleaner than what I have come up with the GraphTraversal way. Thanks 👍

@TitiHl TitiHl closed this as completed Jul 2, 2018
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

2 participants