26.13.14 Loading a PgxFrame from a CSV File

In order to load a PgxFrame from a CSV file, you first need to explicitly authorize access to the corresponding directories by defining a directory object pointing to the directory (on the graph server) where the file needs to be written.
CREATE OR REPLACE DIRECTORY graph_files AS '/tmp';
GRANT READ, WRITE ON DIRECTORY graph_files TO GRAPH_DEVELOPER;

Also, note the following:

  • The directory in the CREATE DIRECTORY statement must exist on the graph server (PGX).
  • The directory must be readable at the OS level by the graph server (PGX).

The preceding code grants the privileges on the directory to the GRAPH_DEVELOPER role. However, you can also grant permissions to an individual user:

GRANT READ ON DIRECTORY graph_files TO <graph_user>;

You can then load a PgxFrame from a CSV file as shown in the following example:

opg4j> import oracle.pgx.api.frames.schema.datatypes.*
opg4j> import static oracle.pgx.api.frames.schema.ColumnDescriptor.columnDescriptor

opg4j> var exampleFrame = session.readFrame().csv().
...>     name("transfersFrame").
...>     columns(
...>       columnDescriptor("from_acct_id", DataTypes.INTEGER_TYPE),
...>       columnDescriptor("to_acct_id", DataTypes.INTEGER_TYPE),
...>       columnDescriptor("amount", DataTypes.FLOAT_TYPE),
...>       columnDescriptor("description", DataTypes.STRING_TYPE)
...>     ).
...>     load("/tmp/Transfers.csv")
import oracle.pgx.api.frames.schema.datatypes.*;
import static oracle.pgx.api.frames.schema.ColumnDescriptor.columnDescriptor;

PgxFrame exampleFrame = session.readFrame().csv().
    name("transfersFrame").
    columns(
      columnDescriptor("from_acct_id", DataTypes.INTEGER_TYPE),
      columnDescriptor("to_acct_id", DataTypes.INTEGER_TYPE),
      columnDescriptor("amount", DataTypes.FLOAT_TYPE),
      columnDescriptor("description", DataTypes.STRING_TYPE)
    ).
    load("/tmp/Transfers.csv");
>>> example_frame = session.read_frame(). \
...     csv(). \
...     name('transfers_frame'). \
...     columns([('from_acct_id', 'INTEGER_TYPE'),
...              ('to_acct_id', 'INTEGER_TYPE'),
...              ('amount', 'FLOAT_TYPE'),
...              ('description', 'STRING_TYPE')]). \
...     load('/tmp/Transfers.csv')