Assistant Engineer
Assistant Engineer
  • UID622
  • Fans3
  • Follows0
  • Posts52

[Others]Programming Guide for DataX Plugin

More Posted time:Sep 13, 2016 16:23 PM
DataX is the tool/platform for offline data synchronization widely used in Alibaba Group to realize efficient synchronization functions among various heterogeneous data sources, including MySQL, Oracle, HDFS, Hive, OceanBase, HBase, OTS, ODPS, etc. DataX adopts framework + plug-in mode and is open-source, with the code hosted on Github.

Address of hosted code:
For development of plug-ins, see:

New modules
First, clone code from https://github.com/alibaba/DataX, and execute the following command:
mvn clean package -DskipTests assembly:assembly

mvn clean package -DskipTests assembly:assembly
The command will generate datax.tar.gz. We can deploy the generated file to the corresponding environment for data import and export.
After development and testing, we can use the command above to integrate our plug-ins into DataX.

Then, import the code to Eclispe (or other IDE), and create a new Maven module under the project.
Next, make some configurations and then it is ready for development.

DataX uses Maven to manage projects, and plug-ins and frameworks are organized together through multiple modules. All modules are packaged with maven-assembly-plugin.
The configuration can be conducted from two aspects during development
1. The module configuration: directory and files should comply with the protocol
2. The configuration of DataX main modules: 2 files should be configured: ./pom.xml and ./package.xml
Plug-in configurations:
The results of source code shall meet the requirements of the following architecture upon the establishment of one plug-in module:

POM configurations:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">





1. The dependence on datax-common is added and it depends on the frame of DataX,
2. The maven-assembly-plugin is configured and src/main/assembly/package.xml is applied here. The package.xml defines the directory structure after the package, and the results of this directory is agreed on by DataX. Details are given below:
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">


Besides two .xml files above, two additional .json files are required.
The plugin.json is a description of the plug-in. In the framework, this file is used to load the plug-in, for example:
    "name": "qvxfilereader",
    "class": "com.alibaba.datax.plugin.reader.qvxfilereader.QvxFileReader",
    "description": "useScene: test. mechanism: use datax framework to transport data from qvx file. warn: The more you know about the data, the less problems you encounter.",
    "developer": "dtstack.com"

plugin_job_template.json: The plug-in configuration module. During the use of plug-ins, users make configurations according to the template. For example,
    "name": "qvxfilereader",
    "parameter": {
        "path": [],
        "fieldDelimiter": ""

Configurations of DataX main modules
In pom.xml, add the module name of the plug-in. The module name is artifactId.

Add the package content of this plug-in in package.xml, so that DataX can include the plug-in into the entire plug-in system.







Below is the pseudocode on how plug-ins write data into channel through RecordSender:
public void startRead(RecordSender recordSender) {
Record record=recordSender.createRecord();
record.addColumn(new LongColumn(1));
record.addColumn(new StringColumn("hello,world!"));

When development is completed, the following command can be executed to generate DataX:
mvn clean package -DskipTests assembly:assembly

and then testing can be conducted.
Because each execution of this command will re-compile and re-package all the plug-ins in the DataX, the speed will be relatively slow. So you can modify the pom.xml and package.xml in Data X to keep only the common and in-development plug-ins.