Skip to content

yogboot/datatunnel

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

238 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

发布打包

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

datatunnel sql 语法

启动 ./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

example

-- 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']
)

参考

  1. Bucket4j 限流库
  2. https://github.com/housepower/spark-clickhouse-connector
  3. https://github.com/apache/incubator-seatunnel
  4. https://www.oudeis.co/blog/2020/spark-jdbc-throttling-writes/

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Java 47.5%
  • Scala 27.8%
  • ANTLR 24.7%