How to configure properties types in JanusGraph?

852 views
Skip to first unread message

Tomasz

unread,
Oct 21, 2017, 4:34:10 AM10/21/17
to Gremlin-users
I want to create vertex with 'confirmed' property which should be a boolen data type. Currently, when I add vertex I do it as follows:

 g.addV('Sample').property(confirmed', '0')


The '0' value is string type. I want to insert the value which will be the boolen type.

I found information about configuring data types in Janus: http://docs.janusgraph.org/latest/schema.html. According to it, I can do it as follows:

mgmt = graph.openManagement()
confirmed
= mgmt.makePropertyKey('confirmed').dataType(Boolean.class).cardinality(Cardinality.SINGLE).make()
mgmt
.commit()

 
I use gremlin-python, that's why I ask here not in JanusGraph groups. I try to execute above code on my graph object which is Graph class type (graph = Graph(), Graph is - from gremlin_python.structure.graph import Graph) but I get an error that there is no openManagement() method on graph object.

I confused how to pass that configutation via gremlin-python to Janus Graph. Maybe I should do in not via Gremlin but in some configuration file od JanusGraph.

How can I add a property of certain type using gremlin-python to JanusGraph database?



Robert Dale

unread,
Oct 21, 2017, 7:53:21 AM10/21/17
to gremli...@googlegroups.com
GLVs only support the traversal API. Schema management is database-specific. Thus, you will need to submit database schema changes as a script to be evaluated on the remote Gremlin Server. You can use the gremlin-python driver to submit scripts.  Be sure to use the matching version (JanusGraph 0.2 -> TinkerPop 3.2.6).



Robert Dale

--
You received this message because you are subscribed to the Google Groups "Gremlin-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/6232df75-8618-4ead-86f2-7e5149915c4d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jason Plurad

unread,
Oct 21, 2017, 8:56:13 AM10/21/17
to gremli...@googlegroups.com
Dave Brown had an example of how to send a schema transaction via Python client on this thread on janusgraph-users
https://groups.google.com/forum/m/?source=mog&gl=us#!topic/janusgraph-users/4aEjYjvzhX8


On Sat, Oct 21, 2017 at 4:53 AM Robert Dale <rob...@gmail.com> wrote:
GLVs only support the traversal API. Schema management is database-specific. Thus, you will need to submit database schema changes as a script to be evaluated on the remote Gremlin Server. You can use the gremlin-python driver to submit scripts.  Be sure to use the matching version (JanusGraph 0.2 -> TinkerPop 3.2.6).



Robert Dale
On Sat, Oct 21, 2017 at 4:34 AM, Tomasz <troj...@gmail.com> wrote:
I want to create vertex with 'confirmed' property which should be a boolen data type. Currently, when I add vertex I do it as follows:

 g.addV('Sample').property(confirmed', '0')


The '0' value is string type. I want to insert the value which will be the boolen type.

I found information about configuring data types in Janus: http://docs.janusgraph.org/latest/schema.html. According to it, I can do it as follows:

mgmt = graph.openManagement()
confirmed
= mgmt.makePropertyKey('confirmed').dataType(Boolean.class).cardinality(Cardinality.SINGLE).make()
mgmt
.commit()

 
I use gremlin-python, that's why I ask here not in JanusGraph groups. I try to execute above code on my graph object which is Graph class type (graph = Graph(), Graph is - from gremlin_python.structure.graph import Graph) but I get an error that there is no openManagement() method on graph object.

I confused how to pass that configutation via gremlin-python to Janus Graph. Maybe I should do in not via Gremlin but in some configuration file od JanusGraph.

How can I add a property of certain type using gremlin-python to JanusGraph database?



--
You received this message because you are subscribed to the Google Groups "Gremlin-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-user...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Gremlin-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/CABed_4pJdhXYt7xe2fzvc14hcUVLQTMiNTMV3BTP%2BLn53%3D9C%2Bg%40mail.gmail.com.

Tomasz

unread,
Oct 21, 2017, 4:16:58 PM10/21/17
to Gremlin-users
Thank you for information.
I have another problem, I added a datatype to number and it works but I get a warning:

458911 [gremlin-server-exec-2] WARN  org.apache.tinkerpop.gremlin.server.op.AbstractEvalOpProcessor  - Exception processing a script on request [RequestMessage{, requestId=a2de96bf-ccf5-4bf0-9332-a8e5fd3d4cbb, op='eval', processor='', args={gremlin=mgmt = graph.openManagement()
                number
= mgmt.makePropertyKey('number').dataType(Integer.class).cardinality(Cardinality.SINGLE).make()
                mgmt
.commit(), aliases={g=g}}}].
org
.janusgraph.core.SchemaViolationException: Adding this property for key [~T$SchemaName] and value [rt number] violates a uniqueness constraint [SystemIndex#~T$SchemaName]
    at org
.janusgraph.graphdb.transaction.StandardJanusGraphTx.addProperty(StandardJanusGraphTx.java:793)
    at org
.janusgraph.graphdb.transaction.StandardJanusGraphTx.addProperty(StandardJanusGraphTx.java:722)
    at org
.janusgraph.graphdb.transaction.StandardJanusGraphTx.makeSchemaVertex(StandardJanusGraphTx.java:849)
    at org
.janusgraph.graphdb.transaction.StandardJanusGraphTx.makePropertyKey(StandardJanusGraphTx.java:869)
    at org
.janusgraph.graphdb.types.StandardPropertyKeyMaker.make(StandardPropertyKeyMaker.java:100)
    at org
.janusgraph.core.schema.PropertyKeyMaker$make$7.call(Unknown Source)
    at org
.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
    at org
.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
    at org
.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117)
    at
Script8.run(Script8.groovy:2)
    at org
.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine.eval(GremlinGroovyScriptEngine.java:843)
    at org
.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine.eval(GremlinGroovyScriptEngine.java:548)
    at javax
.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:233)
    at org
.apache.tinkerpop.gremlin.groovy.engine.ScriptEngines.eval(ScriptEngines.java:120)
    at org
.apache.tinkerpop.gremlin.groovy.engine.GremlinExecutor.lambda$eval$0(GremlinExecutor.java:290)
    at java
.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java
.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java
.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java
.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java
.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java
.lang.Thread.run(Thread.java:748)

I don't understand what means that it "violates a uniqueness constraint". Could you explain me it?

Jason Plurad

unread,
Oct 23, 2017, 11:46:25 AM10/23/17
to Gremlin-users
You typically see that error when you're trying to define a property key that already exists. You should check with the management system if the property exists before creating it.

Tomasz

unread,
Oct 25, 2017, 1:18:52 PM10/25/17
to Gremlin-users
My question is related to the code:

mgmt = graph.openManagement()
number
= mgmt.makePropertyKey('number').dataType(Integer.class).cardinality(Cardinality.SINGLE).make()
...
...
mgmt
.commit()

Should I run the code each time when I start my app or should I run it 'once' and it will be saved somewhere is JanusGraph config?

Robert Dale

unread,
Oct 25, 2017, 10:07:45 PM10/25/17
to gremli...@googlegroups.com
The schema is persisted to the database and becomes available to all graph instances.

Robert Dale

To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/095f5010-4f7d-4760-bcd8-262367c8f4d5%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages