4.5.1 Creating a JSON Configuration to Load a Graph
Loading a Graph from the Property Graph Schema Using JSON Configuration
The graph server (PGX) allows the loading of property graphs from Oracle Database using the property graph schema.
You can create a graph configuration file to load the graph. The following shows a sample graph configuration file that uses a keystore to connect to the database. See Store the Database Password in a Keystore for more information on using a keystore.
{
"name": "BANK_ACCOUNTS",
"format": "pg",
"db_engine": "rdbms",
"jdbc_url": "jdbc:oracle:thin:@<host>:<port>/<service_name>",
"username":"graphuser",
"keystore_alias":"database1",
"vertex_props": [
{
"name": "ID",
"type": "integer"
},
{
"name": "NAME",
"type": "string"
}
],
"edge_props": [
{
"name": "AMOUNT",
"type": "float"
},
{
"name": "DESCRIPTION",
"type": "string"
}
],
"partition_while_loading": "by_label",
"loading":{
"load_edge_label":true,
"load_vertex_labels": true,
"create_vertex_id_mapping": true,
"create_edge_id_mapping": true
}
}
See API for Loading Graphs into Memory for more information on PgxSession
API
methods for reading graphs into memory.
You can now read the graph into the graph server (PGX) using the
PgxSession
API method as shown:
opg4j> var g = session.readGraphWithProperties("bank_graph.json")
PgxGraph g = session.readGraphWithProperties("bank_graph.json");
g = session.read_graph_with_properties("bank_graph.json")
Loading a Partitioned Graph Using JSON Configuration
In order to load a partitioned graph into the graph server (PGX), you can create a graph configuration file, which contains metadata about the graph to be loaded.
The following shows a sample partitioned graph configuration file:
{
"name": "bank_graph_analytics",
"vertex_providers":[
{
"name":"Accounts",
"format":"rdbms",
"database_table_name":"BANK_ACCOUNTS",
"key_column":"ID",
"key_type": "integer",
"parallel_hint_degree": 3,
"props":[
{
"name":"ACCT_ID",
"type":"integer",
"column":"ID"
},
{
"name":"ACCT_NAME",
"type":"string",
"column":"NAME"
}
]
}
],
"edge_providers":[
{
"name":"Transfers",
"format":"rdbms",
"database_table_name":"BANK_TXNS",
"key_column":"ID",
"parallel_hint_degree": 3,
"source_column":"FROM_ACCT_ID",
"destination_column":"TO_ACCT_ID",
"source_vertex_provider":"Accounts",
"destination_vertex_provider":"Accounts",
"props":[
{
"name":"FROM_ACCT_ID",
"type":"integer"
},
{
"name":"TXN_AMOUNT",
"type":"float",
"column":"AMOUNT"
},
{
"name":"TXN_DESC",
"type":"string",
"column":"DESCRIPTION"
},
{
"name":"TO_ACCT_ID",
"type":"integer"
}
]
}
]
}
In the preceding configuration file, the vertex and edge properties
are renamed to different values. For example, edge property
AMOUNT
is renamed to TXN_AMT
. This implies
that you can rename vertex or edge properties when loading a graph in to the
graph server (PGX) to have different names than the names of the underlying
columns in the database.
See Also:
- Configuring PARALLEL Hint when Loading a Partitioned Graph
- Graph Configuration Options for more details on partitioned graph configuration options.
You can now read the graph into the graph server as shown:
opg4j> var g = session.readGraphWithProperties("bank_graph_analytics.json")
PgxGraph g = session.readGraphWithProperties("bank_graph_analytics.json");
g = session.read_graph_with_properties("bank_graph_analytics.json")