>  I really like your idea of overloading addV() to take a map. I also
reaally like the idea of a step like propertyMap() which too would take a
map and be used like:

I was mostly using that syntax as an example, "but we've brought that up
before and it hasn't stuck". sorry that wasn't clear. I don't recall all
the problems with that approach but it won't solve the problem of dynamic
property assignment with a list of maps or anything like that. It just
allows you to pass a Map as an argument to addV(). I think we want to stick
with streams of things to keep with Gremlin's character. I'd also prefer
generalized approaches that further unify maps to graphs elements as we've
done a lot of that in the filtering steps over time.

Cypher uses MERGE in some fashion like this for updating vertices, so while
there is some SQL connotation it seems like there is at least some basis
for the use of the keyword in graphs. Perhaps merge() could even be better
adapted to that case to better cover "get or create" as it does in Cypher.
That way, we'd get rid of the coalesce()/fold()/unfold() patterns with
something more concise. On the other hand, that might make merge() do too
much. Just slanging ideas at this point.....


On Tue, Apr 28, 2020 at 10:25 AM Josh Perryman <[email protected]>
wrote:

> Stephen,
>
> Some really great thoughts here. This is a particular pain point with
> Gremlin and the current syntax for adding properties is extremely verbose.
> I strongly agree that developers are expecting to use a key-value type of
> data structure to set property values in an efficient manner.
>
> I'm leery of using the term merge() just for properties because it's usage
> in SQL is more at the entity level. I can see how it makes sense for the
> map manipulations, but I don't usually do those types of data manipulations
> within graph data.
>
> But for basic usability, I really like your idea of overloading addV() to
> take a map. I also reaally like the idea of a step like propertyMap() which
> too would take a map and be used like:
>
> g.addV('mylable').propertyMap(myProps)
>
> I've been refactoring my DAO these past few days and I'm finding a lot of
> my Java API design comes down to methods with signatures like
> addVertex(label, propertyMap). My implementation uses Java's Map.forEach()
> to build the traversals (after some schema validation on the inputs) much
> like your example.
>
> So hear my hearty agreement for an additional signature for addV(), and
> adding something like propertyMap() to make setting properties less
> verbose.
>
> Great stuff!
>
> Josh
>
>
> On Tue, Apr 28, 2020 at 8:08 AM Stephen Mallette <[email protected]>
> wrote:
>
> > It's interesting how questions about Gremlin go through phases of
> > popularity. For example, there was the period of "how do i search for
> > string property values that start with 'a'". Before that we had "how do i
> > do basic mathematical operations". In each case, we've added
> documentation
> > or new features that makes those questions die off and then something new
> > emerges as something everyone is trying to do.
> >
> > As of the last 6 months, I'd say the new popular thing to ask about has
> > been "how do I dynamically add properties to graph elements" or some
> > variation of that. I've written a blog post on the topic recently:
> >
> > http://stephen.genoprime.com/snippet/2020/03/28/snippet-7.html
> >
> > so that I can typically just paste that link to folks who need more
> > details. There are also a variety of SO and gremlin-users posts on the
> > topic and yet the question persists as there seem to always be new forms
> of
> > the question.
> >
> > In looking at the pattern we offer, it is a "complex" solution given
> that:
> >
> > 1. It is a sufficiently common task that actually has some neat benefits
> in
> > terms of performance - i.e. it is far better to send a shorter traversal
> > with a long list of parameters than a long traversal with tons of steps
> > (which we typically see folks do for "bulk loading")
> > 2. It is a task that new users who may not be familiar with Gremlin
> > immediately want to try and they don't see the "pattern" aspect of it -
> it
> > just looks like a blob of Gremlin to cut/paste
> >
> > I've often felt as though we'd missed something important in Gremlin
> where
> > we don't deal with Maps well. As it is a data type users work with
> > constantly, a typical expectation would be for Gremlin to allow:
> >
> > g.addV([T.label: "person", name:'marko', age: 29, country: 'usa'])
> >
> > While we know that doesn't fit our API exactly that's the kind of ease
> that
> > I think is expected rather than:
> >
> > v = g.addV("person").
> >       property("name", "marko").
> >       property("age", 29).
> >       property("country", "usa").next()
> >
> > or dynamically (not including T.label):
> >
> > m = [name:'marko',age:29,country:'usa']
> > g.withSideEffect('properties',m).
> >   addV('person').as('vertex').
> >   sideEffect(select('properties').
> >              unfold().as('kv').
> >              select('vertex').
> >              property(select('kv').by(Column.keys),
> >                       select('kv').by(Column.values)))
> >
> > An interesting parallel to this is the merging of Map instances which is
> > another common collection manipulation function. Here's a rough
> > demonstration of it:
> >
> > gremlin>
> > g.inject([name:'marko'],[age:29]).unfold().group().by(keys).by(values)
> > ==>[name:[marko],age:[29]]
> >
> > which again relies on unfold() to deconstruct the maps into key/value
> > pairs. This operation is quite analogous to what was done above for
> > dynamically setting properties (right down to the concept of
> > multi-properties).
> >
> > If we think of a Graph Element as a Map then we can unify these patterns
> > behind a step like merge() where you could push one set of key/values
> into
> > another. Roughly speaking merge() might be like:
> >
> > g.withSideEffect('properties',m).
> >   addV('person').
> >   merge('properties')
> >
> > Perhaps from() and to() modulators could come into play instead:
> >
> > g.withSideEffect('properties',m).
> >   addV('person').as('p').
> >   merge().from('properties).to('p')
> >
> > Which would let the following be equivalent:
> >
> > g.inject([name:'marko'],[age:29]).unfold().group().by(keys).by(values)
> > g.inject([name:'marko'],[age:29])..merge()
> >
> > and perhaps then:
> >
> > g.inject([name:'marko'],[age:29])..merge().by(unfold())
> >
> > which would have the effect of keeping single cardinality.
> >
> > Well, just something to think about since this issue keeps coming up
> again
> > and again. Happy to hear any thoughts on the topic.
> >
>

Reply via email to