embulk-output-mysql 0.6.1 → 0.6.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -2
- data/classpath/embulk-output-jdbc-0.6.2.jar +0 -0
- data/classpath/embulk-output-mysql-0.6.2.jar +0 -0
- data/src/main/java/org/embulk/output/MySQLOutputPlugin.java +17 -3
- data/src/main/java/org/embulk/output/mysql/MySQLBatchInsert.java +3 -2
- data/src/main/java/org/embulk/output/mysql/MySQLOutputConnection.java +37 -15
- metadata +4 -4
- data/classpath/embulk-output-jdbc-0.6.1.jar +0 -0
- data/classpath/embulk-output-mysql-0.6.1.jar +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 069acac0c6d408b6e2c2b4c4e95a1fec7a38be4c
|
4
|
+
data.tar.gz: 4235adc1b6848f48e3f22e0d97098508c5ffa929
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 54f83241c5c37fa5998d91e60b7c1cd2f1534a86a0ecddc58889093656477989bf28ca51124e744953687de867716903df259ca5dbd80e3146c869ef2ad728de
|
7
|
+
data.tar.gz: 3ee5327bd2930e5e17a8ee5ea3df9234afe58166be2e59c997943eeae11aed07be136d936b19215404dcb04dfefcf8babf81656731c773e214eab9cf59e56c37
|
data/README.md
CHANGED
@@ -5,8 +5,8 @@ MySQL output plugins for Embulk loads records to MySQL.
|
|
5
5
|
## Overview
|
6
6
|
|
7
7
|
* **Plugin type**: output
|
8
|
-
* **Load all or nothing**:
|
9
|
-
* **Resume supported**:
|
8
|
+
* **Load all or nothing**: depends on the mode. see below.
|
9
|
+
* **Resume supported**: depends on the mode. see below.
|
10
10
|
|
11
11
|
## Configuration
|
12
12
|
|
@@ -17,7 +17,11 @@ MySQL output plugins for Embulk loads records to MySQL.
|
|
17
17
|
- **database**: destination database name (string, required)
|
18
18
|
- **table**: destination table name (string, required)
|
19
19
|
- **options**: extra connection properties (hash, default: {})
|
20
|
+
- **retry_limit** max retry count for database operations (integer, default: 12)
|
21
|
+
- **retry_wait** initial retry wait time in milliseconds (integer, default: 1000 (1 second))
|
22
|
+
- **max_retry_wait** upper limit of retry wait, which will be doubled at every retry (integer, default: 1800000 (30 minutes))
|
20
23
|
- **mode**: "insert", "insert_direct", "truncate_insert", "merge", "merge_direct", or "replace". See below. (string, required)
|
24
|
+
- **merge_rule**: list of column assignments for updating existing records used in merge and merge_direct modes, for example `foo = target_table.foo + VALUES(foo)` in case of merge mode, or `foo = foo + VALUES(foo)` in case of merge_direct mode. (string array, default: always overwrites with new values)
|
21
25
|
- **batch_size**: size of a single batch insert (integer, default: 16777216)
|
22
26
|
- **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`)
|
23
27
|
- **column_options**: advanced: a key-value pairs where key is a column name and value is options for the column.
|
Binary file
|
Binary file
|
@@ -1,6 +1,5 @@
|
|
1
1
|
package org.embulk.output;
|
2
2
|
|
3
|
-
import java.util.List;
|
4
3
|
import java.util.Properties;
|
5
4
|
import java.io.IOException;
|
6
5
|
import java.sql.SQLException;
|
@@ -9,6 +8,7 @@ import org.embulk.config.Config;
|
|
9
8
|
import org.embulk.config.ConfigDefault;
|
10
9
|
import org.embulk.output.jdbc.AbstractJdbcOutputPlugin;
|
11
10
|
import org.embulk.output.jdbc.BatchInsert;
|
11
|
+
import org.embulk.output.jdbc.MergeConfig;
|
12
12
|
import org.embulk.output.mysql.MySQLOutputConnector;
|
13
13
|
import org.embulk.output.mysql.MySQLBatchInsert;
|
14
14
|
|
@@ -104,8 +104,22 @@ public class MySQLOutputPlugin
|
|
104
104
|
}
|
105
105
|
|
106
106
|
@Override
|
107
|
-
protected BatchInsert newBatchInsert(PluginTask task, Optional<
|
107
|
+
protected BatchInsert newBatchInsert(PluginTask task, Optional<MergeConfig> mergeConfig) throws IOException, SQLException
|
108
108
|
{
|
109
|
-
return new MySQLBatchInsert(getConnector(task, true),
|
109
|
+
return new MySQLBatchInsert(getConnector(task, true), mergeConfig);
|
110
|
+
}
|
111
|
+
|
112
|
+
|
113
|
+
@Override
|
114
|
+
protected boolean isRetryableException(String sqlState, int errorCode)
|
115
|
+
{
|
116
|
+
switch (errorCode) {
|
117
|
+
case 1213: // ER_LOCK_DEADLOCK (Message: Deadlock found when trying to get lock; try restarting transaction)
|
118
|
+
return true;
|
119
|
+
case 1205: // ER_LOCK_WAIT_TIMEOUT (Message: Lock wait timeout exceeded; try restarting transaction)
|
120
|
+
return true;
|
121
|
+
default:
|
122
|
+
return false;
|
123
|
+
}
|
110
124
|
}
|
111
125
|
}
|
@@ -5,14 +5,15 @@ import java.io.IOException;
|
|
5
5
|
import java.sql.Types;
|
6
6
|
import java.sql.SQLException;
|
7
7
|
import com.google.common.base.Optional;
|
8
|
+
import org.embulk.output.jdbc.MergeConfig;
|
8
9
|
import org.embulk.output.jdbc.StandardBatchInsert;
|
9
10
|
|
10
11
|
public class MySQLBatchInsert
|
11
12
|
extends StandardBatchInsert
|
12
13
|
{
|
13
|
-
public MySQLBatchInsert(MySQLOutputConnector connector, Optional<
|
14
|
+
public MySQLBatchInsert(MySQLOutputConnector connector, Optional<MergeConfig> mergeConfig) throws IOException, SQLException
|
14
15
|
{
|
15
|
-
super(connector,
|
16
|
+
super(connector, mergeConfig);
|
16
17
|
}
|
17
18
|
|
18
19
|
@Override
|
@@ -3,9 +3,11 @@ package org.embulk.output.mysql;
|
|
3
3
|
import java.util.List;
|
4
4
|
import java.sql.Connection;
|
5
5
|
import java.sql.SQLException;
|
6
|
+
|
6
7
|
import org.embulk.output.jdbc.JdbcColumn;
|
7
8
|
import org.embulk.output.jdbc.JdbcSchema;
|
8
9
|
import org.embulk.output.jdbc.JdbcOutputConnection;
|
10
|
+
import org.embulk.output.jdbc.MergeConfig;
|
9
11
|
|
10
12
|
public class MySQLOutputConnection
|
11
13
|
extends JdbcOutputConnection
|
@@ -18,50 +20,60 @@ public class MySQLOutputConnection
|
|
18
20
|
}
|
19
21
|
|
20
22
|
@Override
|
21
|
-
protected String buildPreparedMergeSql(String toTable, JdbcSchema toTableSchema,
|
23
|
+
protected String buildPreparedMergeSql(String toTable, JdbcSchema toTableSchema, MergeConfig mergeConfig) throws SQLException
|
22
24
|
{
|
23
25
|
StringBuilder sb = new StringBuilder();
|
24
26
|
|
25
27
|
sb.append("INSERT INTO ");
|
26
28
|
quoteIdentifierString(sb, toTable);
|
27
29
|
sb.append(" (");
|
28
|
-
for (int i=0; i < toTableSchema.getCount(); i++) {
|
30
|
+
for (int i = 0; i < toTableSchema.getCount(); i++) {
|
29
31
|
if(i != 0) { sb.append(", "); }
|
30
32
|
quoteIdentifierString(sb, toTableSchema.getColumnName(i));
|
31
33
|
}
|
32
34
|
sb.append(") VALUES (");
|
33
|
-
for(int i=0; i < toTableSchema.getCount(); i++) {
|
35
|
+
for(int i = 0; i < toTableSchema.getCount(); i++) {
|
34
36
|
if(i != 0) { sb.append(", "); }
|
35
37
|
sb.append("?");
|
36
38
|
}
|
37
39
|
sb.append(")");
|
38
40
|
sb.append(" ON DUPLICATE KEY UPDATE ");
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
41
|
+
if (mergeConfig.getMergeRule().isPresent()) {
|
42
|
+
List<String> rule = mergeConfig.getMergeRule().get();
|
43
|
+
for (int i = 0; i < rule.size(); i++) {
|
44
|
+
if (i != 0) {
|
45
|
+
sb.append(", ");
|
46
|
+
}
|
47
|
+
sb.append(rule.get(i));
|
48
|
+
}
|
49
|
+
} else {
|
50
|
+
for (int i = 0; i < toTableSchema.getCount(); i++) {
|
51
|
+
if(i != 0) { sb.append(", "); }
|
52
|
+
String columnName = quoteIdentifierString(toTableSchema.getColumnName(i));
|
53
|
+
sb.append(columnName).append(" = VALUES(").append(columnName).append(")");
|
54
|
+
}
|
43
55
|
}
|
44
56
|
|
45
57
|
return sb.toString();
|
46
58
|
}
|
47
59
|
|
48
60
|
@Override
|
49
|
-
protected String buildCollectMergeSql(List<String> fromTables, JdbcSchema schema, String toTable,
|
61
|
+
protected String buildCollectMergeSql(List<String> fromTables, JdbcSchema schema, String toTable, MergeConfig mergeConfig) throws SQLException
|
50
62
|
{
|
51
63
|
StringBuilder sb = new StringBuilder();
|
52
64
|
|
53
65
|
sb.append("INSERT INTO ");
|
54
66
|
quoteIdentifierString(sb, toTable);
|
55
67
|
sb.append(" (");
|
56
|
-
for (int i=0; i < schema.getCount(); i++) {
|
68
|
+
for (int i = 0; i < schema.getCount(); i++) {
|
57
69
|
if (i != 0) { sb.append(", "); }
|
58
70
|
quoteIdentifierString(sb, schema.getColumnName(i));
|
59
71
|
}
|
60
72
|
sb.append(") ");
|
61
|
-
for (int i=0; i < fromTables.size(); i++) {
|
73
|
+
for (int i = 0; i < fromTables.size(); i++) {
|
62
74
|
if (i != 0) { sb.append(" UNION ALL "); }
|
63
75
|
sb.append("SELECT ");
|
64
|
-
for (int j=0; j < schema.getCount(); j++) {
|
76
|
+
for (int j = 0; j < schema.getCount(); j++) {
|
65
77
|
if (j != 0) { sb.append(", "); }
|
66
78
|
quoteIdentifierString(sb, schema.getColumnName(j));
|
67
79
|
}
|
@@ -69,10 +81,20 @@ public class MySQLOutputConnection
|
|
69
81
|
quoteIdentifierString(sb, fromTables.get(i));
|
70
82
|
}
|
71
83
|
sb.append(" ON DUPLICATE KEY UPDATE ");
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
84
|
+
if (mergeConfig.getMergeRule().isPresent()) {
|
85
|
+
List<String> rule = mergeConfig.getMergeRule().get();
|
86
|
+
for (int i = 0; i < rule.size(); i++) {
|
87
|
+
if (i != 0) {
|
88
|
+
sb.append(", ");
|
89
|
+
}
|
90
|
+
sb.append(rule.get(i));
|
91
|
+
}
|
92
|
+
} else {
|
93
|
+
for (int i = 0; i < schema.getCount(); i++) {
|
94
|
+
if(i != 0) { sb.append(", "); }
|
95
|
+
String columnName = quoteIdentifierString(schema.getColumnName(i));
|
96
|
+
sb.append(columnName).append(" = VALUES(").append(columnName).append(")");
|
97
|
+
}
|
76
98
|
}
|
77
99
|
|
78
100
|
return sb.toString();
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: embulk-output-mysql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.2
|
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-
|
11
|
+
date: 2016-08-10 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Inserts or updates records to a table.
|
14
14
|
email:
|
@@ -24,8 +24,8 @@ files:
|
|
24
24
|
- src/main/java/org/embulk/output/mysql/MySQLBatchInsert.java
|
25
25
|
- src/main/java/org/embulk/output/mysql/MySQLOutputConnection.java
|
26
26
|
- src/main/java/org/embulk/output/mysql/MySQLOutputConnector.java
|
27
|
-
- classpath/embulk-output-jdbc-0.6.
|
28
|
-
- classpath/embulk-output-mysql-0.6.
|
27
|
+
- classpath/embulk-output-jdbc-0.6.2.jar
|
28
|
+
- classpath/embulk-output-mysql-0.6.2.jar
|
29
29
|
- classpath/mysql-connector-java-5.1.34.jar
|
30
30
|
homepage: https://github.com/embulk/embulk-output-jdbc
|
31
31
|
licenses:
|
Binary file
|
Binary file
|