How to make schema less titan graph?How to set schema-default propery ? Please suggest a way?Here is my code :
try{
//timestamp,1416375283,ipaddress,2097152002,mobilenumber,966566564213,eventname,1000
// TODO Auto-generated method stub
FileInputStream fstream = new FileInputStream("/root/edges_sorted.txt");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String csv = "/root/log.CSV";
FileWriter writer = new FileWriter(csv);
Configuration conf = new BaseConfiguration();
conf.setProperty("storage.backend","hbase");
conf.setProperty("storage.hostname","192.168.51.98");
conf.setProperty("storage.batch-loading","true");
conf.setProperty("storage.batch-loading",true);
conf.setProperty("storage.buffer-size",3024000);
conf.setProperty("storage.tablename",graphName);
conf.setProperty("ids.block-size", 1000000);
conf.setProperty("ids.flush ", true);
//set the db cache
conf.setProperty("cache.db-cache",true);
//set the cache size
conf.setProperty("cache.db-cache-size",0.5);
conf.setProperty("storage.hbase.region-count",3);
conf.setProperty("storage.hbase.skip-schema-check", false);
conf.setProperty("storage.index.titan5.backend","elasticsearch");
conf.setProperty("storage.index.titan5.hostname", "192.168.51.95");
conf.setProperty("storage.index.titan5.client-only", false);
conf.setProperty("storage.index.titan5.cluster-name","titancluster");
conf.setProperty("storage.index.titan5.index-name", indexName);
conf.setProperty("graph.set-vertex-id",true);
conf.setProperty("attributes.allow-all",true);
conf.setProperty("schema.default",false);
TitanGraph titanGraph = TitanFactory.open(conf);
titanGraph.makeLabel("reason").manyToMany().make();
titanGraph.makeLabel("many").manyToMany().make();
BatchGraph<TitanGraph> titanBatchGraph=new BatchGraph<TitanGraph>(titanGraph,VertexIDType.NUMBER,batchsize);
titanBatchGraph.setLoadingFromScratch(true);
String locations[]=CreateDummy1.getCircleList();
String strLine1="";
int circleindex=0;
int count=0;
Vertex vertex;
Vertex vertex2;
count ++;
if(circleindex==locations.length)
circleindex=0;
vertex=titanBatchGraph.getVertex(1);
if(vertex==null){
vertex = titanBatchGraph.addVertex(1);
vertex.setProperty("n",1);
vertex.setProperty("a",100);
}
vertex2=titanBatchGraph.getVertex(2);
if(vertex2==null){
count++;
vertex2 = titanBatchGraph.addVertex(2);
vertex2.setProperty("n",2);
vertex2.setProperty("a", 10000);
}
Edge edge= titanBatchGraph.addEdge(1,vertex,vertex2,"reason");
edge.setProperty("ti",1);
edge.setProperty("s", 5);
//second edge
vertex=titanBatchGraph.getVertex(1);
if(vertex==null){
vertex = titanBatchGraph.addVertex(1);
vertex.setProperty("n",1);
vertex.setProperty("a",100);
}
else
{
vertex.setProperty("n1", 45);
}
vertex2=titanBatchGraph.getVertex(2);
if(vertex2==null){
count++;
vertex2 = titanBatchGraph.addVertex(2);
vertex2.setProperty("n",2);
vertex2.setProperty("a", 10000);
}
Edge edge1= titanBatchGraph.addEdge(2,vertex,vertex2,"reason");
edge1.setProperty("ti",2);
edge1.setProperty("s",6);
titanBatchGraph.commit();
titanBatchGraph.shutdown();
}
catch(Exception e)
{
e.printStackTrace();
}
}
How to set scheme-default configuration? how to set it to default so that automatic schemas are generated?Please suggest a way or any alternative ?
Titan is set in that configuration by default. To elaborate, this settings schema.default
is set to blueprints
automatically. To force schema definition, you need to set that value to none
. The docs read:
Configures the DefaultSchemaMaker to be used by this graph. If set to none, automatic schema creation is disabled. Defaults to a blueprints compatible schema maker with MULTI edge labels and SINGLE property keys
To enforce a schema you need to do this:
conf.setProperty("schema.default","none");
and to use the "default" schema creation system you should do:
conf.setProperty("schema.default","blueprints");
All that said, it is generally a bad idea to allow Titan to create the schema for anything except very simple cases. If you don't provide Titan a schema, you will lose many optimizations and features that Titan provides and therefore you performance may not be as good as it possible could be.