Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Mar 20 10:24
    nilay0016 opened #292
  • Jan 31 09:24
    hubertp closed #291
  • Jan 31 09:24
    hubertp commented #291
  • Jan 29 20:31
    mpollmeier review_requested #291
  • Jan 29 20:18

    mpollmeier on v3.4.4.5

    (compare)

  • Jan 29 20:10

    mpollmeier on master

    use 2.13.0 for cross-build bac… (compare)

  • Jan 29 10:29
    hubertp opened #291
  • Jan 29 00:26

    mpollmeier on v3.4.4.4

    (compare)

  • Jan 29 00:17

    mpollmeier on master

    Cross-compile to 2.13.0 as well… Merge pull request #290 from hu… (compare)

  • Jan 29 00:17
    mpollmeier closed #290
  • Jan 28 14:00
    hubertp review_requested #290
  • Jan 28 13:59
    hubertp opened #290
  • Dec 17 2019 19:39

    mpollmeier on v3.4.4.3

    (compare)

  • Dec 17 2019 19:32

    mpollmeier on master

    2.13 enforces postfixops (compare)

  • Dec 09 2019 23:48

    mpollmeier on v3.4.4.2

    (compare)

  • Dec 09 2019 23:40

    mpollmeier on master

    use latest sbt-ci-release-early… (compare)

  • Oct 24 2019 01:19
    mpollmeier commented #289
  • Oct 24 2019 01:13

    mpollmeier on v3.4.4.1

    (compare)

  • Oct 24 2019 01:04

    mpollmeier on master

    auto-tag next version (compare)

  • Oct 23 2019 22:03

    mpollmeier on master

    trigger release (sonatype was d… (compare)

Haruhiko Nishi
@hanishi
Hi, is there any example that shows how a vertex with all of its properties can be cloned.
I need this to make a snapshot of a current record. I was thinking of making a doubly linked list (using next and previous edges) and most recent one connected to the current vertex where all of previous properties are copied from and gets updated every time changes are detected.
Haruhiko Nishi
@hanishi
Haruhiko Nishi
@hanishi

In other words, how do I write

g.V(4).as('source').
  addV().
    property(label, select('source').label()).as('clone').
  sideEffect(                                                // copy vertex properties
    select('source').properties().as('p').
    select('clone').
      property(select('p').key(), select('p').value()))

in gremlin scala?

Haruhiko Nishi
@hanishi
it's the insideEffect enclosed clause that I want to mimic with scala-gremlin, if that's how I would to copy a vertex along with all of its properties.
Haruhiko Nishi
@hanishi
Maybe it's not doable but this is what I have so far and I am stuck.
def snapshot(g: Graph, label: String, currentV: Vertex, date: java.util.Date): Option[Vertex] = {
    g.V(currentV)
      .coalesce(_.out("previous").where(_.has(`updatedDate`, date)), cloneV(_, currentV)) headOption
  }

  private def cloneV(aux: GremlinScala.Aux[Vertex, HNil],
                     source: Vertex): GremlinScala.Aux[Vertex, HNil] = {

  }
Haruhiko Nishi
@hanishi
sns_ads.png
In the above, where the AdGroup or Ad pointing to another of its kind in both direction is what I want to accomplish.
Haruhiko Nishi
@hanishi
I thought about creating a new vertex with most recent property values and have the all IN/OUT edges drawn to/from connecting to it which will have the same effect, but copying and maintaining connections seemed more work to do than cloning a Vertex and move it behind.
Haruhiko Nishi
@hanishi
I am still new to both gremlin and gremlin-scala and appreciate if you could give me any advice. Thank you very much
Haruhiko Nishi
@hanishi
I haven't tried this yet, but do you think I need something like this?
  implicit class copyVertexProperties(aux: GremlinScala.Aux[Vertex, HNil]) {
    def copyProperties[A](source: Vertex, keys: Key[A]*): Aux[Vertex, HNil] = {
      keys.foreach(key => {
        source.valueOption(key) foreach { value =>
          aux.property(key, value)
        }
      })
      aux
    }
  }
Haruhiko Nishi
@hanishi

Here is an extension method that adds edges and returns the right most Vertex (which is previous to the currentV) to which I should apply the copyVertexProperties

  implicit class doublyLinkedList(g: Graph) {

    def insertV[A](currentV: Vertex, in: String, out: String): GremlinScala.Aux[Vertex, HNil] = {
      val p = StepLabel[Vertex]()
      g.V(currentV)
        .outE(in)
        .inV()
        .where(_.outE(out).inV().is(currentV))
        .fold()
        .coalesce(
          _.unfold[Vertex]()
            .sideEffect(_.bothE().where(_.otherV().is(currentV)).drop().iterate())
            .as(p)
            .addV(currentV.label)
            .addE(out)
            .from(p)
            .inV()
            .addE(in)
            .to(p)
            .outV(),
          _.addV(currentV.label)
        )
        .addE(in)
        .from(currentV)
        .inV()
        .addE(out)
        .to(currentV)
        .outV()
    }
  }

and use it like so.

g.insertV(adGroupV, "previous", "next") copyProperties(adGroupV, `name`) headOption()

I guess I need to copy properties manually. Due to the type safe nature of scala-gremlin, unlike gremlin-console that easily allows the copying all properties a vertex posses.

Haruhiko Nishi
@hanishi
Although, it's kind of lame to invoke copyProperties for every type of Key[A]
Haruhiko Nishi
@hanishi
By the way, I get the following when properties of a vertex happens to be a Set, how do modify my code to make this succeed?
java.lang.IllegalStateException: Multiple properties exist for the provided key, use Vertex.properties(targeting.excludedCustomAudiences)
    at org.apache.tinkerpop.gremlin.structure.Vertex$Exceptions.multiplePropertiesExistForProvidedKey(Vertex.java:179)
    at org.apache.tinkerpop.gremlin.structure.Vertex.property(Vertex.java:74)
    at org.apache.tinkerpop.gremlin.structure.Vertex.property(Vertex.java:38)
https://github.com/mpollmeier/gremlin-scala/blob/master/gremlin-scala/src/test/scala/gremlin/scala/ElementSpec.scala#L67
v.setPropertyList(TestProperty, List("one", "two", "three"))
This doesn't seem to be available anymore?
Haruhiko Nishi
@hanishi
This sort of worked in case when a Vertex possesses a property with List/Set cardinality, but looks very ugly. Is there a better way to write the same?
@mpollmeier
implicit class copyVertexProperties(aux: GremlinScala.Aux[Vertex, HNil]) {

    def copyProperties[A](source: Vertex, keys: Key[A]*): GremlinScala.Aux[Vertex, HNil] = {
      keys.foreach(
        key =>
          source
            .properties(key.name)
            .forEachRemaining((property: VertexProperty[A]) => setProperty(aux, key, property)))
      aux
    }

    private def setProperty[A](aux: GremlinScala.Aux[Vertex, HNil],
                               key: Key[A],
                               property: VertexProperty[A]): Unit = {
      aux.property(key, property.value)
      ()
    }
  }
Haruhiko Nishi
@hanishi

v.setPropertyList(TestProperty, List("one", "two", "three"))
This doesn't seem to be available anymore?

My build broke as 3.4.1.13 seemed to be longer available. When I fetched the latest3.4.4.3 I see those methods available. :)

