Search in sources :

Example 1 with ResultSet

use of redis.clients.jedis.graph.ResultSet in project jedis by xetorthio.

the class GraphAPITest method testHeader.

@Test
public void testHeader() {
    assertNotNull(client.graphQuery("social", "CREATE (:person{name:'roi',age:32})"));
    assertNotNull(client.graphQuery("social", "CREATE (:person{name:'amit',age:30})"));
    assertNotNull(client.graphQuery("social", "MATCH (a:person), (b:person) WHERE (a.name = 'roi' AND b.name='amit')  CREATE (a)-[:knows]->(a)"));
    ResultSet queryResult = client.graphQuery("social", "MATCH (a:person)-[r:knows]->(b:person) RETURN a,r, a.age");
    Header header = queryResult.getHeader();
    assertNotNull(header);
    assertEquals("HeaderImpl{" + // + "schemaTypes=[COLUMN_SCALAR, COLUMN_SCALAR, COLUMN_SCALAR], "
    "schemaTypes=[SCALAR, SCALAR, SCALAR], " + "schemaNames=[a, r, a.age]}", header.toString());
    // Assert.assertEquals(-1901778507, header.hashCode());
    List<String> schemaNames = header.getSchemaNames();
    assertNotNull(schemaNames);
    assertEquals(3, schemaNames.size());
    assertEquals("a", schemaNames.get(0));
    assertEquals("r", schemaNames.get(1));
    assertEquals("a.age", schemaNames.get(2));
}
Also used : Header(redis.clients.jedis.graph.Header) ResultSet(redis.clients.jedis.graph.ResultSet) Test(org.junit.Test)

Example 2 with ResultSet

use of redis.clients.jedis.graph.ResultSet in project jedis by xetorthio.

the class GraphAPITest method testParameters.

@Test
public void testParameters() {
    Object[] parameters = { 1, 2.3, true, false, null, "str", 'a', "b", Arrays.asList(1, 2, 3), new Integer[] { 1, 2, 3 } };
    Object[] expected_anwsers = { 1L, 2.3, true, false, null, "str", "a", "b", Arrays.asList(1L, 2L, 3L), new Long[] { 1L, 2L, 3L } };
    Map<String, Object> params = new HashMap<>();
    for (int i = 0; i < parameters.length; i++) {
        Object param = parameters[i];
        params.put("param", param);
        ResultSet resultSet = client.graphQuery("social", "RETURN $param", params);
        assertEquals(1, resultSet.size());
        Record r = resultSet.iterator().next();
        Object o = r.getValue(0);
        Object expected = expected_anwsers[i];
        if (i == parameters.length - 1) {
            expected = Arrays.asList((Object[]) expected);
        }
        assertEquals(expected, o);
    }
}
Also used : ResultSet(redis.clients.jedis.graph.ResultSet) Record(redis.clients.jedis.graph.Record) Test(org.junit.Test)

Example 3 with ResultSet

use of redis.clients.jedis.graph.ResultSet in project jedis by xetorthio.

the class GraphAPITest method testSimpleReadOnly.

@Test
public void testSimpleReadOnly() {
    client.graphQuery("social", "CREATE (:person{name:'filipe',age:30})");
    ResultSet rsRo = client.graphReadonlyQuery("social", "MATCH (a:person) WHERE (a.name = 'filipe') RETURN a.age");
    assertEquals(1, rsRo.size());
    Record r = rsRo.iterator().next();
    assertEquals(Long.valueOf(30), r.getValue(0));
}
Also used : ResultSet(redis.clients.jedis.graph.ResultSet) Record(redis.clients.jedis.graph.Record) Test(org.junit.Test)

Example 4 with ResultSet

use of redis.clients.jedis.graph.ResultSet in project jedis by xetorthio.

the class GraphAPITest method testAdditionToProcedures.

