2

Present i am using janusgraph-0.2.0-hadoop2 server and using gremlin@2.6.0 library for querying

const Gremlin = require("gremlin");
const client = Gremlin.createClient(8182, "192.168.0.103");

function test(p){
   client.execute(q, {}, (err, results) => {
    if (err) {
      console.error(err);
      client.closeConnection();
    }
    else {
    console.log(results);
    client.closeConnection();
   }
});
}

for query g.V().count() result is [ 12 ]

for query g.V().has('name', 'saturn').valueMap() result is [ { name: [ 'saturn' ], age: [ 10000 ] } ]

I am ok with that

But after update my janusgraph to janusgraph-0.5.0-hadoop2 server and using same library gremlin@2.6.0

Getting data in different

for query g.V().count() result is [ { '@type': 'g:Int64', '@value': 12 } ]

for query g.V().has('name', 'saturn').valueMap() result is

[ { '@type': 'g:Map', '@value': [ 'name', [Object], 'age', [Object] ] } ] Updating library to gremlin@3.4.6

const gremlin = require('gremlin');
const client = new gremlin.driver.Client('ws://192.168.0.106:8182/gremlin', { traversalSource: 'g' });

async function test(q){
  const res = await client.submit(q, {});
  console.log('res',res)
  client.close();
}

test()

for query g.V().count() result is [ 12 ]

for query g.V().has('name', 'saturn').valueMap() result is [ Map { 'name' => [ 'saturn' ], 'age' => [ 10000 ] } ]

Getting data in Hashmap I want to know

 1. Is it necessary to update gremlin library 3.4.6 getting correct result.
 2. After updating to 3.4.6 get data in hashmap format, Means i want to know i am getting correct data or not.
 3. I want data in object format but got in hashmap. I know i can convert to object but incase data is in nested hashmap, I dont want to repeat and convert it.

Please give me suggestions

1 Answers1

4

I would say it is a very good idea to be on the current version of Janus Graph. Note that you should use the Gremlin libraries that come with Janus graph and not update those independently. The most recent Javascript/Node Gremlin clients do return Map types as you are seeing.

rod-emerson
  • 113
  • 1
  • 4
  • 2
    this is good advice. note that javascript gremin at 2.6.0 is really old and isn't even publishing artifacts from the Apache project. You don't get that until 3.2.8/3.3.2 when the npm "gremlin" was given to the Apache project. Upgrading from 2.6.0 is likely a massive change as many API operations and configuration options have shifted since then. – stephen mallette Apr 04 '20 at 11:12
  • 3
    The most immediate one you notice in the move from your version is that the old version at 2.6.0 is likely bound to GraphSON 1 but the default in newer versions is likely 3 (or perhaps 2) as a default. You could probably switch back to 1 to get the same formatting but that will mean serialization configuration changes to driver (and maybe server). It would be far better to read the latest documentation on gremlin-javascript and utilize the latest features and capabilities. The mechanisms for developing Gremlin have improved dramatically since sending string scripts of Gremlin through `Client`. – stephen mallette Apr 04 '20 at 11:15
  • 3
    You can find the latest information in our reference documentation - https://tinkerpop.apache.org/docs/current/reference/#gremlin-javascript – stephen mallette Apr 04 '20 at 11:15
  • Thank you rod-emerson and @stephen mallette fo your infomration. I understand better to move recent versions and i got correct result in map format. If result is in nested map it is difficult to convert to object and use it. Ex `[Map { Map { Map{}}}`. – sai ramam chavatapalli Apr 04 '20 at 13:26
  • 2
    I got code to itconvert it to object. `const mapToObj = (inputMap) => { let obj = {}; inputMap.forEach(function(value, key){ obj[key] = value }); return obj; }` **Repeating map object and convert it to object every time and every result through nested map it is diffcult do that. Is there any better way or do same thing ** – sai ramam chavatapalli Apr 04 '20 at 13:30
  • 1
    I'm not sure what circumstances are producing embedded maps for you. Are you just referring to what's returned from `valueMap()`. If the version you are using supports it, perhaps use `elementMap()` (or `project()` otherwise). With Gremlin you can get your data back in whatever form you want essentially - you just transform your result as necessary with the appropriate Gremlin steps. – stephen mallette Apr 04 '20 at 13:59