Graph Database (GDB) Reader y GDB Writer proporcionan sincronización bidireccional de datos entre DataWorks y los orígenes de datos de GDB.
Límites
|
Lectura de datos por lotes |
Escritura de datos por lotes |
|
|
Agregar un origen de datos
Antes de desarrollar una tarea de sincronización en DataWorks, agregue el origen de datos correspondiente siguiendo las instrucciones de Data source configuration. Consulte las descripciones de parámetros en la consola de DataWorks para comprender el significado de cada parámetro al agregar un origen de datos.
Desarrollar una tarea de sincronización de datos
Para conocer el punto de entrada y el procedimiento de configuración de una tarea de sincronización, consulte a continuación las guías de configuración correspondientes.
Configurar una tarea de sincronización por lotes para sincronizar datos de una sola tabla
Para más detalles sobre el procedimiento de configuración, consulte Configure a batch synchronization task by using the codeless UI y Configure a batch synchronization task by using the code editor.
Para consultar todos los parámetros configurados y el código que se ejecuta al usar el editor de código en una tarea de sincronización por lotes, consulte Appendix: Code and parameters.
Apéndice: Código y parámetros
Configurar una tarea de sincronización por lotes mediante el editor de código
Si desea configurar una tarea de sincronización por lotes mediante el editor de código, defina los parámetros correspondientes en el script de acuerdo con los requisitos unificados de formato. Para más información, consulte Script mode configuration. A continuación se describen los parámetros que debe configurar para los orígenes de datos cuando utiliza el editor de código.
Ejemplo de script de Reader
Cuando configure un trabajo de sincronización de datos para escribir en Graph Database (GDB), defina los vértices y las aristas por separado:
-
Configure una tarea de sincronización para leer datos de vértices desde una instancia de GDB
{ "order":{ "hops":[ { "from":"Reader", "to":"Writer" } ] }, "setting":{ "errorLimit":{ "record":"100" // Maximum number of dirty data records to tolerate. }, "jvmOption":"", "speed":{ "concurrent":3, "throttle":true, // If true, throttling is enabled. If false, throttling is disabled and the mbps parameter is ignored. "mbps":"12"// The throttling limit. 1 mbps is equal to 1 MB/s. } }, "steps":[ { "category":"reader", "name":"Reader", "parameter":{ "host": "gdb-xxxxxx.aliyuncs.com", // The endpoint of the GDB instance. "port": 8182, // The port of the GDB instance. "username": "gdb", // The username for accessing the GDB instance. "password": "gdb", // The password for the username. "labelType": "VERTEX", // The type of the label. VERTEX specifies a vertex. "labels": ["label1", "label2"], // A list of labels. If left empty, all vertices are exported. "column": [ { "name": "id", // The field name. "type": "string", // The field type. "columnType": "primaryKey" // Field category. Specifies the vertex primary key, which must be of the STRING type in GDB. }, { "name": "label", // The field name. "type": "string", // The field type. "columnType": "primaryLabel" // Field category. Specifies the vertex label, which must be of the STRING type in GDB. }, { "name": "age", // The property name. "type": "int", // The property type. "columnType": "vertexProperty" // Field category. Specifies a basic property of the vertex in GDB. } ] }, "stepType":"gdb" }, { "category":"writer", "name":"Writer", "parameter":{ "print": true }, "stepType":"stream" } ] } -
Configure una tarea de sincronización para leer datos de aristas desde una instancia de GDB
{ "order":{ "hops":[ { "from":"Reader", "to":"Writer" } ] }, "setting":{ "errorLimit":{ "record":"100" // Maximum number of dirty data records to tolerate. }, "jvmOption":"", "speed":{ "concurrent":3, "throttle":true,// If true, throttling is enabled. If false, throttling is disabled and the mbps parameter is ignored. "mbps":"12"// The throttling limit. 1 mbps is equal to 1 MB/s. } }, "steps":[ { "category":"reader", "name":"Reader", "parameter":{ "host": "gdb-xxxxxx.aliyuncs.com", // The endpoint of the GDB instance. "port": 8182, // The port of the GDB instance. "username": "gdb", // The username for accessing the GDB instance. "password": "gdb", // The password for the username. "labelType": "EDGE", // The type of the label. EDGE specifies an edge. "labels": ["label1", "label2"], // A list of labels. If left empty, all edges are exported. "column": [ { "name": "id", // The field name. "type": "string", // The field type. "columnType": "primaryKey" // Field category. Specifies the edge primary key, which must be of the STRING type in GDB. }, { "name": "label", // The field name. "type": "string", // The field type. "columnType": "primaryLabel" // Field category. Specifies the edge label, which must be of the STRING type in GDB. }, { "name": "srcId", // The field name. "type": "string", // The field type. "columnType": "srcPrimaryKey" // Field category. Specifies the start vertex primary key, which must be of the STRING type in GDB. }, { "name": "srcLabel", // The field name. "type": "string", // The field type. "columnType": "srcPrimaryLabel" // Field category. Specifies the start vertex label, which must be of the STRING type in GDB. }, { "name": "dstId", // The field name. "type": "string", // The field type. "columnType": "dstPrimaryKey" // Field category. Specifies the end vertex primary key, which must be of the STRING type in GDB. }, { "name": "dstLabel", // The field name. "type": "string", // The field type. "columnType": "dstPrimaryLabel" // Field category. Specifies the end vertex label, which must be of the STRING type in GDB. }, { "name": "weight", // The property name. "type": "double", // The property type. "columnType": "edgeProperty" // Field category. Specifies an edge property. } ] }, "stepType":"gdb" }, { "category":"writer", "name":"Writer", "parameter":{ "print": true }, "stepType":"stream" } ] }
Parámetros del script de Reader
|
Parámetro |
Descripción |
Obligatorio |
Valor predeterminado |
|
host |
El endpoint de conexión de la instancia de GDB. En la consola de GDB, haga clic en Management para la instancia de destino y consulte el Internal Endpoint (que corresponde al host). |
Sí |
Ninguno |
|
port |
El puerto utilizado para conectarse a la instancia de GDB. |
Sí |
8182 |
|
username |
El nombre de usuario utilizado para conectarse a la instancia de GDB. |
Sí |
Ninguno |
|
password |
La contraseña utilizada para conectarse a la instancia de GDB. |
Sí |
Ninguna |
|
labels |
La etiqueta (nombre) del vértice o la arista. GDB Reader puede leer datos de varios vértices o aristas a la vez, especificados como un arreglo; por ejemplo, ["label1", "label2"]. |
Sí |
Ninguno |
|
labelType |
El tipo de etiqueta. Valores válidos:
|
Sí |
Ninguno |
|
column |
Los vértices o aristas que se van a sincronizar. |
Sí |
Ninguno |
|
column -> name |
El nombre de la propiedad del vértice o la arista que se va a sincronizar. Es obligatorio si se incluyen propiedades de vértices o aristas. |
Sí |
Ninguno |
|
column -> type |
El tipo de dato de la propiedad del vértice o la arista que se va a sincronizar.
|
Sí |
Ninguno |
|
column -> columnType |
La categoría de la propiedad del vértice o la arista que se va a sincronizar.
|
Sí |
Ninguno |
Ejemplo de script de Writer
-
Configure una tarea de sincronización para escribir datos de vértices en una base de datos de GDB
{ "order":{ "hops":[ { "from":"Reader", "to":"Writer" } ] }, "setting":{ "errorLimit":{ "record":"100" // Maximum number of dirty data records to tolerate. }, "speed":{ "throttle":true,// If true, throttling is enabled. If false, throttling is disabled and the mbps parameter is ignored. "concurrent":3, // The job concurrency. "mbps":"12"// The throttling limit. 1 mbps is equal to 1 MB/s. } }, "steps":[ { "category":"reader", "name":"Reader", "parameter":{ "column":[ "*" ], "datasource":"_ODPS", "emptyAsNull":true, "guid":"", "isCompress":false, "partition":[], "table":"" }, "stepType":"odps" }, { "category":"writer", "name":"Writer", "parameter": { "datasource": "testGDB", // The name of the data source. "label": "person", // The label, which is the name of the vertex. "srcLabel": "", // Not applicable to vertices. "dstLabel": "", // Not applicable to vertices. "labelType": "VERTEX", // The type of the label. "VERTEX" specifies a vertex. "writeMode": "INSERT", // The policy for handling duplicate primary keys. "idTransRule": "labelPrefix", // The conversion rule for the vertex primary key. "srcIdTransRule": "none", // Not applicable to vertices. "dstIdTransRule": "none", // Not applicable to vertices. "column": [ { "name": "id", // The field name. "value": "#{0}", // Takes the value from the source column at index 0. Concatenation is supported. "type": "string", // The field type. "columnType": "primaryKey" // The field category. `primaryKey` specifies the primary key. }, // The primary key of the vertex. The field name must be `id`, the type must be STRING, and this record is required. { "name": "person_age", "value": "#{1}", // Takes the value from the source column at index 1. Concatenation is supported. "type": "int", "columnType": "vertexProperty" // The field category. `vertexProperty` specifies a vertex property. }, // A property of the vertex. Supported types: INT, LONG, FLOAT, DOUBLE, BOOLEAN, and STRING. { "name": "person_credit", "value": "#{2}", // Takes the value from the source column at index 2. Concatenation is supported. "type": "string", "columnType": "vertexProperty" } // A property of the vertex. ] } "stepType":"gdb" } ], "type":"job", "version":"2.0" } -
Configure una tarea de sincronización para escribir datos de aristas en una base de datos de GDB
{ "order":{ "hops":[ { "from":"Reader", "to":"Writer" } ] }, "setting":{ "errorLimit":{ "record":"100" // Maximum number of dirty data records to tolerate. }, "jvmOption":"", "speed":{ "throttle":true,// If true, throttling is enabled. If false, throttling is disabled and the mbps parameter is ignored. "concurrent":3, // The job concurrency. "mbps":"12"// The throttling limit. 1 mbps is equal to 1 MB/s. } }, "steps":[ { "category":"reader", "name":"Reader", "parameter":{ "column":[ "*" ], "datasource":"_ODPS", "emptyAsNull":true, "guid":"", "isCompress":false, "partition":[], "table":"" }, "stepType":"odps" }, { "category":"writer", "name":"Writer", "parameter": { "datasource": "testGDB", // The name of the data source. "label": "use", // The label, which is the name of the edge. "labelType": "EDGE", // The type of the label. `EDGE` specifies an edge. "srcLabel": "person", // The label of the start vertex. "dstLabel": "software", // The label of the end vertex. "writeMode": "INSERT", // The policy for handling duplicate primary keys. "idTransRule": "labelPrefix", // The conversion rule for the edge primary key. "srcIdTransRule": "labelPrefix", // The conversion rule for the primary key of the start vertex. "dstIdTransRule": "labelPrefix", // The conversion rule for the primary key of the end vertex. "column": [ { "name": "id", // The field name. "value": "#{0}", // Takes the value from the source column at index 0. Concatenation is supported. "type": "string", // The field type. "columnType": "primaryKey" // The field category. `primaryKey` specifies the primary key. }, // The primary key of the edge. The field name must be `id` and the type must be STRING. This record is optional. { "name": "id", "value": "#{1}", // Concatenation is supported. Ensure the mapping rule is consistent with the one used when importing vertices. "type": "string", "columnType": "srcPrimaryKey" // The field category. `srcPrimaryKey` specifies the primary key of the start vertex. }, // The primary key of the start vertex. The field name must be `id`, the type must be STRING, and this record is required. { "name": "id", "value": "#{2}", // Concatenation is supported. Ensure the mapping rule is consistent with the one used when importing vertices. "type": "string", "columnType": "dstPrimaryKey" // The field category. `dstPrimaryKey` specifies the primary key of the end vertex. }, // The primary key of the end vertex. The field name must be `id`, the type must be STRING, and this record is required. { "name": "person_use_software_time", "value": "#{3}", // Concatenation is supported. "type": "long", "columnType": "edgeProperty" // The field category. `edgeProperty` specifies an edge property. }, // A property of the edge. Supported types: INT, LONG, FLOAT, DOUBLE, BOOLEAN, and STRING. { "name": "person_regist_software_name", "value": "#{4}", // Concatenation is supported. "type": "string", "columnType": "edgeProperty" }, // A property of the edge. { "name": "id", "value": "#{5}", // Concatenation is supported. "type": "long", "columnType": "edgeProperty" } // A property of the edge with the field name `id`. This is a regular property, not a primary key, and is optional. ] } "stepType":"gdb" } ], "type":"job", "version":"2.0" }
Parámetros del script de Writer
|
Parámetro |
Descripción |
Obligatorio |
Valor predeterminado |
|
datasource |
El nombre del origen de datos. El valor debe coincidir con el nombre del origen de datos que agregó en el editor de código. |
Sí |
Ninguno |
|
label |
La etiqueta, que corresponde al nombre del vértice o la arista. GDB Writer puede obtener etiquetas de las columnas de la tabla de origen. Por ejemplo, si establece este parámetro en #{0}, GDB Writer usa el valor de la primera columna como etiqueta. El índice de columna comienza en 0. |
Sí |
Ninguno |
|
labelType |
El tipo de etiqueta. Valores válidos:
|
Sí |
Ninguno |
|
srcLabel |
|
No |
Ninguno |
|
dstLabel |
|
No |
Ninguno |
|
writeMode |
Indica cómo gestiona GDB Writer los registros de datos con claves principales duplicadas. Valores válidos:
|
Sí |
INSERT |
|
idTransRule |
La regla de conversión para la clave principal. Valores válidos:
|
Sí |
none |
|
srcIdTransRule |
La regla de conversión para la clave principal del vértice de inicio cuando labelType se establece en EDGE. Valores válidos:
|
Obligatorio cuando el parámetro labelType se establece en EDGE |
none |
|
dstIdTransRule |
La regla de conversión para la clave principal del vértice final cuando labelType se establece en EDGE. Valores válidos:
|
Obligatorio cuando el parámetro labelType se establece en EDGE |
none |
|
column |
Los vértices o aristas que se van a sincronizar.
Ejemplo de propiedades
|
Sí |
Ninguno |