@Test
public void testAdditionToProcedures() {
    assertNotNull(client.graphQuery("social", "CREATE (:person{name:'roi',age:32})"));
    assertNotNull(client.graphQuery("social", "CREATE (:person{name:'amit',age:30})"));
    assertNotNull(client.graphQuery("social", "MATCH (a:person), (b:person) WHERE (a.name = 'roi' AND b.name='amit')  CREATE (a)-[:knows]->(b)"));
    // expected objects init
    Property<String> nameProperty = new Property<>("name", "roi");
    Property<Integer> ageProperty = new Property<>("age", 32);
    Property<String> lastNameProperty = new Property<>("lastName", "a");
    Node expectedNode = new Node();
    expectedNode.setId(0);
    expectedNode.addLabel("person");
    expectedNode.addProperty(nameProperty);
    expectedNode.addProperty(ageProperty);
    Edge expectedEdge = new Edge();
    expectedEdge.setId(0);
    expectedEdge.setSource(0);
    expectedEdge.setDestination(1);
    expectedEdge.setRelationshipType("knows");
    ResultSet resultSet = client.graphQuery("social", "MATCH (a:person)-[r:knows]->(b:person) RETURN a,r");
    assertNotNull(resultSet.getHeader());
    Header header = resultSet.getHeader();
    List<String> schemaNames = header.getSchemaNames();
    assertNotNull(schemaNames);
    assertEquals(2, schemaNames.size());
    assertEquals("a", schemaNames.get(0));
    assertEquals("r", schemaNames.get(1));
    assertEquals(1, resultSet.size());
    Iterator<Record> iterator = resultSet.iterator();
    assertTrue(iterator.hasNext());
    Record record = iterator.next();
    assertFalse(iterator.hasNext());
    assertEquals(Arrays.asList("a", "r"), record.keys());
    assertEquals(Arrays.asList(expectedNode, expectedEdge), record.values());
    // test for local cache updates
    expectedNode.removeProperty("name");
    expectedNode.removeProperty("age");
    expectedNode.addProperty(lastNameProperty);
    expectedNode.removeLabel("person");
    expectedNode.addLabel("worker");
    expectedNode.setId(2);
    expectedEdge.setRelationshipType("worksWith");
    expectedEdge.setSource(2);
    expectedEdge.setDestination(3);
    expectedEdge.setId(1);
    assertNotNull(client.graphQuery("social", "CREATE (:worker{lastName:'a'})"));
    assertNotNull(client.graphQuery("social", "CREATE (:worker{lastName:'b'})"));
    assertNotNull(client.graphQuery("social", "MATCH (a:worker), (b:worker) WHERE (a.lastName = 'a' AND b.lastName='b')  CREATE (a)-[:worksWith]->(b)"));
    resultSet = client.graphQuery("social", "MATCH (a:worker)-[r:worksWith]->(b:worker) RETURN a,r");
    assertNotNull(resultSet.getHeader());
    header = resultSet.getHeader();
    schemaNames = header.getSchemaNames();
    assertNotNull(schemaNames);
    assertEquals(2, schemaNames.size());
    assertEquals("a", schemaNames.get(0));
    assertEquals("r", schemaNames.get(1));
    assertEquals(1, resultSet.size());
    iterator = resultSet.iterator();
    assertTrue(iterator.hasNext());
    record = iterator.next();
    assertFalse(iterator.hasNext());
    assertEquals(Arrays.asList("a", "r"), record.keys());
    assertEquals(Arrays.asList(expectedNode, expectedEdge), record.values());
}
Also used : Header(redis.clients.jedis.graph.Header) ResultSet(redis.clients.jedis.graph.ResultSet) Record(redis.clients.jedis.graph.Record) Test(org.junit.Test)

Example 5 with ResultSet

use of redis.clients.jedis.graph.ResultSet in project jedis by xetorthio.

the class GraphAPITest method testNullGraphEntities.

@Test
public void testNullGraphEntities() {
    // Create two nodes connected by a single outgoing edge.
    assertNotNull(client.graphQuery("social", "CREATE (:L)-[:E]->(:L2)"));
    // Test a query that produces 1 record with 3 null values.
    ResultSet resultSet = client.graphQuery("social", "OPTIONAL MATCH (a:NONEXISTENT)-[e]->(b) RETURN a, e, b");
    assertEquals(1, resultSet.size());
    Iterator<Record> iterator = resultSet.iterator();
    assertTrue(iterator.hasNext());
    Record record = iterator.next();
    assertFalse(iterator.hasNext());
    assertEquals(Arrays.asList(null, null, null), record.values());
    // Test a query that produces 2 records, with 2 null values in the second.
    resultSet = client.graphQuery("social", "MATCH (a) OPTIONAL MATCH (a)-[e]->(b) RETURN a, e, b ORDER BY ID(a)");
    assertEquals(2, resultSet.size());
    iterator = resultSet.iterator();
    record = iterator.next();
    assertEquals(3, record.size());
    assertNotNull(record.getValue(0));
    assertNotNull(record.getValue(1));
    assertNotNull(record.getValue(2));
    record = iterator.next();
    assertEquals(3, record.size());
    assertNotNull(record.getValue(0));
    assertNull(record.getValue(1));
    assertNull(record.getValue(2));
    // Test a query that produces 2 records, the first containing a path and the
    // second containing a null value.
    resultSet = client.graphQuery("social", "MATCH (a) OPTIONAL MATCH p = (a)-[e]->(b) RETURN p");
    assertEquals(2, resultSet.size());
    iterator = resultSet.iterator();
    record = iterator.next();
    assertEquals(1, record.size());
    assertNotNull(record.getValue(0));
    record = iterator.next();
    assertEquals(1, record.size());
    assertNull(record.getValue(0));
}
Also used : ResultSet(redis.clients.jedis.graph.ResultSet) Record(redis.clients.jedis.graph.Record) Test(org.junit.Test)

Aggregations

ResultSet (redis.clients.jedis.graph.ResultSet)45 Test (org.junit.Test)43 Record (redis.clients.jedis.graph.Record)37 Header (redis.clients.jedis.graph.Header)14 Node (redis.clients.jedis.graph.entities.Node)8 Property (redis.clients.jedis.graph.entities.Property)8 Pipeline (redis.clients.jedis.Pipeline)4 Transaction (redis.clients.jedis.Transaction)4