Skip to content

Commit

Permalink
[Add][plugin][reader] Add support for Access Database (#931)
Browse files Browse the repository at this point in the history
  • Loading branch information
wgzhao authored Nov 1, 2023
1 parent 576e4e3 commit 6613350
Show file tree
Hide file tree
Showing 13 changed files with 314 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ Addax supports more than 20 SQL and NoSQL [data sources](support_data_sources.md
<td><img src="./docs/images/logos/tdengine.svg" height="50px" alt="TDengine" style="border: 1px solid #ddd;"></td>
<td><img src="./docs/images/logos/trino.svg" height="50px" alt="Trino" style="border: 1px solid #ddd;"></td>
</tr>
<tr>
<td><img src="./docs/images/logos/access.svg" height="50px" alt="Access" style="border: 1px solid #add;"></td>
</tr>
</table>

## Getting Started
Expand Down
3 changes: 3 additions & 0 deletions README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ Addax 支持超过 20 种[关系型和非关系型数据库](support_data_source
<td><img src="./docs/images/logos/tdengine.svg" height="50px" alt="TDengine" style="border: 1px solid #ddd;"></td>
<td><img src="./docs/images/logos/trino.svg" height="50px" alt="Trino" style="border: 1px solid #ddd;"></td>
</tr>
<tr>
<td><img src="./docs/images/logos/access.svg" height="50px" alt="Access" style="border: 1px solid #add;"></td>
</tr>
</table>

## 快速开始
Expand Down
42 changes: 42 additions & 0 deletions docs/assets/jobs/accessreader.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"job": {
"setting": {
"speed": {
"byte": -1,
"channel": 1
}
},
"content": [
{
"reader": {
"name": "accessreader",
"parameter": {
"username": "root",
"password": "",
"column": [
"*"
],
"connection": [
{
"table": [
"tbl_Users"
],
"jdbcUrl": [
"jdbc:ucanaccess:///Users/wgzhao/Downloads/AccessThemeDemo.mdb"
]
}
],
"where": ""
}
},
"writer": {
"name": "streamwriter",
"parameter": {
"encoding": "utf-8",
"print": true
}
}
}
]
}
}
18 changes: 18 additions & 0 deletions docs/images/logos/access.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 32 additions & 0 deletions docs/reader/accessreader.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Access Reader

AccessReader 实现了从 [Access][1] 数据库上读取数据的能力,他基于 [Addax RDBMS Reader][2] 实现。

## 示例

我们下载用于测试用的 [Acess Demo](http://www.databasedev.co.uk/downloads/AccessThemeDemo.zip) 文件,解药后得到 `AccessThemeDemo.mdb` 文件,该文件中包含了一个 `tbl_Users` 表,我们将该表的数据同步到终端上。

下面的配置是读取该表到终端的作业:

=== "job/access2stream.json"

```json
--8<-- "jobs/accessreader.json"
```

将上述配置文件保存为 `job/access2stream.json`

### 执行采集命令

执行以下命令进行数据采集

```shell
bin/addax.sh job/access2stream.json
```

## 参数说明

因本插件基于[Addax RDBMS Reader][2] 实现,所以参数说明请参考 [Addax RDBMS Reader][2]

[1]: https://en.wikipedia.org/wiki/Microsoft_Access
[2]: ../rdbmsreader
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ public enum DataBaseType
TDengine("tdengine", "com.taosdata.jdbc.TSDBDriver"),
Trino("trino", "io.trino.jdbc.TrinoDriver"),
Sybase("sybase", "com.sybase.jdbc4.jdbc.SybDriver"),
Databend("databend", "com.databend.jdbc.DatabendDriver");
Databend("databend", "com.databend.jdbc.DatabendDriver"),
Access("access","net.ucanaccess.jdbc.UcanaccessDriver");

private static final Pattern jdbcUrlPattern = Pattern.compile("jdbc:\\w+:(?:thin:url=|//|thin:@|)([\\w\\d.,]+).*");

Expand Down
8 changes: 8 additions & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@
<outputDirectory>addax-${project.version}/lib</outputDirectory>
</fileSet>
<!-- reader -->
<fileSet>
<directory>plugin/reader/accessreader/target/accessreader-${project.version}/</directory>
<includes>
<include>**/*.*</include>
</includes>
<fileMode>0644</fileMode>
<outputDirectory>addax-${project.version}</outputDirectory>
</fileSet>
<fileSet>
<directory>plugin/reader/cassandrareader/target/cassandrareader-${project.version}/</directory>
<includes>
Expand Down
37 changes: 37 additions & 0 deletions plugin/reader/accessreader/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<assembly
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-component-1.1.2.xsd">
<id>release</id>
<formats>
<format>dir</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>src/main/resources</directory>
<includes>
<include>*.json</include>
</includes>
<outputDirectory>plugin/reader/${project.artifactId}</outputDirectory>
</fileSet>
<fileSet>
<directory>target/</directory>
<includes>
<include>${project.artifactId}-${project.version}.jar</include>
</includes>
<outputDirectory>plugin/reader/${project.artifactId}</outputDirectory>
</fileSet>
</fileSets>

<dependencySets>
<dependencySet>
<useProjectArtifact>false</useProjectArtifact>
<outputDirectory>plugin/reader/${project.artifactId}/libs</outputDirectory>
<scope>runtime</scope>
<excludes>
<exclude>com.wgzhao.addax:*</exclude>
</excludes>
</dependencySet>
</dependencySets>
</assembly>
66 changes: 66 additions & 0 deletions plugin/reader/accessreader/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.wgzhao.addax</groupId>
<artifactId>addax-all</artifactId>
<version>4.1.3-SNAPSHOT</version>
<relativePath>../../../pom.xml</relativePath>
</parent>

<artifactId>accessreader</artifactId>
<name>access-reader</name>
<packaging>jar</packaging>

<dependencies>
<dependency>
<groupId>com.wgzhao.addax</groupId>
<artifactId>addax-common</artifactId>
<version>${project.version}</version>
<exclusions>
<exclusion>
<artifactId>slf4j-log4j12</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>com.wgzhao.addax</groupId>
<artifactId>addax-rdbms</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>net.sf.ucanaccess</groupId>
<artifactId>ucanaccess</artifactId>
<version>5.0.1</version>
</dependency>

</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<descriptor>package.xml</descriptor>
</descriptors>
<finalName>${project.artifactId}-${project.version}</finalName>
</configuration>
<executions>
<execution>
<id>release</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package com.wgzhao.addax.plugin.reader.accessreader;

import com.wgzhao.addax.common.base.Constant;
import com.wgzhao.addax.common.base.Key;
import com.wgzhao.addax.common.plugin.RecordSender;
import com.wgzhao.addax.common.spi.Reader;
import com.wgzhao.addax.common.util.Configuration;
import com.wgzhao.addax.rdbms.reader.CommonRdbmsReader;
import com.wgzhao.addax.rdbms.util.DataBaseType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

public class AccessReader extends Reader {
private static final DataBaseType DATABASE_TYPE = DataBaseType.Access;

public static class Job extends Reader.Job {

private static final Logger LOG = LoggerFactory.getLogger(Job.class);

private Configuration configuration = null;

private CommonRdbmsReader.Job commonRdbmsReaderJob;

@Override
public void init() {
this.configuration = getPluginJobConf();
this.commonRdbmsReaderJob = new CommonRdbmsReader.Job(DATABASE_TYPE);
this.configuration = this.commonRdbmsReaderJob.init(this.configuration);
}

@Override
public void preCheck() {
this.commonRdbmsReaderJob.preCheck(this.configuration, DATABASE_TYPE);
}

@Override
public void destroy() {
this.commonRdbmsReaderJob.destroy(this.configuration);
}

@Override
public List<Configuration> split(int adviceNumber) {
return this.commonRdbmsReaderJob.split(this.configuration, adviceNumber);
}
}

public static class Task extends Reader.Task {

private Configuration configuration = null;
private CommonRdbmsReader.Task commonRdbmsReaderTask;

@Override
public void startRead(RecordSender recordSender) {

int fetchSize = this.configuration.getInt(Key.FETCH_SIZE, Constant.DEFAULT_FETCH_SIZE);
this.commonRdbmsReaderTask.startRead(this.configuration, recordSender, this.getTaskPluginCollector(), fetchSize);
}

@Override
public void init() {
this.configuration = getPluginJobConf();
this.commonRdbmsReaderTask = new CommonRdbmsReader.Task(DATABASE_TYPE, getTaskGroupId(), getTaskId());
this.commonRdbmsReaderTask.init(this.configuration);
}

@Override
public void destroy() {

this.commonRdbmsReaderTask.destroy(this.configuration);

}
}
}
6 changes: 6 additions & 0 deletions plugin/reader/accessreader/src/main/resources/plugin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "accessreader",
"class": "com.wgzhao.addax.plugin.reader.accessreader.AccessReader",
"description": "access reader",
"developer": "wgzhao"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "accessreader",
"parameter": {
"username": "root",
"password": "root",
"column": [
"*"
],
"connection": [
{
"table": [
"addax_reader"
],
"jdbcUrl": [
"jdbc:ucanaccess://<mdb or accdb file path>"
]
}
],
"where": ""
}
}
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
<module>lib/addax-rdbms</module>
<module>lib/addax-storage</module>
<module>lib/addax-transformer</module>
<module>plugin/reader/accessreader</module>
</modules>

<developers>
Expand Down

0 comments on commit 6613350

Please sign in to comment.