1.背景
客户需要excel导入功能,同时支持导入多种数据源,尝试用seatunnel数据集成工具来实现。
2.步骤
2.1 配置文件
./config/v2.excel2mysql.config
env {
# You can set SeaTunnel environment configuration here
execution.parallelism = 1
job.mode = "BATCH"
}
source {
LocalFile {
schema {
fields {
area_id = string
area_name = string
area_age = int
}
}
path = "/data/upload_files/test.xlsx"
file_format_type = "excel"
sheet_name = "Sheet1"
result_table_name = "faker"
parallelism = 1
delimiter = "#"
skip_header_row_number = 1
}
}
transform {
Sql {
source_table_name = "faker"
result_table_name = "faker1"
query = "select area_id, area_name, area_age from faker"
}
}
sink {
# Console {
# source_table_name = "faker1"
# }
Jdbc {
url = "jdbc:mysql://132.151.9.1:3306/test"
driver = "com.mysql.cj.jdbc.Driver"
source_table_name = "faker1"
max_retries = 0
user = "root"
password = "123"
query = "insert into dim_area(area_id, area_name, sort_id) values(?, ?, ?)"
is_exactly_once = "true"
xa_data_source_class_name = "com.mysql.cj.jdbc.MysqlXADataSource"
}
}
2.2 执行
./bin/seatunnel.sh -c ./config/v2.excel2mysql.config -e local
3. 引用
Seatunnel官网
教你完美避坑,从头到尾开发一个 SeaTunnel Connector
jar和sources.jar及javadoc.jar的作用
seatunnel及web安装常见问题与解决方法