27.13.8 ベクトル・プロパティのロードと格納

PgxFrameを使用して、グラフ・サーバー(PGX)のPgxML機能の基礎であるベクトル・プロパティをロードまたは格納できます。

ベクトル・プロパティを含むPgxFrameをロードするには、次に示すステップに従います。

  1. PgxFrameスキーマを作成し、次に示すように列を定義します。
    opg4j> var vecFrameSchema = List.of(
      columnDescriptor("intProp", DataTypes.INTEGER_TYPE),
      columnDescriptor("intProp2", DataTypes.INTEGER_TYPE),
      columnDescriptor("vectProp", DataTypes.vector(DataTypes.FLOAT_TYPE, 3)),
      columnDescriptor("stringProp", DataTypes.STRING_TYPE),
      columnDescriptor("vectProp2", DataTypes.vector(DataTypes.FLOAT_TYPE, 2))
    ).toArray(new ColumnDescriptor[0])
    ColumnDescriptor[] vecFrameSchema = {
        columnDescriptor("intProp", DataTypes.INTEGER_TYPE),
        columnDescriptor("intProp2", DataTypes.INTEGER_TYPE),
        columnDescriptor("vectProp", DataTypes.vector(DataTypes.FLOAT_TYPE, 3)),
        columnDescriptor("stringProp", DataTypes.STRING_TYPE),
        columnDescriptor("vectProp2", DataTypes.vector(DataTypes.FLOAT_TYPE, 2))
    };
  2. 指定したパスから、指定したスキーマでPgxFrameをロードします。
    opg4j> var vecFrame = session.readFrame().
        db().
        name("vector PgxFrame").
        tablename("tablename").      // name of the table from where the data must be loaded
        jdbcUrl("jdbcUrl").
        username("user").
        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(vecFrameSchema).     // columns to load
        load()
    PgxFrame vecFrame = session.readFrame()
        .db()
        .name("vector PgxFrame")
        .tablename("tablename")      // name of the table from where the data must be loaded
        .jdbcUrl("jdbcUrl")
        .username("user")
        .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(vecFrameSchema)     // columns to load
        .load();
    PgxFrame内の最終結果は、次のようになります。
    +-----------------------------------------------------------+
    | intProp | intProp2 | vectProp    | stringProp | vectProp2 |
    +-----------------------------------------------------------+
    | 0       | 2        | 0.1;0.2;0.3 | testProp0  | 0.1;0.2   |
    | 1       | 1        | 0.1;0.2;0.3 | testProp10 | 0.1;0.2   |
    | 1       | 2        | 0.1;0.2;0.3 | testProp20 | 0.1;0.2   |
    | 2       | 3        | 0.1;0.2;0.3 | testProp30 | 0.1;0.2   |
    | 3       | 1        | 0.1;0.2;0.3 | testProp40 | 0.1;0.2   |
    +-----------------------------------------------------------+