28.1 ファイルからのグラフ・データのロード
複数のファイル形式(.csv
、.xml
、.pgb
など)からグラフ・データをロードできます。
session.readGraphFiles() APIを使用したグラフのロード
CSV
ファイルからグラフをロードする場合は、それらのファイルに、ロードする列の名前がプロパティとして示されているヘッダーがあることを確認してください。このヘッダーは、特定の形式に従っている必要があります。ヘッダー詳細を含むCSV
ファイルの例は、「カンマ区切り値(CSV)」を参照してください。
グラフ・サーバー(PGX)により、このヘッダーを使用して、ロードするプロパティの名前とタイプ、および頂点(またはエッジ)IDとして使用する列、エッジの出力頂点IDと入力頂点IDを示す列、ならびに頂点またはエッジ・ラベルとしてロードする列が特定されます。
その後、PgxSession.readGraphFiles()
APIを使用してそのグラフをロードできます。このメソッドは次の3つの引数を使用します。
- 頂点ファイルへのパス
- エッジ・ファイルへのパス
- グラフの名前
opg4j> var loadedGraph = session.readGraphFiles("<path/vertices.csv>
", "<path/edges.csv>
", "<graph_name>
")
import oracle.pgx.api.PgxSession;
import oracle.pgx.api.PgxGraph;
PgxSession session = Pgx.createSession("NewSession");
PgxGraph loadedGraph = session.readGraphFiles("<path/vertices.csv>
", "<path/edges.csv>
", "<graph_name>
");
session = pypgx.get_session(session_name="<session_name>")
loaded_graph = session.read_graph_files("<path/vertices.csv>
", "<path/edges.csv>
", "<graph_name>
")
GraphConfigBuilder
オブジェクトを使用したグラフのロード
次のように、グラフ・データ・ファイルのグラフ構成オブジェクトを作成してからそのグラフをグラフ・サーバー(PGX)にロードできます:
opg4j> var vertexProviderConfig = new FileEntityProviderConfigBuilder(ProviderFormat.CSV).
...> addUri("sample.vertices.csv").
...> setName("vertices").
...> setKeyType(IdType.INTEGER).
...> setKeyColumn(1).
...> build()
vertexProviderConfig ==> {"key_type":"integer","props":[],"key_column":1,"name":"vertices","format":"csv","uris":["sample.vertices.csv"],
"loading":{"create_key_mapping":true},"error_handling":{},"attributes":{}}
opg4j> var edgeProviderConfig = new FileEntityProviderConfigBuilder(ProviderFormat.CSV).
...> addUri("sample.edges.csv").
...> setName("edges").
...> setSourceVertexProvider("vertices").
...> setDestinationVertexProvider("vertices").
...> setSourceColumn(1).
...> setDestinationColumn(2).
...> build()
edgeProviderConfig ==> {"destination_vertex_provider":"vertices","props":[],"source_column":1,"format":"csv","loading":{"create_key_mapping":false},
"error_handling":{},"attributes":{},"destination_column":2,"key_type":"long","source_vertex_provider":"vertices","name":"edges","uris":["sample.edges.csv"]}
opg4j> var config = GraphConfigBuilder.forPartitioned().
...> addVertexProvider(vertexProviderConfig).
...> addEdgeProvider(edgeProviderConfig).
...> setName("simple graph").
...> setVertexIdType(IdType.INTEGER).
...> build()
config ==> {"edge_providers":[{"destination_vertex_provider":"vertices","props":[],"storing":{},"source_column":1,"time_with_timezone_format":
["h[h]:m[m][:s[s]] a[ XXX]","[yyyy-MM-dd'T']H[H]:m[m][:s[s][.SSS[SSS]]][XXX]","yyyy-MM-dd'T'H[H]:m[m][:s[s][.SSSSSS]][XXX]"],"format":"csv",
"loading":{"create_key_mapping":false},"has_keys":true,"error_handling":{},"attributes":{},"timestamp_format":["yyyy-MM-dd'T'H[H]:m[m][:s[s][.SSS[SSS]]][XXX]",
"yyyy-MM-dd H[H]:m[m][:s[s][.SSS[SSS]]][XXX]","yyyy-MM-dd'T'H[H]:m[m][:s[s][.SSSSSS]][XXX]"],"destination_column":2,"key_type":"long",
"time_format":["h[h]:m[m][:s[s][.SSS]] a[ XXX]","[yyyy-MM-dd'T']H[H]:m[m][:s[s][.SSS[SSS]]][XXX]","yyyy-MM-dd'T'H[H]:m[m][:s[s][.SSSSSS]][XXX]"],
"source_vertex_provider":"vertices","local_date_format":["yyyy-M[M]-d[d]","M[M]/d[d]/yyyy","d[d]-MMM-yyyy","d[d]-M[M]-yyyy","yyyy-MM-dd'T'H[H]:m[m][:s[s][.SSS[SSS]]][XXX]",
"yyyy-MM-dd'T'H[H]:m[m][:s[s][.SSSSSS]][XXX]"],"timestamp_with_timezone_format":["yyyy-MM-dd'T'H[H]:m[m][:s[s][.SSS[SSS]]][XXX]","yyyy-MM-dd H[H]:m[m][:s[s][.SSS[SSS]]][XXX]",
"yyyy-MM-dd'T'H[H]:m[m][:s[s][.SSSSSS]][XXX]"],"header":false,"name":"edges","uris":["sample.edges.csv"]}],"vertex_providers":[{"props":[],"storing":{},"key_column":1,
"time_with_timezone_format":["h[h]:m[m][:s[s]] a[ XXX]","[yyyy-MM-dd'T']H[H]:m[m][:s[s][.SSS[SSS]]][XXX]","yyyy-MM-dd'T'H[H]:m[m][:s[s][.SSSSSS]][XXX]"],
"format":"csv","loading":{"create_key_mapping":true},"has_keys":true,"error_handling":{},"attributes":{},"timestamp_format":["yyyy-MM-dd'T'H[H]:m[m][:s[s][.SSS[SSS]]][XXX]",
"yyyy-MM-dd H[H]:m[m][:s[s][.SSS[SSS]]][XXX]","yyyy-MM-dd'T'H[H]:m[m][:s[s][.SSSSSS]][XXX]"],"key_type":"integer","time_format":["h[h]:m[m][:s[s][.SSS]] a[ XXX]",
"[yyyy-MM-dd'T']H[H]:m[m][:s[s][.SSS[SSS]]][XXX]","yyyy-MM-dd'T'H[H]:m[m][:s[s][.SSSSSS]][XXX]"],"local_date_format":["yyyy-M[M]-d[d]","M[M]/d[d]/yyyy",
"d[d]-MMM-yyyy","d[d]-M[M]-yyyy","yyyy-MM-dd'T'H[H]:m[m][:s[s][.SSS[SSS]]][XXX]","yyyy-MM-dd'T'H[H]:m[m][:s[s][.SSSSSS]][XXX]"],"timestamp_with_timezone_format":["yyyy-MM-dd'T'H[H]:m[m][:s[s][.SSS[SSS]]][XXX]",
"yyyy-MM-dd H[H]:m[m][:s[s][.SSS[SSS]]][XXX]","yyyy-MM-dd'T'H[H]:m[m][:s[s][.SSSSSS]][XXX]"],"header":false,"name":"vertices","uris":["sample.vertices.csv"]}],
"error_handling":{},"name":"simple graph","vertex_id_type":"integer","attributes":{},"loading":{}}
opg4j> var graph = session.readGraphWithProperties(config)
EntityProviderConfig vertexProviderConfig = new FileEntityProviderConfigBuilder(ProviderFormat.CSV)
.addUri("sample.vertices.csv")
.setName("vertices")
.setKeyType(IdType.INTEGER)
.setKeyColumn(1)
.build();
EntityProviderConfig edgeProviderConfig = new FileEntityProviderConfigBuilder(ProviderFormat.CSV)
.addUri("sample.edges.csv")
.setName("edges")
.setSourceVertexProvider("vertices")
.setDestinationVertexProvider("vertices")
.setSourceColumn(1)
.setDestinationColumn(2)
.build();
PartitionedGraphConfig config = GraphConfigBuilder.forPartitioned()
.addVertexProvider(vertexProviderConfig)
.addEdgeProvider(edgeProviderConfig)
.setName("simple graph")
.setVertexIdType(IdType.INTEGER)
.build();
PgxGraph graph = session.readGraphWithProperties(config);