DataWorks数据集成支持使用Maxgraph Writer导入MaxCompute表数据至Maxgraph,本文为您介绍DataWorks的Maxgraph数据写入能力。

使用限制

  • 当前仅支持使用脚本模式将数据写入Maxgraph。
  • 当前主要应用场景为同步MaxCompute数据至Maxgraph。

数据同步前准备:Maxgraph账号权限配置

如果需要导入MaxCompute表至Maxgraph,请先在源端MaxCompute项目中授予Maxgraph build账号读取源端MaxCompute表的权限。请联系Maxgraph管理员提供关于授权的Maxgraph build账号。

数据同步任务开发

附录:Maxgraph脚本Demo与参数说明

附录:离线任务脚本配置方式

如果您配置离线任务时使用脚本模式的方式进行配置,您需要在任务脚本中按照脚本的统一格式要求编写脚本中的reader参数和writer参数,脚本模式的统一要求请参见通过脚本模式配置离线同步任务,以下为您介绍脚本模式下的数据源的Reader参数和Writer参数的指导详情。

Maxgraph Writer脚本Demo

Maxgraph中点和边的导入配置不一致,所以Maxgraph Writer需要区分点和边。
  • 点配置示例
    {
      "job": {
        "setting": {
          "speed": {
            "channel": 1 //配置channel为1即可。
          },
          "errorLimit": {
            "record": 1000
          }
        },
        "content": [
          {
            "reader": {
              "name": "odpsreader",
              "parameter": {
                "accessId": "*****",
                "accessKey": "*****",
                "project": "maxgraph_dev",
                "table": "maxgraph_demo_person",
                "column": [ //对应MaxCompute表的column名称,与Writer配置项中的column一一对应。
                  "id",
                  "name",
                  "age"
                ],
                "packageAuthorizedProject": "biggraph_dev",
                "splitMode": "record",
                "odpsServer": "******"
              }
            },
            "writer": {
              "name": "maxgraphwriter",
              "parameter": {
                "endpoint": "http://graph.alibaba.net",
                "graphName": "xxx",
                "accessId": "xxx",
                "accessKey": "xxx",
                "label": "person",
                "labelType": "vertex",
                "onlineMode": "partition",
                "splitSize": "256",
                "column": [ //对应Maxgraph vertex的属性名,与reader配置项中的column一一对应。
                  "id",
                  "name",
                  "age"
                ]
              }
            }
          }
        ]
      }
    }
                            
  • 边配置示例
    {
      "job": {
        "setting": {
          "speed": {
            "channel": 1 //配置channel为1即可。
          },
          "errorLimit": {
            "record": 1000
          }
        },
        "content": [
          {
            "reader": {
              "name": "odpsreader",
              "parameter": {
                "accessId": "*****",
                "accessKey": "*****",
                "project": "maxgraph_dev",
                "table": "maxgraph_demo_knows",
                "column": [
                  "person_id",
                  "person_id2",
                  "weight",
                  "id"
                ],
                "packageAuthorizedProject": "biggraph_dev",
                "splitMode": "record",
                "odpsServer": "****"
              }
            },
            "writer": {
              "name": "maxgraphwriter",
              "parameter": {
                "endpoint": "http://graph.alibaba.net",
                "graphName": "xxx",
                "accessId": "xxx",
                "accessKey": "xxx",
                "label": "knows",
                "labelType": "edge",
                "srcLabel": "person",
                "dstLabel": "person",
                "onlineMode": "partition",
                "splitSize": "256",
                "column": [ 
                  {
                    "name": "id", //对应的在graph中的属性名。
                    "propertyType": "srcPrimaryKey" //对应该属性的类型,主要用来标识是起点、终点还是边的属性。
                  },
                  {
                    "name": "id",
                    "propertyType": "dstPrimaryKey"
                  },
                  {
                    "name": "weight",
                    "propertyType": "edgeProperty"
                  },
                  {
                    "name": "id",
                    "propertyType": "edgeProperty"
                  }
                ]
              }
            }
          }
        ]
      }
    }

Maxgraph Writer脚本参数

参数描述是否必选默认值
endpointMaxgraph的URL。
graphName图实例的名称。
accessId用户名。
accessKey用户密码。
label标签名,即点或边的名称。
labelType标签类型,只能选择vertex或edge其中一种类型。
srcLabel边的起点标签,仅在导入边时使用。
dstLabel边的终点标签,仅在导入边时使用。
splitSize创建数据过程中MapReduce作业的分片大小。256MB
onlineMode数据上线模式,包括partition和type。两者区别如下:
  • 以partition模式上线,在上线过程中可能会查询到旧数据与新数据混合的结果,但是保证最终一致性,上线速度较快。
  • 以type模式上线,只有数据上线成功后才能查询到新上线的数据,在数据上线过程中只能查询到旧的数据(假如存在旧的数据),上线速度较慢。
type
column点的属性名,仅导入点时使用。
name属性的名称。仅导入边时必填
propertyType属性的类型,包括srcPrimaryKey、dstPrimaryKey和edgeProperty。仅导入边时必填
srcPrimaryKey起点主键,仅导入边时使用。仅导入边时必填
dstPrimaryKey终点主键,仅导入边时使用。仅导入边时必填
edgeProperty边的属性,如果边没有属性,可以不填。