14.12.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:
- 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 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.*Creating a Session and an Analyst Using Javaimport 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();Creating a Session and an Analyst Using Pythonsession = pypgx.get_session(session_name="my-session") analyst = session.create_analyst() - Load a
PgxFrame.Loading a PgxFrame Using JShellopg4j> 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 JavaPgxFrame 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(); - 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 Javaimport 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.
Parent topic: PgxFrames Tabular Data-Structure