27.13.13 データベースからのPgxFrameのロード

Oracleデータベースのリレーショナル表からPgxFrameをロードできます。リレーショナル表の各列は、ロードされたフレーム内の列に対応します。データベースからPgxFrameをロードする場合、デフォルトの動作では、表の列が検出され、それらがすべてロードされます。明示的に指定しない場合、現在のユーザーおよびセッションの接続詳細が使用され、列が自動的に検出されます。また、CLOBデータ型の列を含むデータベース表からPgxFrameをロードできます。

データベース表からPgxFrameをロードするステップを次に示します。

  1. 次のようにセッションアナリストを作成します。
    cd /opt/oracle/graph/
    ./bin/opg4j
    
    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.*
    
    opg4j> var session = Pgx.createSession("my-session")
    opg4j> var analyst = session.createAnalyst()
    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. PgxFrameをロードします。この例では、現在ログインしているスキーマからPgxFrameをロードすることを前提としています。
    opg4j> var exampleFrame = session.readFrame().
    ...>       db().
    ...>       name("Transfers").      // name of the frame
    ...>       tablename("T1").        // 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("Transfers")     // name of the frame 
        .tablename("T1")       // 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();
    >>> example_frame = (
    ...     session.read_frame().
    ...     name('Transfers').    # name of the frame
    ...     db().
    ...     table_name('T1').     # 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. 列のサブセットのみをロードする必要がある場合は、次の例に示すように列を指定できます。次の例では、別のスキーマからPgxFrameをロードしていることに注意してください。
    opg4j> session.registerKeystore("<pathToKeystore>", "<keystorePassword>".toCharArray())
    opg4j> var exampleFrame = session.readFrame().
    ...>       db().
    ...>       name("Transfers").  // name of the frame
    ...>       tablename("T1").    // name of the table from where the data must be loaded
    ...>       jdbcUrl("<jdbcUrl>").
    ...>       username("<username>").
    ...>       keystoreAlias("<keystoreAlias>").
    ...>       connections(16).    // indicates that 16 connections can be used to load in parallel
    ...>       columns(
    ...>         columnDescriptor("FROM_ACCT_ID", DataTypes.INTEGER_TYPE),
    ...>         columnDescriptor("TO_ACCT_ID", DataTypes.INTEGER_TYPE)
    ...>       ).                 // columns to load
    ...>       load()
    session.registerKeystore("<pathToKeystore>", "<keystorePassword>".toCharArray())
    PgxFrame exampleFrame = session.readFrame()
        .db()
        .name("Transfers") // name of the frame
        .tablename("T1")   // name of the table from where the data must be loaded
        .jdbcUrl("<jdbcUrl>")
        .username("<username>")
        .keystoreAlias("<keystoreAlias>")
        .connections(16)  // indicates that 16 connections can be used to load in parallel
        .columns(
           columnDescriptor("FROM_ACCT_ID", DataTypes.INTEGER_TYPE),
           columnDescriptor("TO_ACCT_ID", DataTypes.INTEGER_TYPE)
         )               // columns to load
        .load();
    >>> session.register_keystore("<pathToKeystore>", "<keystorePassword>")
    >>> example_frame = (
    ...     session.read_frame().
    ...     name('Transfers').   # name of the frame
    ...     db(). 
    ...     table_name('T1').    # name of the table from where the data must be loaded
    ...     jdbc_url('<jdbc_url>'). 
    ...     username('<username>').
    ...     keystore_alias('<keystore_alias>'). 
    ...     connections(16).     # indicates that 16 connections can be used to load in parallel
    ...     columns(
    ...       [
    ...         ('FROM_ACCT_ID', 'INTEGER_TYPE'),
    ...         ('TO_ACCT_ID', 'INTEGER_TYPE')
    ...       ]
    ...     ).  # columns to load
    ...     load()
    ...     )
    PgxFrameからグラフを作成することもできます。詳細は、複数のPgxFrameオブジェクトからのグラフの作成を参照してください。