Skip to content

Instantly share code, notes, and snippets.

@zachkinstner
Last active December 17, 2015 15:19
Show Gist options
  • Save zachkinstner/5630877 to your computer and use it in GitHub Desktop.
Save zachkinstner/5630877 to your computer and use it in GitHub Desktop.
Testing a Titan code change that would allow vertex-centric indexing on IN-unique and OUT-unique edges.

Related discussion about the "Cannot define a primary key on a unique type" exception: https://groups.google.com/forum/#!topic/aureliusgraphs/KFVtfC9Xy94

First step: change this StandardTypeMaker line to use the And operator between isUnique:

if ((isUnique[0] && isUnique[1]) && !primaryKey.isEmpty()) throw new IllegalArgumentException("Cannot define a primary key on a unique type")

This allows an IN-unique or OUT-unique edge to use Titan's vertex-centric indexing. Note the unique(OUT) in the example below:

g.makeType().name("uses").unique(OUT).primaryKey(factorType).makeEdgeLabel();

Test scenarios for both Berkeley and Cassandra are below.

Local Berkeley

One local Berkeley database.

The net result:

{"timer":10,"results":[20]} //vertex-centric indexing
{"timer":1619,"results":[20]} //linear scan of edge properties

RexConnectConsole setup:

$ bin/rexConnectConsole.sh

"            ---===##\    
"                --==##\  
"  ---===################>
"                --==##/  
"            ---===##/    

RexConnect Console 0.3.1
{rexpro_port=8184, rexpro_graph_name=graph, rexconnect_port=8185, rexpro_hosts=rexster, rexpro_timeout_ms=120000}

-------------------------------------------------------------

# RexConnect> query
#   ...script (0; string): g
#   ...params (1; string; opt): 

{"timer":5,"results":["titangraph[local:data/FabricIndex]"]}

# RexConnect> query
#   ...script (0; string): factorType = g.makeType().name("FactorType").dataType(Integer.class).unique(OUT).indexed(Vertex.class).makePropertyKey(); g.makeType().name("uses").unique(OUT).primaryKey(factorType).makeEdgeLabel();
#   ...params (1; string; opt): 

{"timer":695,"results":[{"_id":"36028797018963990","_type":"vertex"}]}

# RexConnect> query
#   ...script (0; string): a = g.addVertex([ArtifactId:1]); (1..100000).each { ft = (it%5000); f = g.addVertex([FactorId:it, FactorType:ft]); g.addEdge(f, a, "uses", [FactorType:ft, NotIndexed:ft]); }; a;
#   ...params (1; string; opt): 

{"timer":29321,"results":[{"_properties":{"ArtifactId":1},"_id":"4","_type":"vertex"}]}

# RexConnect> query
#   ...script (0; string): g.v(4).inE('uses').count();
#   ...params (1; string; opt): 

{"timer":3617,"results":[100000]}

# RexConnect> query
#   ...script (0; string): g.v(4).inE('uses').count();
#   ...params (1; string; opt): 

{"timer":1272,"results":[100000]}

# RexConnect> query
#   ...script (0; string): g.v(4).inE('uses').has('FactorType', Tokens.T.eq, 8).inV.count();
#   ...params (1; string; opt): 

{"timer":45,"results":[20]}

# RexConnect> query
#   ...script (0; string): g.v(4).inE('uses').has('FactorType', Tokens.T.eq, 8).inV.count();
#   ...params (1; string; opt): 

{"timer":10,"results":[20]}

# RexConnect> query
#   ...script (0; string): g.v(4).inE('uses').has('NotIndexed', Tokens.T.eq, 8).inV.count();
#   ...params (1; string; opt): 

{"timer":2390,"results":[20]}

# RexConnect> query
#   ...script (0; string): g.v(4).inE('uses').has('NotIndexed', Tokens.T.eq, 8).inV.count();
#   ...params (1; string; opt): 

{"timer":1619,"results":[20]}

Cassandra Cluster

EmbeddedCassandra on a three-node cluster.

Net result:

{"timer":124,"results":[20]} //vertex-centric indexing
{"timer":2242,"results":[20]} //linear scan of edge properties

RexConnectConsole setup:

# bin/rexConnectConsole.sh

"            ---===##\
"                --==##\
"  ---===################>
"                --==##/
"            ---===##/

RexConnect Console 0.3.1
{rexpro_port=8184, rexpro_graph_name=graph, rexconnect_port=8185, rexpro_hosts=127.0.0.1, rexpro_timeout_ms=120000}

-------------------------------------------------------------

# RexConnect> query
#   ...script (0; string): g
#   ...params (1; string; opt):

{"timer":16,"results":["titangraph[embeddedcassandra:null]"]}

# RexConnect> query
#   ...script (0; string): factorType = g.makeType().name("FactorType").dataType(Integer.class).unique(OUT).indexed(Vertex.class).makePropertyKey(); g.makeType().name("uses").unique(OUT).primaryKey(factorType).makeEdgeLabel();
#   ...params (1; string; opt):

{"timer":2217,"results":[{"_id":"36028797018964182","_type":"vertex"}]}

# RexConnect> query
#   ...script (0; string): a = g.addVertex([ArtifactId:1]); (1..100000).each { ft = (it%5000); f = g.addVertex([FactorId:it, FactorType:ft]); g.addEdge(f, a, "uses", [FactorType:ft, NotIndexed:ft]); }; a;
#   ...params (1; string; opt):

{"timer":120002,"err":"java.io.IOException> Message received response timeoutConnection (8000 s)"}

//waited for a while...

# RexConnect> query
#   ...script (0; string): g.v(4)
#   ...params (1; string; opt):

{"timer":112,"results":[{"_properties":{"ArtifactId":1},"_id":"4","_type":"vertex"}]}

# RexConnect> query
#   ...script (0; string): g.v(4).inE('uses').has('FactorType', Tokens.T.eq, 8).inV.count();
#   ...params (1; string; opt):

{"timer":179,"results":[20]}

# RexConnect> query
#   ...script (0; string): g.v(4).inE('uses').has('FactorType', Tokens.T.eq, 8).inV.count();
#   ...params (1; string; opt):

{"timer":124,"results":[20]}

# RexConnect> query
#   ...script (0; string): g.v(4).inE('uses').has('NotIndexed', Tokens.T.eq, 8).inV.count();
#   ...params (1; string; opt):

{"timer":5074,"results":[20]}

# RexConnect> query
#   ...script (0; string): g.v(4).inE('uses').has('NotIndexed', Tokens.T.eq, 8).inV.count();
#   ...params (1; string; opt):

{"timer":2242,"results":[20]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment