15.12.1 Loading a PgxFrame from a Database

PgxFrames 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.
    Creating a Session and an Analyst Using JShell
    
    cd /opt/oracle/graph/
    ./bin/opg4j
    // starting the shell will create an implicit session and analyst
    Creating a Session and an Analyst Using Java
    
    import oracle.pgx.api.*;
    import oracle.pgx.api.frames.*;
    ...
    PgxSession session = Pgx.createSession("my-session");
    Analyst analyst = session.createAnalyst();
    Creating a Session and an Analyst Using Python
    
    session = pypgx.get_session(session_name="my-session")
    analyst = session.create_analyst()
  2. Load a PgxFrame.
    Loading a PgxFrame Using JShell
    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();
    Loading a PgxFrame Using Java
    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().
    Loading a PgxFrame for a Subset of Columns Using JShell
    // 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();
    Loading a PgxFrame for a Subset of Columns Using Java
    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();