A.2 2表スキーマを使用したプロパティ・グラフへのデータの格納

2表スキーマを使用して頂点のセットを頂点表にロードするには、API OraclePropertyGraphUtils.writeTwoTablesGraphVertexAndPropertiesを使用できます。この操作は、TinkerPop Blueprints頂点オブジェクトのIterable(またはIterator)の配列を取り込み、頂点表スキーマで定義されたプロパティのIDと値を読み取ります。この情報に基づき、頂点が新しい行として頂点表に後で挿入されます。頂点にスキーマで定義されたプロパティが含まれていない場合、関連する列の値はNULLに設定されます。

次のコード・スニペットは、OraclePropertyGraph APIを使用して、プロパティ・グラフemployeesGraphDALを作成し、2つの頂点と1つのエッジをロードします。次に、2表スキーマを使用して、頂点表employeesNodesを作成し、それにemployeesGraphDALの頂点からのデータを移入します。頂点v1のプロパティemailは、スキーマで定義されていないため、employeesNode表にロードされないことに注意してください。また、頂点v2のプロパティSSNは、頂点で定義されていないため、NULLに設定されます。

// Create employeesGraphDAL
import oracle.pg.rdbms.*;
Oracle oracle = new Oracle(jdbcURL, username, password);
OraclePropertyGraph opgEmployees
                  = OraclePropertyGraph.getInstance(oracle, "employeesGraphDAL");

// Create vertex v1 and assign it properties as key-value pairs
Vertex v1 = opgEmployees.addVertex(1l);
v1.setProperty("age",  Integer.valueOf(31));
v1.setProperty("name", "Alice");
v1.setProperty("address", "Main Street 12");
v1.setProperty("email", "alice@mymail.com");
v1.setProperty("SSN", "123456789");

Vertex v2 = opgEmployees.addVertex(2l);
v2.setProperty("age",  Integer.valueOf(27));
v2.setProperty("name", "Bob");
v2.setProperty("adress", "Sesame Street 334"); 
       
// Add edge e1
Edge e1 = opgEmployees.addEdge(1l, v1, v2, "managerOf");
e1.setProperty("weight", 0.5d);

opgEmployees.commit();

// Prepare the vertex table using a Two Tables schema
import oracle.pgx.common.types.PropertyType;
List<String> propertyNames = new ArrayList<String>();
propertyNames.addAll(new String[4]{ "name", "age", "address", "SSN" });

List<PropertyType> = new ArrayList<PropertyType>();
propertyType.add(PropertyType.STRING);
propertyType.add(PropertyType.INTEGER);
propertyType.add(PropertyType.STRING);
propertyType.add(PropertyType.STRING);

Connection conn 
     = opgEmployees.getOracle().clone().getConnection(); /* Clone the connection
                                                            from the property graph 
                                                            instance */    
OraclePropertyGraphUtils.prepareTwoTablesGraphVertexTab(conn /* Connection object */,
                                            pg /* table owner */, 
                                            "employeesNodes" /* vertex table name */, 
                                            propertyNames /* property names */, 
                                            propertyTypes /* property data types */,
                                            "pgts" /* table space */, 
                                            null /* storage options */, 
                                            true /* no logging */);

// Get the vertices from the employeesDAL graph
Iterable<Vertex> vertices = opgEmployees.getVertices();

// Load the vertices into the vertex table using a Two-Tables schema
Connection[] conns = new Connection[1]; /* the connection array size defines the
                                           Degree of parallelism (multithreading)
                                        */
conns[1] = conn;
OraclePropertyGraphUtils.writeTwoTablesGraphVertexAndProperties(
                                           conn /* Connectionobject */,
                                            pg /* table owner */, 
                                            "employeesNodes" /* vertex table name */,  
                                            1000 /* batch size*/, 
                                            new Iterable[] {vertices} /* array of 
                                                                vertex iterables */); 

