3

Getting some problem while playing with JanusGraph. I am new in JanusGraph recently I have installed and followed the documentation for add vertex with its properties and few more but when I am trying to insert a property of float digit and set the key as "abc" and value would be 9.5f in this case I got an error but in the same query when I change the key to "a" or something else it works fine.

Example with key abc

g.addV("T22").property("abc", 9.5f)

Error

Value [9.5] is not an instance of the expected data type for property key [abc] and cannot be converted. Expected: class java.lang.Integer, found: class java.lang.Float

Example with key a

g.addV("T22").property("a", 9.5f) working fine

g.V(163848208).valueMap() {a=[10.5]}

updated

enter image description here

Got the same error again the error occurred only with 2 properties keys

  1. abc
  2. Mailing_Code
Jason Plurad
  • 6,682
  • 2
  • 18
  • 37
Akshay
  • 359
  • 1
  • 3
  • 14
  • Did you create a schema before you executed those traversals? It looks like the `abc` property is already defined as an `Integer`. Also did you change the value of `schema.default` in your configuration? – Florian Hockmann May 12 '18 at 10:21
  • I recreated the server and tested the same code with key `abc` and its working the same problem occurred with `Mailing_Code` now this also fixed but I didn't change anything and not set any property I just followed the documentation **http://docs.janusgraph.org/0.1.0/getting-started.html** – Akshay May 14 '18 at 04:24
  • how do I create the schema – Akshay May 14 '18 at 04:24
  • I have tested same keys with different property value but didn't get any error the problem has happened only with this keys. – Akshay May 14 '18 at 05:49

1 Answers1

3

By default, JanusGraph uses an automatic schema maker. When a new property key is used, it will define a property key with its data type based on the value. In your scenario, it sounds like the first usage of abc used Integer rather than Float. Here's an example recreating your scenario:

gremlin> JanusGraph.version()
==>0.2.0
gremlin> graph = JanusGraphFactory.open('inmemory')
==>standardjanusgraph[inmemory:[127.0.0.1]]
gremlin> g = graph.traversal()
==>graphtraversalsource[standardjanusgraph[inmemory:[127.0.0.1]], standard]
gremlin> g.addV("T22").property("abc", 9).iterate()
gremlin> g.tx().commit()
==>null
gremlin> g.addV("T22").property("abc", 9.5f).iterate()
Value [9.5] is not an instance of the expected data type for property key [abc] and cannot be converted. Expected: class java.lang.Integer, found: class java.lang.Float

After a property key is defined, its data type cannot be changed. As described in the docs:

It is strongly encouraged to explicitly define all schema elements and to disable automatic schema creation by setting schema.default=none in the JanusGraph graph configuration.

Doing so will give you better control over the schema that is created. Here's an example on how to do that:

gremlin> graph = JanusGraphFactory.build().
......1>     set('storage.backend', 'inmemory').
......2>     set('schema.default', 'none').
......3>     open()
==>standardjanusgraph[inmemory:[127.0.0.1]]
gremlin> mgmt = graph.openManagement()
==>org.janusgraph.graphdb.database.management.ManagementSystem@46aa712c
gremlin> mgmt.makeVertexLabel('T22').make()
==>T22
gremlin> mgmt.makePropertyKey('abc').dataType(Float.class).make()
==>abc
gremlin> mgmt.commit()
==>null
gremlin> g = graph.traversal()
==>graphtraversalsource[standardjanusgraph[inmemory:[127.0.0.1]], standard]
gremlin> g.addV('T22').property('abc', 9).iterate()
gremlin> g.tx().commit()
==>null
gremlin> g.addV('T22').property('abc', 9.5f).iterate()
gremlin> g.tx().commit()
==>null
gremlin> g.V().values('abc').map{ [ it.get(), it.get().getClass().getName() ] }
11:29:34 WARN  org.janusgraph.graphdb.transaction.StandardJanusGraphTx  - Query requires iterating over all vertices [()]. For better performance, use indexes
==>[9.5,java.lang.Float]
==>[9.0,java.lang.Float]

Here is a link to the documentation on JanusGraph schema which has more information.

Jason Plurad
  • 6,682
  • 2
  • 18
  • 37