Haruhiko Nishi
@hanishi

@mpollmeier

 def valueOption[A](key: Key[A]): Option[A] =
    element.property[A](key.name).toOption

This does not support retrieval of multiple properties however. Do you have any plan to support ? (If there is setPropertyListfor storing multiple values, I thought it would be nice if the reverse operation is supported as well)

Haruhiko Nishi
@hanishi
For now, I will use the following to achieve copying properties regardless of cardinality.(revised the above)
  implicit class copyVertexProperties(aux: GremlinScala.Aux[Vertex, HNil]) {

    def copyProperties[A](source: Vertex, keys: Key[A]*): GremlinScala.Aux[Vertex, HNil] = {
      keys.foreach { key =>
        values(source.properties[A](key.name), Nil) foreach { property =>
          aux.property(key, property.value)
        }
      }
      aux
    }

    private def values[A](iterator: util.Iterator[VertexProperty[A]],
                          list: List[VertexProperty[A]]): List[VertexProperty[A]] = {
      def iterate(iterator: util.Iterator[VertexProperty[A]],
                  list: List[VertexProperty[A]]): List[VertexProperty[A]] = {
        values(iterator, iterator.next :: Nil)
      }
      if (iterator.hasNext) list ::: iterate(iterator, list) else list
    }
  }
Haruhiko Nishi
@hanishi

By the way, I had to fix my insertV function to below after upgrading to 3.4.4.3 from 3.4.1.13

.where(_.outE(out).inV().is(currentV))
.sideEffect(.bothE().where(.otherV().is(currentV).drop().iterate())
to
.where(_.outE(out).inV().has(T.id, currentV.id))
.sideEffect(_.bothE().where(_.otherV().has(T.id, currentV.id)).drop().iterate())

to make my method work properly. When I was having the former with 3.4.1.13 the sideEffect clause was dropping both edges from the head of linked list after the 3 nodes.

has there been any changes made in is() operator?

    def insertV[A](currentV: Vertex, in: String, out: String): Aux[Vertex, HNil] = {
      val p = StepLabel[Vertex]()
      g.V(currentV)
        .outE(in)
        .inV()
        .where(_.outE(out).inV().has(T.id, currentV.id))
        .fold()
        .coalesce(
          _.unfold[Vertex]()
            .as(p)
            .sideEffect(_.bothE().where(_.otherV().has(T.id, currentV.id)).drop().iterate())
            .addV(currentV.label)
            .addE(out)
            .from(p)
            .inV()
            .addE(in)
            .to(p)
            .outV(),
          _.addV(currentV.label)
        )
        .addE(in)
        .from(currentV)
        .inV()
        .addE(out)
        .to(currentV)
        .outV()
    }
Bowofola
@bowofolaf
Hey all, From readme, When going from case classes to vertices, "List members will be stored as multi-properties, i.e. Cardinality.list". Is there a way to do Cardinality.set ?
Michael Pollmeier
@mpollmeier
@hanishi @bowofolaf currently i don't have capacity (and personal need) to expand the capabilities of gremlin-scala, sorry. I'm happy to help with PRs and moderation though.
Bowofola
@bowofolaf
@mpollmeier ah I wasn't asking about any extensions, just asking about current capability :)
Haruhiko Nishi
@hanishi
@bowofolaf
There is this, but I didn't find one that executesvertex.property(Cardinality.set, key, value)
  def setPropertyList[A <: AnyRef](key: String, values: List[A]): VertexProperty[A] = {
    removeProperty(Key[A](key), Cardinality.list)
    values
      .map { value =>
        vertex.property(Cardinality.list, key, value)
      }
      .lastOption
      .getOrElse(VertexProperty.empty[A])
  }
Michael Pollmeier
@mpollmeier
@bowofolaf so for case classes the capability to store them as 'set' doesn't exist - would need to be implemented in the Marshallable macro
Bowofola
@bowofolaf
@hanishi yea I think I found that, implementing my own wrapper that can do it. Thank all @mpollmeier
Haruhiko Nishi
@hanishi
スクリーンショット 2020-01-28 10.47.16.png
@mpollmeier
Hi, I have trouble understanding how select should be used. I am getting the "No implicit arguments of type: ..." as depicted in the screen capture above. What it is that I am not doing it properly?
Haruhiko Nishi
@hanishi
スクリーンショット 2020-01-28 11.29.40.png
Haruhiko Nishi
@hanishi
BTW, use of select() without specifying a tuple of StepLabeldoes not show this error and compiles fine.
Michael Pollmeier
@mpollmeier
@hanishi here's an example that works, maybe you can work your way back from there: https://github.com/mpollmeier/gremlin-scala/blob/master/gremlin-scala/src/test/scala/gremlin/scala/SelectSpec.scala#L61-L67
if not, can you share a minimal reproducable example? e.g. a small project that demonstrates your case
Haruhiko Nishi
@hanishi
@mpollmeier Thank you for your response.
I think I will clone the gremlin-scalarepo and see what the difference is. I don't know anything about shapeless so I have to study before digging into what's going on. (My Scala skill is limited) it could be my environmental setup that is causing the error.
Until I then, I have modified the code above to the following.
    .V()
        .has(`accountId`, account)
        .hasLabel("Date")
        .inE("results")
        .has(`Timestamp`)
        .order(By(Timestamp, Order.desc))
        .local(
          _.union(
            _.join(_.outV().inE("has").outV().inE("has").outV().value(`id`))
              .join(_.outV().inE("has").outV().value(`id`))
              .join(_.outV().value(`id`))
              .join(_.unionFlat(_.value(`impressions`), _.value(`clicks`), _.value(`cvs`)))))
        .toList()
I am starting to like gremlin btw.
Haruhiko Nishi
@hanishi
@mpollmeier
I have no idea, but the following compiled and ran without any problem even though the intelliJ was suggesting the error aforementioned.
スクリーンショット 2020-01-29 1.50.20.png
Haruhiko Nishi
@hanishi
By the way, would it be not a good idea to have an implicit conversion for
implicit def keyName[A](key: Key[A]): String = key.name ?
so I can just use Key[A] for ?
def values[A](key: String*)(implicit ev: End <:< Element) =
    GremlinScala[A, Labels](traversal.values[A](key: _*))
Haruhiko Nishi
@hanishi
Bowofola
@bowofolaf
@hanishi shapeless tracks the order of your aliases, that could be the problem. I think if you pass labels into select in the same order you aliased them, it should be fine.
Haruhiko Nishi
@hanishi
@bowofolaf
Thank you. I'll try and see if it works.
Michael Pollmeier
@mpollmeier
@hanishi having an implicit Key -> String is not a good idea, because String is a very basic type, so it would apply far too broadly (i.e. potentially to all functions that take a String)
Haruhiko Nishi
@hanishi

@mpollmeier
True, although I kind of did that myself in my code. Looks cleaner :)

 if (!mgmt.containsPropertyKey(name)) {
    mgmt.makePropertyKey(name).dataType(classOf[String]).cardinality(Cardinality.SINGLE).make()
  }

