26.5.1.1.2 Loading Edge Providers
alterationBuilder.addEdgeProvider(EntityProviderConfig edgeProviderConfig) where
edgeProviderConfig
. edgeProviderConfig
is an edge provider
configuration and it provides configuration details such as:
- location of the datasource to load from
- the stored format
- properties of the edge provider
The source and destination vertex providers to which it is linked must either be already in the base graph (and not removed in the alteration), or added with the alteration.
Adding an Edge Provider from a JSON Configuration
You can also add the provider by calling
alterationBuilder.addEdgeProvider(String pathToEdgeProviderConfig)
where
pathToEdgeProviderConfig
points to a file accessible from the client that
contains a JSON representation of an edge provider configuration.
For example, an edge provider configuration can be stored in a JSON file as shown:
{
"name": "Transfers",
"format": "rdbms",
"database_table_name": "BANK_EDGES_AMT",
"key_column": "ID",
"source_column": "SRC_ID",
"destination_column": "DEST_ID",
"source_vertex_provider": "Accounts",
"destination_vertex_provider": "Accounts",
"props": [
{
"name": "AMOUNT",
"type": "float"
}
]
}
You can then add the edge provider as shown in the following example:
// Loading by indicating the path to the JSON file
opg4j> alterationBuilder.addEdgeProvider("<path-to-edge-provider-configuration>")
$10 ==> oracle.pgx.api.graphalteration.internal.GraphAlterationBuilderImpl@48d464cf
// Or by first loading the content of a JSON file into an EntityProviderConfig object
opg4j> EntityProviderConfig edgeProviderConfig = new AnyFormatEntityProviderConfigFactory().fromPath("<path-to-edge-provider-configuration>")
edgeProviderConfig ==> {"format":"rdbms","source_vertex_provider":"Accounts","name":"Transfers","database_table_name":"BANK_EDGES_AMT","loading":{"create_key_mapping":false},"source_column":"SRC_ID","destination_column":
"DEST_ID","key_type":"long","destination_vertex_provider":"Accounts","props":[{"type":"float","name":"AMOUNT"}],"key_column":"ID"}
opg4j> alterationBuilder.addEdgeProvider(edgeProviderConfig)
$26 ==> oracle.pgx.api.graphalteration.internal.GraphAlterationBuilderImpl@7b303608
// Loading by indicating the path to the JSON file
alterationBuilder.addEdgeProvider("<path-to-edge-provider-configuration>");
// Or by first loading the content of a JSON file into an EntityProviderConfig object
EntityProviderConfig edgeProviderConfig = new AnyFormatEntityProviderConfigFactory().fromPath("<path-to-edge-provider-configuration>");
alterationBuilder.addEdgeProvider(edgeProviderConfig);
# Loading by indicating the path to the JSON file
alterationBuilder.add_edge_provider("<path-to-edge-provider-configuration>");
Adding an Edge Provider Programmatically Using an API
Alternatively, the edge provider configuration can be built programmatically:
opg4j> RdbmsEntityProviderConfigBuilder edgeProviderConfigBuilder = new RdbmsEntityProviderConfigBuilder().
...> setName("Transfers").
...> setKeyColumn("id").
...> setSourceColumn("src_id").
...> setDestinationColumn("dest_id").
...> setSourceVertexProvider("Accounts").
...> setDestinationVertexProvider("Accounts").
...> createKeyMapping(true).
...> setDatabaseTableName("bank_txns").
...> addProperty("from_acct_id", PropertyType.LONG).
...> addProperty("to_acct_id", PropertyType.LONG).
...> addProperty("amount", PropertyType.LONG)
edgeProviderConfigBuilder ==> oracle.pgx.config.RdbmsEntityProviderConfigBuilder@5a5f65b9
opg4j> EntityProviderConfig edgeProviderConfig = edgeProviderConfigBuilder.build()
edgeProviderConfig ==> {"error_handling":{},"attributes{},"destination_column":"dest_id","key_type":"long","destination_vertex_provider":"Accounts","key_column":"id","format":"rdbms","source_vertex_provider":
"Accounts","name":"Transfers","database_table_name":"bank_txns","loading":{"create_key_mapping":true},"source_column":"src_id","props":[{"dimension":0,"type":"long","name":"from_acct_id"},{"dimension":0,"type":"long",
"name":"to_acct_id"},{"dimension":0,"type":"long","name":"amount"}]}
opg4j> alterationBuilder.addEdgeProvider(edgeProviderConfig)
$30 ==> oracle.pgx.api.graphalteration.internal.GraphAlterationBuilderImpl@441ccfd7
RdbmsEntityProviderConfigBuilder edgeProviderConfigBuilder = new RdbmsEntityProviderConfigBuilder()
.setName("Transfers")
.setKeyColumn("id")
.setSourceColumn("src_id")
.setDestinationColumn("dest_id").
.setSourceVertexProvider("Accounts")
.setDestinationVertexProvider("Accounts")
.createKeyMapping(true)
.setDatabaseTableName("bank_txns")
.addProperty("from_acct_id", PropertyType.LONG)
.addProperty("to_acct_id", PropertyType.LONG)
.addProperty("amount", PropertyType.LONG);
EntityProviderConfig edgeProviderConfig = edgeProviderConfigBuilder.build();
alterationBuilder.addEdgeProvider(edgeProviderConfig);
Parent topic: Loading Or Removing Additional Vertex or Edge Providers