diff --git a/docs/assets/jobs/accesswriter.json b/docs/assets/jobs/accesswriter.json new file mode 100644 index 000000000..a2946f67b --- /dev/null +++ b/docs/assets/jobs/accesswriter.json @@ -0,0 +1,66 @@ +{ + "job": { + "setting": { + "speed": { + "channel": 1, + "bytes": -1 + } + }, + "content": [ + { + "reader": { + "name": "streamreader", + "parameter": { + "column" : [ + { + "value": "Addax", + "type": "string" + }, + { + "value": 19880808, + "type": "long" + }, + { + "value": "1988-08-08 08:08:08", + "type": "date" + }, + { + "value": true, + "type": "bool" + }, + { + "value": "test", + "type": "bytes" + } + ], + "sliceRecordCount": 1000 + } + }, + "writer": { + "name": "accesswriter", + "parameter": { + "username": "wgzhao", + "password": "", + "column": [ + "name", + "file_size", + "file_date", + "file_open", + "memo" + ], + "ddl":"create table tbl_test(name varchar(20), file_size int, file_date date, file_open boolean, memo blob);", + "connection": [ + { + "jdbcUrl": "jdbc:ucanaccess:////Users/wgzhao/Downloads/AccessThemeDemo.mdb", + "table": [ + "tbl_test" + ] + } + ] + } + } + } + ] + } +} + diff --git a/docs/writer/accesswriter.md b/docs/writer/accesswriter.md new file mode 100644 index 000000000..6c6096cf8 --- /dev/null +++ b/docs/writer/accesswriter.md @@ -0,0 +1,36 @@ +# Access Writer + +AccessWriter 插件实现了写入数据到 [Access][1] 目的表的功能。 + +## 示例 + +假定要写入的 Access 表建表语句如下: + +```sql +create table tbl_test(name varchar(20), file_size int, file_date date, file_open boolean, memo blob); +``` + +这里使用一份从内存产生到 Access 导入的数据。 + +=== "job/stream2access.json" + + ```json + --8<-- "jobs/accesswriter.json" + ``` + +将上述配置文件保存为 `job/stream2access.json` + +### 执行采集命令 + +执行以下命令进行数据采集 + +```shell +bin/addax.sh job/stream2access.json +``` + +## 参数说明 + +因本插件基于[Addax RDBMS Writer][2] 实现,所以参数说明请参考 [Addax RDBMS Writer][2]。 + +[1]: https://en.wikipedia.org/wiki/Microsoft_Access +[2]: ../rdbmswriter \ No newline at end of file diff --git a/mkdocs.yml b/mkdocs.yml index e8b83ea37..c0fbd14da 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -75,6 +75,7 @@ nav: - reader/txtfilereader.md - 写入插件: + - writer/accesswriter.md - writer/cassandrawriter.md - writer/clickhousewriter.md - writer/dbfwriter.md diff --git a/package.xml b/package.xml index d38474bc7..e7d922080 100644 --- a/package.xml +++ b/package.xml @@ -322,6 +322,14 @@ + + plugin/writer/accesswriter/target/accesswriter-${project.version}/ + + **/*.* + + 0644 + addax-${project.version} + plugin/writer/cassandrawriter/target/cassandrawriter-${project.version}/ diff --git a/plugin/writer/accesswriter/package.xml b/plugin/writer/accesswriter/package.xml new file mode 100644 index 000000000..8ecab9f9f --- /dev/null +++ b/plugin/writer/accesswriter/package.xml @@ -0,0 +1,37 @@ + + release + + dir + + false + + + src/main/resources + + *.json + + plugin/writer/${project.artifactId} + + + target/ + + ${project.artifactId}-${project.version}.jar + + plugin/writer/${project.artifactId} + + + + + + false + plugin/writer/${project.artifactId}/libs + runtime + + com.wgzhao.addax:* + + + + diff --git a/plugin/writer/accesswriter/pom.xml b/plugin/writer/accesswriter/pom.xml new file mode 100644 index 000000000..a1569a520 --- /dev/null +++ b/plugin/writer/accesswriter/pom.xml @@ -0,0 +1,53 @@ + + 4.0.0 + + com.wgzhao.addax + addax-all + 4.1.3-SNAPSHOT + ../../../pom.xml + + accesswriter + access-writer + + + + com.wgzhao.addax + addax-common + ${project.version} + + + com.wgzhao.addax + addax-rdbms + ${project.version} + + + net.sf.ucanaccess + ucanaccess + 5.0.1 + + + + + + + maven-assembly-plugin + + + package.xml + + ${project.artifactId}-${project.version} + + + + release + package + + single + + + + + + + diff --git a/plugin/writer/accesswriter/src/main/java/com/wgzhao/addax/plugin/writer/accesswriter/AccessWriter.java b/plugin/writer/accesswriter/src/main/java/com/wgzhao/addax/plugin/writer/accesswriter/AccessWriter.java new file mode 100644 index 000000000..88616be45 --- /dev/null +++ b/plugin/writer/accesswriter/src/main/java/com/wgzhao/addax/plugin/writer/accesswriter/AccessWriter.java @@ -0,0 +1,86 @@ +package com.wgzhao.addax.plugin.writer.accesswriter; + + +import com.wgzhao.addax.common.plugin.RecordReceiver; +import com.wgzhao.addax.common.spi.Writer; +import com.wgzhao.addax.common.util.Configuration; +import com.wgzhao.addax.rdbms.util.DataBaseType; +import com.wgzhao.addax.rdbms.writer.CommonRdbmsWriter; + +import java.util.List; + +public class AccessWriter extends Writer { + + private static final DataBaseType DATABASE_TYPE = DataBaseType.Access; + + public static class Job extends Writer.Job { + + private Configuration originalConfig = null; + + private CommonRdbmsWriter.Job commonRdbmsWriterJob = null; + @Override + public void init() { + this.originalConfig = getPluginJobConf(); + this.commonRdbmsWriterJob = new CommonRdbmsWriter.Job(DATABASE_TYPE); + this.commonRdbmsWriterJob.init(this.originalConfig); + } + + @Override + public void preCheck() { + this.commonRdbmsWriterJob.writerPreCheck(this.originalConfig, DATABASE_TYPE); + } + @Override + public void prepare() { + this.commonRdbmsWriterJob.prepare(this.originalConfig); + } + + @Override + public void post() { + this.commonRdbmsWriterJob.post(this.originalConfig); + } + + @Override + public void destroy() { + this.commonRdbmsWriterJob.destroy(this.originalConfig); + } + + @Override + public List split(int mandatoryNumber) { + return this.commonRdbmsWriterJob.split(this.originalConfig, mandatoryNumber); + } + } + + public static class Task extends Writer.Task { + + private Configuration configuration; + + private CommonRdbmsWriter.Task commonRdbmsWriterTask; + + @Override + public void init() { + this.configuration = super.getPluginJobConf(); + this.commonRdbmsWriterTask = new CommonRdbmsWriter.Task(DATABASE_TYPE); + this.commonRdbmsWriterTask.init(this.configuration); + } + + @Override + public void prepare() { + this.commonRdbmsWriterTask.prepare(this.configuration); + } + + @Override + public void startWrite(RecordReceiver lineReceiver) { + this.commonRdbmsWriterTask.startWrite(lineReceiver, this.configuration, super.getTaskPluginCollector()); + } + + @Override + public void post() { + this.commonRdbmsWriterTask.post(configuration); + } + + @Override + public void destroy() { + this.commonRdbmsWriterTask.destroy(configuration); + } + } +} diff --git a/plugin/writer/accesswriter/src/main/resources/plugin.json b/plugin/writer/accesswriter/src/main/resources/plugin.json new file mode 100644 index 000000000..0e5435934 --- /dev/null +++ b/plugin/writer/accesswriter/src/main/resources/plugin.json @@ -0,0 +1,6 @@ +{ + "name": "accesswriter", + "class": "com.wgzhao.addax.plugin.writer.accesswriter.AccessWriter", + "description": "writer to access database", + "developer": "wgzhao" +} \ No newline at end of file diff --git a/plugin/writer/accesswriter/src/main/resources/plugin_job_template.json b/plugin/writer/accesswriter/src/main/resources/plugin_job_template.json new file mode 100644 index 000000000..bc02ae8a3 --- /dev/null +++ b/plugin/writer/accesswriter/src/main/resources/plugin_job_template.json @@ -0,0 +1,22 @@ +{ + "name": "accesswriter", + "parameter": { + "writeMode": "insert", + "username": "root", + "password": "", + "column": [ + "*" + ], + "preSql": [ + "delete from @table" + ], + "connection": [ + { + "jdbcUrl": "jdbc:ucanaccess://", + "table": [ + "addax_tbl" + ] + } + ] + } +} \ No newline at end of file diff --git a/pom.xml b/pom.xml index 45ec4e74f..b217590b8 100644 --- a/pom.xml +++ b/pom.xml @@ -127,7 +127,6 @@ lib/addax-rdbms lib/addax-storage lib/addax-transformer - plugin/reader/accessreader @@ -394,6 +393,7 @@ + plugin/reader/accessreader plugin/reader/cassandrareader plugin/reader/clickhousereader plugin/reader/databendreader @@ -429,6 +429,7 @@ plugin/reader/txtfilereader + plugin/writer/accesswriter plugin/writer/cassandrawriter plugin/writer/clickhousewriter plugin/writer/dbfwriter diff --git a/support_data_sources.md b/support_data_sources.md index fd5560385..c367c37f3 100644 --- a/support_data_sources.md +++ b/support_data_sources.md @@ -2,7 +2,7 @@ | database/filesystem | read | write | plugin(reader/writer) | memo | |---------------------|------|-------|-----------------------------------------|---------------------------------| -| Access | ✓ | x | accessreader | suuport [Access][9] | +| Access | ✓ | ✓ | accessreader/accesswriter | suuport [Access][9] | | Cassandra | ✓ | ✓ | cassandrareader/cassandrawriter | | | ClickHouse | ✓ | ✓ | clickhousereader/clickhousewriter | | | Databend | ✓ | ✓ | databendreader/databendwriter | support [Databend][8] | @@ -39,11 +39,19 @@ | TEXT | ✓ | ✓ | textfilereader/textfilewriter | | [1]: https://github.com/Kestrong/datax-elasticsearch + [2]: https://phoenix.apache.org + [3]: https://trino.io + [4]: https://www.taosdata.com/cn/ + [5]: http://transwarp.cn/ + [6]: https://aws.amazon.com/s3 + [7]: https://min.io/ + [8]: https://databend.rs + [9]: https://en.wikipedia.org/wiki/Microsoft_Access