1

Using RedishGraph from Redis Labs in Java project. Getting below error when I pass Map Properties as input to Cypher query.

 ObjectMapper oMapper = new ObjectMapper();
 Person person=new Person(2, "Jagadeesh", 23);
 Map<String, Object> personMap = oMapper.convertValue(person, Map.class);

 Map<String, Object> props=new HashMap<>();
 props.put("props", personMap);

 ResultSet rs1 = graph.query("UserGraph", "CREATE ($props)", props);

There was an unexpected error (type=Internal Server Error, status=500). redis.clients.jedis.exceptions.JedisDataException: errMsg: Invalid input 'p': expected PROFILE line: 1, column: 4, offset: 3 errCtx: props={id=2, name=Jagadeesh, age=23} CREATE ($props) errCtxOffset: 3

1 Answers1

2

Disclaimer: I'm one of the RedisGraph engineers.

First, for the time being, we do not support maps as a native datatype in RedisGraph so, unfortunately, your query is currently not supported.

Second, Can you please share which version of RedisGraph are you using? I executed the following code over our latest docker image (docker run -p 6379:6379 --rm redislabs/redisgraph:latest)

    @Test
    public void testStackOverflowQuestion(){
        RedisGraph graph = new RedisGraph();
        Map<String, Object> props = new HashMap<>();
        props.put("id", 2);
        props.put("name", "Jagadeesh");
        props.put("age", 23);
        graph.query("UserGraph", "CREATE ($props)", props);
    }

and the response seems to be more appropriate for unsuppoted data types:

com.redislabs.redisgraph.exceptions.JRedisGraphCompileTimeException: redis.clients.jedis.exceptions.JedisDataException: Encountered unhandled type in inlined properties.

Edit after comment:

I modify the test to be

    @Test
    public void testStackOverflowQuestion(){
        RedisGraph graph = new RedisGraph();
        Map<String, Object> personMap = new HashMap<>();
        personMap.put("id", 2);
        personMap.put("name", "Jagadeesh");
        personMap.put("age", 23);
        Map<String, Object> props = new HashMap<>();
        props.put("props", personMap);
        graph.query("UserGraph", "CREATE ($props)", props);
    }

I got the same response as you as you. This is our parser error. Our parser expects map key-value pair to be seperated by colon key:value The error caused by wrong format of serialization of the map object in JRedisGraph which currently calls the map toString() method which serializes it as key = value so our parser skips the parameter parsing and treats the map as part of the actual query.

By applying MONITOR in redis-cli, your query yields the command: "graph.QUERY" "UserGraph" "CYPHER props={name=Jagadeesh, id=2, age=23} CREATE ($props)" "--COMPACT" As you can see, the map is sent in key=value format. I manually changed the query and sent it in redis-cli with key:value format and got the expected response:

127.0.0.1:6379> graph.query g "CYPHER props={name:Jagadeesh, id:2, age:23} CREATE ($props)"
(error) Encountered unhandled type in inlined properties.
  • Thanks Dvir, I am using Redis version=6.0.3. Your code is using direct HashMap object. But my code using HashMap created as property inside another HashMap. This might be the reason for different exception. – Jagadeesh Urlana Jun 10 '20 at 10:47
  • Thank you so much for the update Dvir. That parsing should be taken care at RedisGraph plugin level right. What we can do from our side. I have followed below link to create nodes with properties. Please let us know your inputs. https://neo4j.com/docs/java-reference/current/java-embedded/query-parameters/ – Jagadeesh Urlana Jun 12 '20 at 04:56