-
Notifications
You must be signed in to change notification settings - Fork 22
New resultset structure #35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
2130924
created redisconf branch
9bb8781
changed gitignore
cc9faee
changed gitignore
6cbdcc5
Added graph entities and graph entity property classes
b437f9a
Added Header interface and class implementation
3fc3655
Added equals, hashCode, toString for RecordImpl
3e828d7
Added documentation, equals, hashCode, toString for StatisticsImpl
630c5d8
Modified ResultSet interface to return a Header object instead of
31997c0
Modified ResultSet implementation to handle new compact query answer,
b1865bf
Added documentation, send compact command method, static instance to
1fa2318
tests
615db35
moved to version 2.0.0-SNAPSHOT at pom.xml
6330e6b
fixed according to pull request comments
40be547
changed circle-ci to work with 2.0-edge docker image
e1e9bfd
result set impl is now holding a local ref to redis graph api
06059bf
Modified implementation to work in multi threaded mode
36cf626
added connection closing and added multi threaded test
4cc3a88
changed pull request comments
d87acb7
changed pull request comments
fcc9a5e
Update GraphCacheList.java
gkorland 584dcad
fixed a bug
3daea75
Merge branch 'new-resultset-structure' of https://github.com/RedisGra…
e6ceab1
bug fix tests
3bf901f
testing redisconf branch
ca8d001
removed Jedis try resource block - move to try catch
659f7c4
changed try resource block
3ea0b34
changed try resource block (again)
f3ee260
removed release flag from circleci config.yaml
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,3 +29,6 @@ hs_err_pid* | |
| .classpath | ||
| .project | ||
| /.settings/ | ||
|
|
||
| #intelij | ||
| .idea | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) { | ||
gkorland marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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
108
src/main/java/com/redislabs/redisgraph/RedisGraphAPI.java
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.