or this

 _.join(_.value(Timestamp))
              .join(_.constant(account))
              .join(_.outV().repeat(_.inE("has").outV()).times(2).value(`id`))
              .join(_.outV().inE("has").outV().value(`id`))
              .join(_.outV().value(`id`))
              .join(_.values[Int](
                `impressions`,
                `clicks`,
                `cvs`,
                `cost`,
                `3-second video views`,
                `Video watches at 25%`,
                `Video watches at 50%`,
                `Video watches at 75%`,
                `Video watches at 95%`,
where Video watches at 25% is Key[String]
Haruhiko Nishi
@hanishi
@mpollmeier Thank you for your insight very much appreciated
gremlin-scala has become indispensable for building our ads analyzing platform so thank you very much!
Endre Galaczi
@chiller

Hello. In the readme on gremlin-scala it says this in the section "mapping to and from case classes":

Annotating members with @id and @underlying will instruct the marshaller to set the element id and/or the underlying element in the class. Note: you cannot specify the id when adding a vertex like this.

I wonder why that is, and is there a way to get around it?

Michael Pollmeier
@mpollmeier
it's a good practice to let the graphdb assign the id rather than specifying it yourself, but other than that the reason is 'no one needed it yet'
Endre Galaczi
@chiller
Thanks
G-Ark
@G-Ark

Hello,

I am trying to merge two nodes in a graph using gremlin - Java.
Was able to generate the query using this SO answer - https://stackoverflow.com/a/46435070

g.V(parentNode).union(identity(), janusClient.g.V(aliasNode)) .unfold() .sideEffect(properties().group("p").by(T.key).by(value())) .sideEffect(__.outE().group("o").by(T.label).by(__.project("p","iv").by(__.valueMap()).by(__.inV()).fold())) .sideEffect(__.inE().group("i").by(T.label).by(__.project("p","ov").by(__.valueMap()).by(__.outV()).fold())) .sideEffect(__.drop()) .cap("p","o","i").as("poi") .addV().as("u") .sideEffect( __.select("poi").select("p").unfold().as("kv") .select("u").property(__.select("kv").select(Column.keys), __.select("kv").select(Column.values))) .sideEffect( __.select("poi").select("o").unfold().as("x").select(Column.values) .unfold().addE(__.select("x").select(Column.keys)).from(__.select("u")).to(__.select("iv"))) .sideEffect( __.select("poi").select("i").unfold().as("x").select(Column.values) .unfold().addE(__.select("x").select(Column.keys)).from(__.select("ov")).to(__.select("u"))).iterate();

The problem is with this line .addE(__.select("x").select(Column.keys)) in the last sideEffect step.

Replacing with String.valueOf(.addE(__.select("x").select(Column.keys))) does not yield the desired results.

Any help appreciated!

Nilay Gupta
@nilay0016

Hi, i am trying to make a test graph by adding vertex to it and return them while calling mock functions.

val gr = TinkerGraph.open().asScala()
val BTO_ID = Key[String](PropertyLabels.BTO_ID)
gr.addV(VertexLabels.BTO)
      .property(KeyValue(BTO_ID,id1))
      .property(KeyValue(FIRST_NAME,firstName1))
      .iterate()
println("VertexID GR -:"+gr.V(vertexId).headOption())
 Mockito.when(db.g).thenReturn(gr)

    Mockito.when(vertexIdGenerator.vertexId(VertexLabels.BTO, id1, PropertyLabels.BTO_ID)).thenReturn(vertexId)
    val result = btoService.getBTO(id1)

this println statement always returns null when i add headOptions(), The sevice class that i am testing -:

def getBTO(id: String) = {
    implicit val g = db.g
    val bto = g
    .V(
      vertexIdGenerator.vertexId(VertexLabels.BTO, id, PropertyLabels.BTO_ID))
      .headOption() match {
      case Some(value) => val x = value.getClass()
        value.toCC[BTOModel]
      case None        => throw BtoDoesNotExistException(s"BTO $id Does not exists")

    }
    println(res)
    BtoInfo(firstName = res.firstName,
            lastName = res.lastName,
            profilePic = res.profilePic)
  }

Link to stackoverflow question -:
https://stackoverflow.com/questions/60716402/how-to-test-a-dse-graph-based-scala-application