27.13.13 データベースからのPgxFrameのロード
Oracleデータベースのリレーショナル表から
PgxFrame
をロードできます。リレーショナル表の各列は、ロードされたフレーム内の列に対応します。データベースからPgxFrame
をロードする場合、デフォルトの動作では、表の列が検出され、それらがすべてロードされます。明示的に指定しない場合、現在のユーザーおよびセッションの接続詳細が使用され、列が自動的に検出されます。また、CLOBデータ型の列を含むデータベース表からPgxFrame
をロードできます。
データベース表からPgxFrame
をロードするステップを次に示します。
- 次のようにセッションとアナリストを作成します。
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()
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() ... )
- 列のサブセットのみをロードする必要がある場合は、次の例に示すように列を指定できます。次の例では、別のスキーマから
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オブジェクトからのグラフの作成を参照してください。
親トピック: PgxFrameの表形式データ構造