14.13.1 Loading a PgxFrame from a Database

PgxFrame(s) can also be loaded from relational tables in an Oracle database. Each column of the relational table will correspond to a column in the loaded frame. When loading PgxFrames from the database, the default behavior is to detect what columns the table has, and to load them all. If not specified explicitly, the connection details of the current user and session are used and the columns are detected automatically.

The following describes the steps to load a PgxFrame from a database table:

  1. Create a Session and an Analyst:
    cd /opt/oracle/graph/
    ./bin/opg4j
    // starting the shell will create an implicit session and analyst
    opg4j> import static oracle.pgx.api.frames.functions.ColumnRenaming.renaming
    opg4j> import static oracle.pgx.api.frames.schema.ColumnDescriptor.columnDescriptor
    opg4j> import oracle.pgx.api.frames.schema.*
    opg4j> import oracle.pgx.api.frames.schema.datatypes.*
    import oracle.pgx.api.*;
    import oracle.pgx.api.frames.*;
    import oracle.pgx.api.frames.functions.*;
    import oracle.pgx.api.frames.schema.*;
    import oracle.pgx.api.frames.schema.datatypes.*;
    import static oracle.pgx.api.frames.functions.ColumnRenaming.renaming;
    import static oracle.pgx.api.frames.schema.ColumnDescriptor.columnDescriptor;
    
    PgxSession session = Pgx.createSession("my-session");
    Analyst analyst = session.createAnalyst();
    session = pypgx.get_session(session_name="my-session")
    analyst = session.create_analyst()
  2. Load a PgxFrame.
    opg4j> var exampleFrame = session.readFrame().
        db().
        name("framename").      // name of the frame
        tablename("tablename"). // name of the table from where the data must be loaded
        connections(16).        // indicates that 16 connections can be used to load in parallel
        load()
    PgxFrame exampleFrame = session.readFrame()
        .db()
        .name("framename")      // name of the frame
        .tablename("tablename") // name of the table from where the data must be loaded
        .connections(16)        // indicates that 16 connections can be used to load in parallel
        .load();
  3. If only a subset of the columns must be loaded, then you must specify the columns with FrameReader.columns().
    // You must specify jdbc connection, keystore and the columns to load
    opg4j> session.registerKeystore("keystore", pathToKeystore, keystorePassword)
    opg4j> var exampleFrame = session.readFrame().
        db().
        name("framename").
        tablename("tablename").      // name of the table from where the data must be loaded
        jdbcUrl("jdbcUrl").
        username("user").
        keystoreAlias("keytore").
        owner("owner").              // necessary if the table is owned by another user
        connections(16).             // indicates that 16 connections can be used to load in parallel
        columns(exampleFrameSchema). // columns to load
        load()
    import oracle.pgx.api.frames.schema.datatypes.DataTypes;
    import oracle.pgx.api.frames.schema.ColumnDescriptor;
    // You must specify jdbc connection, keystore and the columns to load
    session.registerKeystore("keystore", pathToKeystore, keystorePassword)
    PgxFrame exampleFrame = session.readFrame()
        .db()
        .name("framename")
        .tablename("tablename")      // name of the table from where the data must be loaded
        .jdbcUrl("jdbcUrl")
        .username("user")
        .keystoreAlias("keytore")
        .owner("owner")              // necessary if the table is owned by another user
        .connections(16)             // indicates that 16 connections can be used to load in parallel
        .columns(exampleFrameSchema) // columns to load
        .load();
    You can also create a graph from the PgxFrame(s). See Creating a Graph from Multiple PgxFrame Objects for more information.