inthefabric / Weaver

A fluent, strongly-typed Gremlin script generator (for .NET/C#).
www.inthefabric.com
Other
12 stars 0 forks source link

Auto-Add Vertex Centric Properties to Edges #4

Closed zachkinstner closed 11 years ago

zachkinstner commented 11 years ago

From inthefabric/Fabric#22:

Implement a way to automatically set an edge's VCI properties during addEdge(). I don't want to re-write the code for this process every time/place an edge is created.

I'm thinking something like this:

zachkinstner commented 11 years ago

Found an issue during some tests with Fabric data:

NullPointerException: Attribute cannot be null.

The issue occurs when a vertex property is not present -- like vertex b not having a set b.Something property in the example above.

The solution seems to be: build the property map (checking for existence) prior to the addEdge() call.

zachkinstner commented 11 years ago

Possible solution:

a = g.v(4);
b = g.v(8);
p = [:];
["Prop1", "Prop2", "Prop3"].each{ x ->
    v = a.getProperty(x);
    (v ? p.put(x, v) : null);
};
["Prop4", "Prop5", "Prop6"].each{ x ->
    v = b.getProperty(x);
    (v ? p.put(x, v) : null);
};
g.addEdge(a, b, "test", p);
zachkinstner commented 11 years ago

Another try:

a = g.v(592);
b = g.v(72);
p = [test:1234,edgeProp:true];
[[a,"A_AId"], [a,"fail"], [a,"N_FT"], [b,"Cl_Na"], [b,"A_Cr"]].each{
    x -> p.put(x.get(1), x.get(0).getProperty(x.get(1)))
};
p;

Produces (with Fabric test data):

{
    "results": [
        {
            "test": 1234,
            "edgeProp": true,
            "A_AId": 70,
            "N_FT": 3,
            "A_Cr": 635076256265176600
        }
    ],
    "success": true,
    "version": "2.4.0-SNAPSHOT",
    "queryTime": 31.234048
}
zachkinstner commented 11 years ago

This works:

a = g.v(592);
b = g.v(72);
p = [:];
[[a,"A_AId"], [a,"fail"], [a,"N_FT"], [b,"Cl_Na"], [b,"A_Cr"]].each{
    x -> v = x.get(0).getProperty(x[1]); (v ? p.put(x[1], v) : null)
};
e = g.addEdge(a,b,"testEdge",p);
zachkinstner commented 11 years ago

This works:

a = g.v(592);
b = g.v(72);
p = [:];
[A_AId:a, fail:a, N_FT:a, Cl_Na:b, A_Cr:b].each{
    k,v -> if ( (z=v.getProperty(k)) ) { p.put(k, z) }
};
e = g.addEdge(a,b,"testEdge",p);