mvn clean package -DlibScope=provided -Dmaven.test.skip=true
解压 assembly/target/ 目录下生成可用包 datatunnel-[version].tar.gz。复制所有jar 到 spark_home/jars 在conf/spark-default.conf 添加配置: spark.sql.extensions com.github.melin.datatunnel.core.DataxExtensions
启动 ./bin/spark-sql,可以直接执行如下SQL 语法
-- hive source 支持CTE语法,方便原表数据经过处理过,写入到目标表,其他数据源不支持CTE 语法。
-- 相比 transform 更灵活
WITH t AS (
WITH t2 AS (SELECT 1)
SELECT * FROM t2
)
datatunnel source('数据类型名称') options(键值对参数)
transform(数据加工SQL,可以对数据处理后输出)
sink('数据类型名称') options(键值对参数)| 数据源 | Reader(读) | Writer(写) | 文档 |
|---|---|---|---|
| file | √ | √ | 读写 支持excel, json,csv 文件 |
| sftp | √ | √ | 读写 |
| hdfs | √ | 读 | |
| jdbc | √ | √ | 读写 支持: mysql,oracle,db2,sqlserver,hana,tidb,guass,postgresql |
| tispark | √ | 读 基于TiSpark读取数据 | |
| hive | √ | √ | 读写 |
| hbase | √ | 写 | |
| clickhouse | √ | √ | 读写 基于 spark-clickhouse-connector 项目 |
| elasticsearch | √ | 开发中 | |
| log | √ | 写 | |
| kafka | √ | √ | 读写 spark streaming任务,支持写入jdbc,hudi表 |
| doris | √ | √ | 读写 基于 doris-spark-connector |
| starrocks | √ | √ | 读写 基于 starrocks-spark-connector |
-- support cte
WITH tmp_demo_test2 AS (SELECT * FROM bigdata.test_demo_test2 where name is not null)
datatunnel SOURCE('hive') OPTIONS(
databaseName='bigdata',
tableName='tmp_demo_test2',
columns=['*'])
SINK('log') OPTIONS(numRows = 10)
-- mysql to hive
DATATUNNEL SOURCE("mysql") OPTIONS (
username = "dataworks",
password = "dataworks2021",
host = '10.5.20.20',
port = 3306,
databaseName = 'dataworks',
tableName = 'dc_dtunnel_datasource',
columns = ["*"]
)
SINK("hive") OPTIONS (
databaseName = "bigdata",
tableName = 'hive_dtunnel_datasource',
writeMode = 'overwrite',
columns = ["*"]
);
DATATUNNEL SOURCE('mysql') OPTIONS (
username = 'dataworks',
password = 'dataworks2021',
host = '10.5.20.20',
port = 3306,
resultTableName = 'tdl_dc_job',
databaseName = 'dataworks',
tableName = 'dc_job',
columns = ['*']
)
TRANSFORM = 'select * from tdl_dc_job where type="spark_sql"'
SINK('log') OPTIONS (
numRows = 10
);
DATATUNNEL SOURCE("hive") OPTIONS (
databaseName = 'bigdata',
tableName = 'hive_dtunnel_datasource',
columns = ['id', 'code', 'type', 'description', 'config', 'gmt_created', 'gmt_modified', 'creater', 'modifier']
)
SINK("mysql") OPTIONS (
username = "dataworks",
password = "dataworks2021",
host = '10.5.20.20',
port = 3306,
databaseName = 'dataworks',
tableName = 'dc_datax_datasource_copy1',
writeMode = 'overwrite',
truncate = true,
columns = ['id', 'code', 'dstype', 'description', 'config', 'gmt_created', 'gmt_modified', 'creater', 'modifier']
)