2表スキーマを使用してエッジのセットをエッジ表にロードするには、API OraclePropertyGraphUtils.writeTwoTablesGraphEdgesAndPropertiesを使用できます。この操作は、Blueprintsエッジ・オブジェクトのIterable(またはIterator)の配列を取り込み、エッジ表スキーマで定義されたプロパティのID、EL、SVID、DVIDと値を読み取ります。この情報に基づき、エッジが新しい行としてエッジ表に後で挿入されます。エッジにスキーマで定義されたプロパティが含まれていない場合、指定した列の値はNULLに設定されます。

次のコード・スニペットは、OraclePropertyGraph APIを使用して、プロパティ・グラフemployeesGraphDALを作成し、2つの頂点と1つのエッジをロードします。次に、2表スキーマを使用して、頂点表organizationEdgesを作成し、それにemployeesGraphDALのエッジからのデータを移入します。

// Create employeesGraphDAL
import oracle.pg.rdbms.*;
Oracle oracle = new Oracle(jdbcURL, username, password);
OraclePropertyGraph opgEmployees
                  = OraclePropertyGraph.getInstance(oracle, "employeesGraphDAL");

// Create vertex v1 and assign it properties as key-value pairs
Vertex v1 = opgEmployees.addVertex(1l);
v1.setProperty("age",  Integer.valueOf(31));
v1.setProperty("name", "Alice");
v1.setProperty("address", "Main Street 12");
v1.setProperty("email", "alice@mymail.com");
v1.setProperty("SSN", "123456789");

Vertex v2 = opgEmployees.addVertex(2l);
v2.setProperty("age",  Integer.valueOf(27));
v2.setProperty("name", "Bob");
v2.setProperty("adress", "Sesame Street 334"); 
       
// Add edge e1
Edge e1 = opgEmployees.addEdge(1l, v1, v2, "managerOf");
e1.setProperty("weight", 0.5d);

opgEmployees.commit();

// Prepare the edge table using a Two Tables schema
import oracle.pgx.common.types.PropertyType;
       Connection conn 
            = opgEmployees.getOracle().clone().getConnection(); /* Clone the connection
                                                                   from the property graph 
                                                                   instance */    
List<String> propertyNames = new ArrayList<String>();
propertyNames.addAll(new String[1]{ "weight" });

List<PropertyType> = new ArrayList<PropertyType>();
propertyType.add(PropertyType.DOUBLE);
OraclePropertyGraphUtils.prepareTwoTablesGraphEdgeTab(conn /* Connection object */,
                                            pg /* table owner */, 
                                            organizationEdges" /* edge table name */, 
                                            propertyNames /* property names */, 
                                            propertyTypes /* property data types */,
                                            "pgts" /* table space */, 
                                            null /* storage options */, 
                                            true /* no logging */);

// Get the edges from the employeesDAL graph
Iterator<Edge> edges = opgEmployees.getEdges().iterator();

// Load the edges into the edges table using a Two-Tables schema
Connection[] conns = new Connection[1]; /* the connection array size defines the
                                           Degree of parallelism (multithreading)
                                        */
conns[1] = conn;
OraclePropertyGraphUtils.writeTwoTablesGraphVertexAndProperties(conn /* Connection 
                                                                        object */,
                                            pg /* table owner */, 
                                            "organizationEdges" /* edge table 
                                                                   name */,  
                                            1000 /* batch size*/, 
                                            new Iterator[] {edges} /* array of 
                                                           iterator of edges */); 

格納操作のパフォーマンスを最適化するために、writeTwoTablesGraph APIを呼び出すときに、フラグやヒントのセットを指定できます。これらのヒントとしては次のものがあります。

  • DOP: 並列度。接続配列のサイズが、データのロード時に使用する並列度を定義します。これは、データを表にロードするときに使用するローダー・スレッドの数と同様に、Iterableの読取り時に生成するチャンクの数を決定します。

  • バッチ・サイズ: バッチ・モードでOracleのupdate文で使用するバッチ・サイズを指定する整数。推奨バッチ・サイズは1000です。