Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
2130924
created redisconf branch
May 1, 2019
9bb8781
changed gitignore
May 1, 2019
cc9faee
changed gitignore
May 1, 2019
6cbdcc5
Added graph entities and graph entity property classes
May 6, 2019
b437f9a
Added Header interface and class implementation
May 6, 2019
3fc3655
Added equals, hashCode, toString for RecordImpl
May 6, 2019
3e828d7
Added documentation, equals, hashCode, toString for StatisticsImpl
May 6, 2019
630c5d8
Modified ResultSet interface to return a Header object instead of
May 6, 2019
31997c0
Modified ResultSet implementation to handle new compact query answer,
May 6, 2019
b1865bf
Added documentation, send compact command method, static instance to
May 6, 2019
1fa2318
tests
May 6, 2019
615db35
moved to version 2.0.0-SNAPSHOT at pom.xml
May 6, 2019
6330e6b
fixed according to pull request comments
May 8, 2019
40be547
changed circle-ci to work with 2.0-edge docker image
May 12, 2019
e1e9bfd
result set impl is now holding a local ref to redis graph api
May 12, 2019
06059bf
Modified implementation to work in multi threaded mode
May 14, 2019
36cf626
added connection closing and added multi threaded test
May 15, 2019
4cc3a88
changed pull request comments
May 16, 2019
d87acb7
changed pull request comments
May 16, 2019
fcc9a5e
Update GraphCacheList.java
gkorland May 16, 2019
584dcad
fixed a bug
May 16, 2019
3daea75
Merge branch 'new-resultset-structure' of https://github.com/RedisGra…
May 16, 2019
e6ceab1
bug fix tests
May 19, 2019
3bf901f
testing redisconf branch
May 23, 2019
ca8d001
removed Jedis try resource block - move to try catch
May 26, 2019
659f7c4
changed try resource block
May 28, 2019
3ea0b34
changed try resource block (again)
May 28, 2019
f3ee260
removed release flag from circleci config.yaml
May 28, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
docker:
- image: circleci/openjdk:8u171-jdk

- image: redislabs/redisgraph:edge
- image: redislabs/redisgraph:2.0-edge
port: 6379:6379

working_directory: ~/repo
Expand Down Expand Up @@ -44,7 +44,7 @@ jobs:

- run: bash <(curl -s https://codecov.io/bash) -t ${CODECOV_TOKEN}

- run: mvn -s .circleci.settings.xml -DskipTests deploy
- run: mvn -s .circleci.settings.xml -DskipTests deploy

workflows:
version: 2
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,6 @@ hs_err_pid*
.classpath
.project
/.settings/

#intelij
.idea
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.redislabs</groupId>
<artifactId>jredisgraph</artifactId>
<version>1.0.7-SNAPSHOT</version>
<version>2.0.0-SNAPSHOT</version>

<name>JRedisGraph</name>
<description>Official client for Redis-Graph</description>
Expand Down
23 changes: 23 additions & 0 deletions src/main/java/com/redislabs/redisgraph/Header.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.redislabs.redisgraph;

import java.util.List;

/**
* Query response header interface. Represents the response schame (column names and types)
*/
public interface Header {


public enum ResultSetColumnTypes {
COLUMN_UNKNOWN,
COLUMN_SCALAR,
COLUMN_NODE,
COLUMN_RELATION;

}


List<String> getSchemaNames();

List<ResultSetColumnTypes> getSchemaTypes();
}
190 changes: 190 additions & 0 deletions src/main/java/com/redislabs/redisgraph/RedisGraph.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
package com.redislabs.redisgraph;

import com.redislabs.redisgraph.impl.GraphCache;
import com.redislabs.redisgraph.impl.ResultSetImpl;
import org.apache.commons.text.translate.AggregateTranslator;
import org.apache.commons.text.translate.CharSequenceTranslator;
import org.apache.commons.text.translate.LookupTranslator;
import redis.clients.jedis.BinaryClient;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.commands.ProtocolCommand;
import redis.clients.jedis.util.Pool;

import java.io.Closeable;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;


/**
*
*/
public class RedisGraph implements Closeable {



private final Pool<Jedis> client;
private final Map<String, GraphCache> graphCaches = new ConcurrentHashMap<>();



private static final CharSequenceTranslator ESCAPE_CHYPER;
static {
final Map<CharSequence, CharSequence> escapeJavaMap = new HashMap<>();
escapeJavaMap.put("\'", "\\'");
escapeJavaMap.put("\"", "\\\"");
ESCAPE_CHYPER = new AggregateTranslator(new LookupTranslator(Collections.unmodifiableMap(escapeJavaMap)));
}

/**
* Creates a client running on the local machine

*/
public RedisGraph() {
this("localhost", 6379);
}

/**
* Creates a client running on the specific host/post
*
* @param host Redis host
* @param port Redis port
*/
public RedisGraph(String host, int port) {
this( new JedisPool(host, port));
}

/**
* Creates a client using provided Jedis pool
*
* @param jedis bring your own Jedis pool
*/
public RedisGraph( Pool<Jedis> jedis) {

this.client = jedis;
}

@Override
public void close(){
this.client.close();
}


/**
* Execute a Cypher query with arguments
*
* @param graphId a graph to perform the query on
* @param query Cypher query
* @param args
* @return a result set
*/
public ResultSet query(String graphId, String query, Object ...args) {
if(args.length > 0) {
for(int i=0; i<args.length; ++i) {
if(args[i] instanceof String) {
args[i] = "\'" + ESCAPE_CHYPER.translate((String)args[i]) + "\'";
}
}
query = String.format(query, args);
}
graphCaches.putIfAbsent(graphId, new GraphCache(graphId, this));
List<Object> rawResponse = null;
try(Jedis conn = getConnection()){
rawResponse= sendCompactCommand(conn, Command.QUERY, graphId, query).getObjectMultiBulkReply();
}
return new ResultSetImpl(rawResponse, graphCaches.get(graphId));

}

/**
* Invokes stored procedures without arguments
* @param graphId a graph to perform the query on
* @param procedure procedure name to invoke
* @return result set with the procedure data
*/
public ResultSet callProcedure(String graphId, String procedure ){
return callProcedure(graphId, procedure, new ArrayList<>(), new HashMap<>());
}


/**
* Invokes stored procedure with arguments
* @param graphId a graph to perform the query on
* @param procedure procedure name to invoke
* @param args procedure arguments
* @return result set with the procedure data
*/
public ResultSet callProcedure(String graphId, String procedure, List<String> args ){
return callProcedure(graphId, procedure, args, new HashMap<>());
}


/**
* Deletes the entire graph
*
* @return delete running time statistics
*/
public String deleteGraph(String graphId) {
//clear local state
graphCaches.remove(graphId);
try (Jedis conn = getConnection()) {
return sendCommand(conn, Command.DELETE, graphId).getBulkReply();
}

}


/**
* Sends command - will be replaced with sendCompactCommand once graph.delete support --compact flag
* @param conn - connection
* @param provider - command type
* @param args - command arguments
* @return
*/
private BinaryClient sendCommand(Jedis conn, ProtocolCommand provider, String ...args) {
BinaryClient binaryClient = conn.getClient();
binaryClient.sendCommand(provider, args);
return binaryClient;
}


/**
* Sends the command with --COMPACT flag
* @param conn - connection
* @param provider - command type
* @param args - command arguments
* @return
*/
private BinaryClient sendCompactCommand(Jedis conn, ProtocolCommand provider, String ...args) {
String[] t = new String[args.length +1];
System.arraycopy(args, 0 , t, 0, args.length);
t[args.length]="--COMPACT";
return sendCommand(conn, provider, t);
}

private Jedis getConnection() {
return this.client.getResource();
}


/**
* Invoke a stored procedure
* @param graphId a graph to perform the query on
* @param procedure - procedure to execute
* @param args - procedure arguments
* @param kwargs - procedure output arguments
* @return
*/
public ResultSet callProcedure(String graphId, String procedure, List<String> args , Map<String, List<String>> kwargs ){

args = args.stream().map( s -> Utils.quoteString(s)).collect(Collectors.toList());
StringBuilder queryString = new StringBuilder();
queryString.append(String.format("CALL %s(%s)", procedure, String.join(",", args)));
List<String> kwargsList = kwargs.getOrDefault("y", null);
if(kwargsList != null){
queryString.append(String.join(",", kwargsList));
}
return query(graphId, queryString.toString());
}
}
108 changes: 0 additions & 108 deletions src/main/java/com/redislabs/redisgraph/RedisGraphAPI.java

This file was deleted.

25 changes: 17 additions & 8 deletions src/main/java/com/redislabs/redisgraph/ResultSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,21 @@
/**
* Hold a query result
*/
public interface ResultSet extends Iterator<Record>{
/**
* Return the query statistics
* @return statistics object
*/
Statistics getStatistics();
public interface ResultSet extends Iterator<Record> {

List<String> getHeader();
}
public enum ResultSetScalarTypes {
PROPERTY_UNKNOWN,
PROPERTY_NULL,
PROPERTY_STRING,
PROPERTY_INTEGER,
PROPERTY_BOOLEAN,
PROPERTY_DOUBLE,
}

public int size();

Statistics getStatistics();

Header getHeader();

}
Loading