embulk-output-jdbc 0.6.5 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1e7b878973e6e97c5149c469886b1d11c9efc8d9
|
4
|
+
data.tar.gz: 3af9509130f455d733b78de7d0805907d259bdc2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 586210422b7503a9921dcf879ab13b2fd6691521cddb5afb37ef51349c844173f6ac4b6506b048e8f01d08f4f172724341b4e6a40097c8c508b8f17119248659
|
7
|
+
data.tar.gz: cf113f39192e5ec7dbba13c33947c1095dcf03c1297a0fbfebc251c219725a4a8ffc0580551d2001ff45cf3ea865e62faa5af133a5baa2dae70f7cd109d4ce84
|
data/README.md
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
# Generic JDBC output plugin for Embulk
|
2
|
+
|
3
|
+
Generic JDBC output plugin for Embulk loads records to a database using a JDBC driver. If the database follows ANSI SQL standards and JDBC standards strictly, this plugin works. But because of many incompatibilities, use case of this plugin is very limited. It's recommended to use specific plugins for the databases.
|
4
|
+
|
5
|
+
## Overview
|
6
|
+
|
7
|
+
* **Plugin type**: output
|
8
|
+
* **Load all or nothing**: depends on the mode. see below.
|
9
|
+
* **Resume supported**: depends on the mode. see below.
|
10
|
+
|
11
|
+
## Configuration
|
12
|
+
|
13
|
+
- **driver_path**: path to the jar file of the JDBC driver (e.g. 'sqlite-jdbc-3.8.7.jar') (string, optional)
|
14
|
+
- **driver_class**: class name of the JDBC driver (e.g. 'org.sqlite.JDBC') (string, required)
|
15
|
+
- **url**: URL of the JDBC connection (e.g. 'jdbc:sqlite:mydb.sqlite3') (string, required)
|
16
|
+
- **user**: database login user name (string, optional)
|
17
|
+
- **password**: database login password (string, optional)
|
18
|
+
- **schema**: destination schema name (string, default: use default schema)
|
19
|
+
- **table**: destination table name (string, required)
|
20
|
+
- **options**: extra JDBC properties (hash, default: {})
|
21
|
+
- **retry_limit** max retry count for database operations (integer, default: 12)
|
22
|
+
- **retry_wait** initial retry wait time in milliseconds (integer, default: 1000 (1 second))
|
23
|
+
- **max_retry_wait** upper limit of retry wait, which will be doubled at every retry (integer, default: 1800000 (30 minutes))
|
24
|
+
- **mode**: "insert", "insert_direct", "truncate_insert", or "replace". See below (string, required)
|
25
|
+
- **batch_size**: size of a single batch insert (integer, default: 16777216)
|
26
|
+
- **max_table_name_length**: maximum length of table name in this RDBMS (integer, default: 256)
|
27
|
+
- **default_timezone**: If input column type (embulk type) is timestamp, this plugin needs to format the timestamp into a SQL string. This default_timezone option is used to control the timezone. You can overwrite timezone for each columns using column_options option. (string, default: `UTC`)
|
28
|
+
- **column_options**: advanced: a key-value pairs where key is a column name and value is options for the column.
|
29
|
+
- **type**: type of a column when this plugin creates new tables (e.g. `VARCHAR(255)`, `INTEGER NOT NULL UNIQUE`). This used when this plugin creates intermediate tables (insert and truncate_insert modes), when it creates the target table (replace mode), and when it creates nonexistent target table automatically. (string, default: depends on input column type. `BIGINT` if input column type is long, `BOOLEAN` if boolean, `DOUBLE PRECISION` if double, `CLOB` if string, `TIMESTAMP` if timestamp)
|
30
|
+
- **value_type**: This plugin converts input column type (embulk type) into a database type to build a INSERT statement. This value_type option controls the type of the value in a INSERT statement. (string, default: depends on the sql type of the column. Available values options are: `byte`, `short`, `int`, `long`, `double`, `float`, `boolean`, `string`, `nstring`, `date`, `time`, `timestamp`, `decimal`, `json`, `null`, `pass`)
|
31
|
+
- **timestamp_format**: If input column type (embulk type) is timestamp and value_type is `string` or `nstring`, this plugin needs to format the timestamp value into a string. This timestamp_format option is used to control the format of the timestamp. (string, default: `%Y-%m-%d %H:%M:%S.%6N`)
|
32
|
+
- **timezone**: If input column type (embulk type) is timestamp, this plugin needs to format the timestamp value into a SQL string. In this cases, this timezone option is used to control the timezone. (string, value of default_timezone option is used by default)
|
33
|
+
|
34
|
+
## Modes
|
35
|
+
|
36
|
+
* **insert**:
|
37
|
+
* Behavior: This mode writes rows to some intermediate tables first. If all those tasks run correctly, runs `INSERT INTO <target_table> SELECT * FROM <intermediate_table_1> UNION ALL SELECT * FROM <intermediate_table_2> UNION ALL ...` query. If the target table doesn't exist, it is created automatically.
|
38
|
+
* Transactional: Yes. This mode successfully writes all rows, or fails with writing zero rows.
|
39
|
+
* Resumable: Yes.
|
40
|
+
* **insert_direct**:
|
41
|
+
* Behavior: This mode inserts rows to the target table directly. If the target table doesn't exist, it is created automatically.
|
42
|
+
* Transactional: No. If fails, the target table could have some rows inserted.
|
43
|
+
* Resumable: No.
|
44
|
+
* **truncate_insert**:
|
45
|
+
* Behavior: Same with `insert` mode excepting that it truncates the target table right before the last `INSERT ...` query.
|
46
|
+
* Transactional: Yes.
|
47
|
+
* Resumable: Yes.
|
48
|
+
* **replace**:
|
49
|
+
* Behavior: This mode writes rows to an intermediate table first. If all those tasks run correctly, drops the target table and alters the name of the intermediate table into the target table name.
|
50
|
+
* Transactional: No. If fails, the target table could be dropped.
|
51
|
+
* Resumable: No.
|
52
|
+
* **merge**:
|
53
|
+
* Behavior: This mode writes rows to some intermediate tables first. If all those tasks run correctly, merges the intermediate tables into the target table. Namely, if primary keys of a record in the intermediate tables already exist in the target table, the target record is updated by the intermediate record, otherwise the intermediate record is inserted. If the target table doesn't exist, it is created automatically.
|
54
|
+
* Transactional: Yes.
|
55
|
+
* Resumable: Yes.
|
56
|
+
* **merge_direct**:
|
57
|
+
* Behavior: This mode merges rows to the target table directly. Namely, if primary keys of an input record already exist in the target table, the target record is updated by the input record, otherwise the input record is inserted. If the target table doesn't exist, it is created automatically.
|
58
|
+
* Transactional: No.
|
59
|
+
* Resumable: No.
|
60
|
+
|
61
|
+
## Example
|
62
|
+
|
63
|
+
```yaml
|
64
|
+
out:
|
65
|
+
type: jdbc
|
66
|
+
driver_path: /usr/local/nz/lib/nzjdbc3.jar
|
67
|
+
driver_class: org.netezza.Driver
|
68
|
+
url: jdbc:jdbc:netezza://127.0.0.1:5480/mydb
|
69
|
+
user: myuser
|
70
|
+
password: "mypassword"
|
71
|
+
table: my_table
|
72
|
+
mode: insert
|
73
|
+
```
|
74
|
+
|
75
|
+
Advanced configuration:
|
76
|
+
|
77
|
+
```yaml
|
78
|
+
out:
|
79
|
+
type: jdbc
|
80
|
+
driver_path: /usr/local/nz/lib/nzjdbc3.jar
|
81
|
+
driver_class: org.netezza.Driver
|
82
|
+
url: jdbc:jdbc:netezza://127.0.0.1:5480/mydb
|
83
|
+
user: myuser
|
84
|
+
password: "mypassword"
|
85
|
+
table: my_table
|
86
|
+
options: {loglevel: 2}
|
87
|
+
mode: insert_direct
|
88
|
+
column_options:
|
89
|
+
my_col_1: {type: 'VARCHAR(255)'}
|
90
|
+
my_col_3: {type: 'INT NOT NULL'}
|
91
|
+
my_col_4: {value_type: string, timestamp_format: `%Y-%m-%d %H:%M:%S %z`, timezone: '-0700'}
|
92
|
+
my_col_5: {type: 'DECIMAL(18,9)', value_type: pass}
|
93
|
+
```
|
94
|
+
|
95
|
+
## Build
|
96
|
+
|
97
|
+
```
|
98
|
+
$ ./gradlew gem
|
99
|
+
```
|
Binary file
|
@@ -1,6 +1,9 @@
|
|
1
1
|
package org.embulk.output;
|
2
2
|
|
3
3
|
import java.io.File;
|
4
|
+
import java.io.FileInputStream;
|
5
|
+
import java.io.IOException;
|
6
|
+
import java.io.InputStreamReader;
|
4
7
|
import java.net.URISyntaxException;
|
5
8
|
import java.nio.charset.Charset;
|
6
9
|
import java.sql.Connection;
|
@@ -11,17 +14,115 @@ import java.util.ArrayList;
|
|
11
14
|
import java.util.Collections;
|
12
15
|
import java.util.Comparator;
|
13
16
|
import java.util.List;
|
17
|
+
import java.util.Map;
|
14
18
|
import java.util.regex.Matcher;
|
15
19
|
import java.util.regex.Pattern;
|
16
20
|
|
21
|
+
import org.embulk.config.ConfigException;
|
22
|
+
import org.embulk.output.jdbc.AbstractJdbcOutputPlugin;
|
17
23
|
import org.embulk.output.tester.EmbulkPluginTester;
|
24
|
+
import org.embulk.output.tester.EmbulkPluginTester.PluginDefinition;
|
25
|
+
import org.yaml.snakeyaml.Yaml;
|
18
26
|
|
19
27
|
import com.google.common.io.Files;
|
20
28
|
|
29
|
+
import static java.util.Locale.ENGLISH;
|
30
|
+
|
21
31
|
public abstract class AbstractJdbcOutputPluginTest
|
22
32
|
{
|
23
|
-
|
24
|
-
|
33
|
+
private static final String CONFIG_FILE_NAME = "tests.yml";
|
34
|
+
|
35
|
+
protected boolean enabled;
|
36
|
+
// TODO:destroy EmbulkPluginTester after test
|
37
|
+
protected EmbulkPluginTester tester = new EmbulkPluginTester();
|
38
|
+
private String pluginName;
|
39
|
+
private Map<String, ?> testConfigurations;
|
40
|
+
|
41
|
+
protected AbstractJdbcOutputPluginTest()
|
42
|
+
{
|
43
|
+
try {
|
44
|
+
prepare();
|
45
|
+
} catch (SQLException e) {
|
46
|
+
throw new RuntimeException(e);
|
47
|
+
}
|
48
|
+
}
|
49
|
+
|
50
|
+
protected abstract void prepare() throws SQLException;
|
51
|
+
|
52
|
+
|
53
|
+
private Map<String, ?> getTestConfigs()
|
54
|
+
{
|
55
|
+
if (testConfigurations == null) {
|
56
|
+
for (PluginDefinition pluginDefinition : tester.getPlugins()) {
|
57
|
+
if (AbstractJdbcOutputPlugin.class.isAssignableFrom(pluginDefinition.impl)) {
|
58
|
+
pluginName = pluginDefinition.name;
|
59
|
+
break;
|
60
|
+
}
|
61
|
+
}
|
62
|
+
|
63
|
+
Yaml yaml = new Yaml();
|
64
|
+
File configFile = new File(CONFIG_FILE_NAME);
|
65
|
+
if (!configFile.exists()) {
|
66
|
+
configFile = new File("../" + CONFIG_FILE_NAME);
|
67
|
+
if (!configFile.exists()) {
|
68
|
+
throw new ConfigException(String.format(ENGLISH, "\"%s\" doesn't exist.",
|
69
|
+
CONFIG_FILE_NAME));
|
70
|
+
}
|
71
|
+
}
|
72
|
+
|
73
|
+
try {
|
74
|
+
InputStreamReader reader = new InputStreamReader(new FileInputStream(configFile), Charset.forName("UTF8"));
|
75
|
+
try {
|
76
|
+
Map<String, ?> allTestConfigs = (Map<String, ?>)yaml.load(reader);
|
77
|
+
if (!allTestConfigs.containsKey(pluginName)) {
|
78
|
+
throw new ConfigException(String.format(ENGLISH, "\"%s\" doesn't contain \"%s\" element.",
|
79
|
+
CONFIG_FILE_NAME, pluginName));
|
80
|
+
}
|
81
|
+
testConfigurations = (Map<String, ?>)allTestConfigs.get(pluginName);
|
82
|
+
} finally {
|
83
|
+
reader.close();
|
84
|
+
}
|
85
|
+
} catch (IOException e) {
|
86
|
+
throw new RuntimeException(e);
|
87
|
+
}
|
88
|
+
}
|
89
|
+
return testConfigurations;
|
90
|
+
}
|
91
|
+
|
92
|
+
private Object getTestConfig(String name)
|
93
|
+
{
|
94
|
+
Map<String, ?> testConfigs = getTestConfigs();
|
95
|
+
if (!testConfigs.containsKey(name)) {
|
96
|
+
throw new ConfigException(String.format(ENGLISH, "\"%s\" element in \"%s\" doesn't contain \"%s\" element.",
|
97
|
+
pluginName, CONFIG_FILE_NAME, name));
|
98
|
+
}
|
99
|
+
return testConfigs.get(name);
|
100
|
+
}
|
101
|
+
|
102
|
+
protected String getHost()
|
103
|
+
{
|
104
|
+
return (String)getTestConfig("host");
|
105
|
+
}
|
106
|
+
|
107
|
+
protected int getPort()
|
108
|
+
{
|
109
|
+
return (Integer)getTestConfig("port");
|
110
|
+
}
|
111
|
+
|
112
|
+
protected String getUser()
|
113
|
+
{
|
114
|
+
return (String)getTestConfig("user");
|
115
|
+
}
|
116
|
+
|
117
|
+
protected String getPassword()
|
118
|
+
{
|
119
|
+
return (String)getTestConfig("password");
|
120
|
+
}
|
121
|
+
|
122
|
+
protected String getDatabase()
|
123
|
+
{
|
124
|
+
return (String)getTestConfig("database");
|
125
|
+
}
|
25
126
|
|
26
127
|
protected void dropTable(String table) throws SQLException
|
27
128
|
{
|
@@ -122,6 +223,11 @@ public abstract class AbstractJdbcOutputPluginTest
|
|
122
223
|
|
123
224
|
protected String convertYmlLine(String line)
|
124
225
|
{
|
226
|
+
line = line.replaceAll("#host#", getHost());
|
227
|
+
line = line.replaceAll("#port#", Integer.toString(getPort()));
|
228
|
+
line = line.replaceAll("#database#", getDatabase());
|
229
|
+
line = line.replaceAll("#user#", getUser());
|
230
|
+
line = line.replaceAll("#password#", getPassword());
|
125
231
|
return line;
|
126
232
|
}
|
127
233
|
|
@@ -13,7 +13,7 @@ import com.google.inject.Module;
|
|
13
13
|
|
14
14
|
public class EmbulkPluginTester
|
15
15
|
{
|
16
|
-
|
16
|
+
public static class PluginDefinition
|
17
17
|
{
|
18
18
|
public final Class<?> iface;
|
19
19
|
public final String name;
|
@@ -47,6 +47,11 @@ public class EmbulkPluginTester
|
|
47
47
|
plugins.add(new PluginDefinition(iface, name, impl));
|
48
48
|
}
|
49
49
|
|
50
|
+
public List<PluginDefinition> getPlugins()
|
51
|
+
{
|
52
|
+
return plugins;
|
53
|
+
}
|
54
|
+
|
50
55
|
public void run(String yml) throws Exception
|
51
56
|
{
|
52
57
|
if (embulk == null) {
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: embulk-output-jdbc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sadayuki Furuhashi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-10-
|
11
|
+
date: 2016-10-26 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Inserts or updates records to a table.
|
14
14
|
email:
|
@@ -17,8 +17,9 @@ executables: []
|
|
17
17
|
extensions: []
|
18
18
|
extra_rdoc_files: []
|
19
19
|
files:
|
20
|
+
- README.md
|
20
21
|
- build.gradle
|
21
|
-
- classpath/embulk-output-jdbc-0.
|
22
|
+
- classpath/embulk-output-jdbc-0.7.0.jar
|
22
23
|
- lib/embulk/output/jdbc.rb
|
23
24
|
- src/main/java/org/embulk/output/JdbcOutputPlugin.java
|
24
25
|
- src/main/java/org/embulk/output/jdbc/AbstractJdbcOutputPlugin.java
|