PGX 20.1.1
Documentation

Handling Graph Config in Applications

This document discusses how to handle Graph Config (and even creates a new one) in the user application — for Embedded Use Case.

Java APIs to Parse Graph Configuration Files

PGX provides a range of factory classes in the oracle.pgx.config package you can use to parse graph configuration files. Factories can be used to deserialize graph configurations from a range of data-sources. There is one factory for each format:

FileGraphConfigFactory factory = GraphConfigFactory.forFileFormats();
PgRdbmsGraphConfigFactory factory = GraphConfigFactory.forRdbms();
PgNosqlGraphConfigFactory factory = GraphConfigFactory.forNosql();
PgHbaseGraphConfigFactory factory = GraphConfigFactory.forHbase();
TwoTablesTextGraphConfigFactory factory = GraphConfigFactory.forTwoTablesText();
TwoTablesRdbmsGraphConfigFactory factory = GraphConfigFactory.forTwoTablesRdbms();
RdfGraphConfigFactory factory = GraphConfigFactory.forRdf();

As well as a general-purpose factory which detects the right factory by looking at the format, db_engine and datastore field of the given configuration:

GraphConfigFactory factory = GraphConfigFactory.forAnyFormat();

Every factory can deserialize configurations from various input sources:

factory.fromFilePath("/path/to/my/mygraph.json");
factory.fromJson("{ 'format': 'pgb', 'uri': 'my-graph.pgb' ... }");
factory.fromHttp("https://my-server.com/mygraph.json");
factory.fromClasspath("/classpath/to/my/mygraph.json");
factory.fromHdfs("/hdfs-path/to/my/mygraph.json");
factory.fromInputStream(new ByteArrayInputStream(...));
Properties props = ...
factory.fromProperties(props);

The returned graph config objects match its factory:

FileGraphConfig config = GraphConfigFactory.forFileFormats().from(...);
String path = config.getUri();

FileGraphConfig config = GraphConfigFactory.forFileFormats().from(...);
List<String> vertexUris = config.getVertexUris();
List<String> edgeUris = config.getEdgeUris();

PgRdbmsGraphConfig config = GraphConfigFactory.forRdbms().from(...);
String jdbcUrl = config.getJdbcUrl();

PgNosqlGraphConfig config = GraphConfigFactory.forNosql().from(...);
String[] hosts = config.getHosts();

PgHbaseGraphConfig config = GraphConfigFactory.forHbase().from(...);
String zkQuorum = config.getZkQuorum();

TwoTablesTextGraphConfig config = GraphConfigFactory.forTwoTablesText().from(...);
List<String> vertexUris = config.getVertexUris();
List<String> edgeUris = config.getEdgeUris();

TwoTablesRdbmsGraphConfig config = GraphConfigFactory.forTwoTablesRdbms().from(...);
Integer maxPrefetchedRows = config.getMaxPrefetchedRows();

RdfGraphConfig config = GraphConfigFactory.forRdf().from(...);
List<RdfGraphPrefixConfig> prefixes = config.getPrefixes();

GraphConfig config = GraphConfigFactory.forAnyFormat().from(...);
Format format = config.getFormat();

Factories can detect the protocol from the path:

factory.fromPath("/path/to/local/file/system");
factory.fromPath("hdfs:///path/to/hdfs");
factory.fromPath("https:///my-server.com/mygraph.json");
factory.fromPath("classpath:/my/class/path");
factory.fromPath("jar:/my/class/path");

See the Javadocs for the full set of APIs.


Java APIs to Build Graph Configuration Objects Programmatically

PGX provides builder classes in the oracle.pgx.config package which can be used to construct graph config objects programmatically without the need of any JSON or properties file:

Example 1

Build a single file-based graph configuration object:

FileGraphConfig cfg = GraphConfigBuilder.forFileFormat(Format.GRAPHML)
  .setUri("classpath:/my/classpath/mygraph.graphml")
  .addVertexProperty("np", PropertyType.DOUBLE, 1.0)
  .addEdgeProperty("ep1", PropertyType.LONG, 1l)
  .addEdgeProperty("ep2", PropertyType.FLOAT, 1.0f)
  .setVertexIdType(IdType.STRING)
  .build();

Example 2

Build a multiple file-based graph configuration object:

FileGraphConfig cfg = GraphConfigBuilder.forFileFormat(Format.FLAT_FILE)
  .setVertexUris("classpath:/my/classpath/mygraph.opv", ...)
  .setEdgeUris("classpath:/my/classpath/mygraph.ope", ...)
  .addVertexProperty("np", PropertyType.DOUBLE, 1.0)
  .addEdgeProperty("ep1", PropertyType.LONG, 1l)
  .addEdgeProperty("ep2", PropertyType.FLOAT, 1.0f)
  .setVertexIdType(IdType.STRING)
  .build();

Example 3

Build a Property Graph graph configuration object targeting Oracle RDBMS database:

PgRdbmsGraphConfig cfg = GraphConfigBuilder.forRdbms()
  .setJdbcUrl("jdbc:oracle:thin:@mydatabaseserver:1521/dbName")
  .setUsername("dbUser")
  .setPassword("dbPassword")
  .setName("mygraph")
  .setLoadEdgeLabel(false)
  .setCreateEdgeIdMapping(true)
  .addEdgeProperty("ep", PropertyType.DOUBLE)
  .build();

Example 4

Build a Property Graph graph configuration object targeting Oracle NoSQL database:

PgNosqlGraphConfig cfg = GraphConfigBuilder.forNosql()
  .setName("mygraph")
  .setHosts(Arrays.asList("my-host:5000", "my-host2:5000"))
  .setStorename("mystore")
  .hasEdgeLabel(true)
  .setLoadEdgeLabel(true)
  .build();

Example 5

Build a Property Graph graph configuration object targeting Apache HBase database:

PgHbaseGraphConfig cfg = GraphConfigBuilder.forHbase()
  .setName("mygraph")
  .setZkQuorum("host1,host2,host3")
  .setZkClientPort(2181)
  .setZkSessionTimeout(60000)
  .setSplitsPerRegion(2)
  .hasEdgeLabel(true)
  .setLoadEdgeLabel(true)
  .build();

Example 6

Build a Two Tables graph configuration object targeting files:

TwoTablesTextGraphConfig cfg = GraphConfigBuilder.forTwoTablesText()
  .setVertexUris("classpath:/my/classpath/mygraph.nodes", ...)
  .setEdgeUris("classpath:/my/classpath/mygraph.edges", ...)
  .addVertexProperty("np", PropertyType.DOUBLE, 1.0)
  .addEdgeProperty("ep1", PropertyType.LONG, 1l)
  .addEdgeProperty("ep2", PropertyType.FLOAT, 1.0f)
  .setVertexIdType(IdType.LONG)
  .build();

Example 7

Build a Two Tables graph configuration object targeting Oracle RDBMS database:

TwoTablesRdbmsGraphConfig config = GraphConfigBuilder.forTwoTablesRdbms()
  .setJdbcUrl("jdbc:oracle:thin:@mydatabaseserver:1521/dbName")
  .setUsername("dbUser")
  .setPassword("dbPassword")
  .setVerticesTableName("vertices")
  .setEdgesTableName("edges")
  .addVertexProperty("np", PropertyType.STRING)
  .addEdgeProperty("ep", PropertyType.FLOAT)
  .build();

Example 8

Build a Rdf graph configuration object:

RdfGraphConfig cfg = GraphConfigBuilder.forRdf()
  .setJdbcUrl("jdbc:oracle:thin:@mydatabaseserver:1521/dbName")
  .setUsername("dbUser")
  .setPassword("dbPassword")
  .setVertexIdType(IdType.STRING)
  .setName("test")
  .hasVertexLabels(true)
  .hasEdgeLabel(true)
  .setLoadVertexLabels(true)
  .setLoadEdgeLabel(true)
  .build();

Example 9

Build a graph configuration object with string properties and set their string pooling behavior in runtime:

GraphConfig cfg =  FileGraphConfigBuilder
   .forFormat(Format.ADJ_LIST)
   .addUri(tmp.getPath())
   .addVertexStringProperty("indexed_pool_np", "default", StringPoolingStrategy.INDEXED, 67000)
   .addVertexStringProperty("on_heap_pool_np", 'default', StringPoolingStrategy.ON_HEAP, null)
   .addEdgeStringProperty("non_pool_np", "default", StringPoolingStrategy.NONE, null)
   .build();

See the Javadocs for the full set of APIs.