embulk-output-mysql 0.4.1 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 654a8874f6c05b83a2d036215f89cdfb9d9f8aae
4
- data.tar.gz: f6e2cfe04f4c76cc5da595ee92d6cf2fc7c5c08e
3
+ metadata.gz: 5b8da74a6c3c7cc8fcfa8a2192e0557be139d107
4
+ data.tar.gz: b22ef5085ab4107bccc6b73b351f193f9b62030d
5
5
  SHA512:
6
- metadata.gz: dc49a5db36e08d94cae403c1981d0acfc6f82f1a8b244fab5f692c4031ae25ec6320249ae325c270ecb322d0e209ce7d238eede4c3a8dcefa57bce0d2981a779
7
- data.tar.gz: 73f221998318088f1edd6abdf14c68da3e955238829d9601f8fec99a179195961200d5b1edff45adbdc460b9e131723cc00df261c850526328d0f73f3eab04a0
6
+ metadata.gz: 4ac5b1cc0c7b0c60c71f84702d1156ddf8c5965823fdec8e8a78e13c250a7d7231f3bab8e1fce1ab756903af7309116e2ad4ed774ade7f5da238f1734ab16566
7
+ data.tar.gz: 22bb204200401263e0f1e5698a7ffbb69e0b6d94f9123538e15a6dab129a9c749f67baa3b747681324b54df3f7acafd61ccba99698e12ba1b1132407a768b1ee
data/README.md CHANGED
@@ -1,92 +1,92 @@
1
- # MySQL output plugins for Embulk
2
-
3
- MySQL output plugins for Embulk loads records to MySQL.
4
-
5
- ## Overview
6
-
7
- * **Plugin type**: output
8
- * **Load all or nothing**: depnds on the mode. see bellow.
9
- * **Resume supported**: depnds on the mode. see bellow.
10
-
11
- ## Configuration
12
-
13
- - **host**: database host name (string, required)
14
- - **port**: database port number (integer, default: 3306)
15
- - **user**: database login user name (string, required)
16
- - **password**: database login password (string, default: "")
17
- - **database**: destination database name (string, required)
18
- - **table**: destination table name (string, required)
19
- - **options**: extra connection properties (hash, default: {})
20
- - **mode**: "insert", "insert_direct", "truncate_insert", "merge", "merge_direct", or "replace". See bellow. (string, required)
21
- - **batch_size**: size of a single batch insert (integer, default: 16777216)
22
- - **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
- - **column_options**: advanced: a key-value pairs where key is a column name and value is options for the column.
24
- - **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, insert_truncate and merge modes), when it creates the target table (insert_direct, merge_direct and replace modes), 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)
25
- - **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 input column type. Available values options are: `byte`, `short`, `int`, `long`, `double`, `float`, `boolean`, `string`, `nstring`, `date`, `time`, `timestamp`, `decimal`, `null`, `pass`)
26
- - **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`)
27
- - **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)
28
-
29
- ### Modes
30
-
31
- * **insert**:
32
- * 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.
33
- * Transactional: Yes. This mode successfully writes all rows, or fails with writing zero rows.
34
- * Resumable: Yes.
35
- * **insert_direct**:
36
- * Behavior: This mode inserts rows to the target table directly.
37
- * Transactional: No. If fails, the target table could have some rows inserted.
38
- * Resumable: No.
39
- * **truncate_insert**:
40
- * Behavior: Same with `insert` mode excepting that it truncates the target table right before the last `INSERT ...` query.
41
- * Transactional: Yes.
42
- * Resumable: Yes.
43
- * **merge**:
44
- * 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 ... ON DUPLICATE KEY UPDATE ...` query.
45
- * Transactional: Yes.
46
- * Resumable: Yes.
47
- * **merge_direct**:
48
- * Behavior: This mode inserts rows to the target table directory using `INSERT INTO ... ON DUPLICATE KEY UPDATE ...` query.
49
- * Transactional: No.
50
- * Resumable: No.
51
- * **replace**:
52
- * Behavior: Same with `insert` mode excepting that it truncates the target table right before the last `INSERT ...` query.
53
- * Transactional: Yes.
54
- * Resumable: No.
55
-
56
- ### Example
57
-
58
- ```yaml
59
- out:
60
- type: mysql
61
- host: localhost
62
- user: root
63
- password: ""
64
- database: my_database
65
- table: my_table
66
- mode: insert
67
- ```
68
-
69
- Advanced configuration:
70
-
71
- ```yaml
72
- out:
73
- type: mysql
74
- host: localhost
75
- user: root
76
- password: ""
77
- database: my_database
78
- table: my_table
79
- options: {connectTimeout: 20000}
80
- mode: insert_direct
81
- column_options:
82
- my_col_1: {type: 'TEXT'}
83
- my_col_3: {type: 'INT NOT NULL'}
84
- my_col_4: {value_type: string, timestamp_format: `%Y-%m-%d %H:%M:%S %z`, timezone: '-0700'}
85
- my_col_5: {type: 'DECIMAL(18,9)', value_type: pass}
86
- ```
87
-
88
- ### Build
89
-
90
- ```
91
- $ ./gradlew gem
92
- ```
1
+ # MySQL output plugins for Embulk
2
+
3
+ MySQL output plugins for Embulk loads records to MySQL.
4
+
5
+ ## Overview
6
+
7
+ * **Plugin type**: output
8
+ * **Load all or nothing**: depnds on the mode. see bellow.
9
+ * **Resume supported**: depnds on the mode. see bellow.
10
+
11
+ ## Configuration
12
+
13
+ - **host**: database host name (string, required)
14
+ - **port**: database port number (integer, default: 3306)
15
+ - **user**: database login user name (string, required)
16
+ - **password**: database login password (string, default: "")
17
+ - **database**: destination database name (string, required)
18
+ - **table**: destination table name (string, required)
19
+ - **options**: extra connection properties (hash, default: {})
20
+ - **mode**: "insert", "insert_direct", "truncate_insert", "merge", "merge_direct", or "replace". See bellow. (string, required)
21
+ - **batch_size**: size of a single batch insert (integer, default: 16777216)
22
+ - **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
+ - **column_options**: advanced: a key-value pairs where key is a column name and value is options for the column.
24
+ - **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, insert_truncate and merge modes), when it creates the target table (insert_direct, merge_direct and replace modes), 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)
25
+ - **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 input column type. Available values options are: `byte`, `short`, `int`, `long`, `double`, `float`, `boolean`, `string`, `nstring`, `date`, `time`, `timestamp`, `decimal`, `null`, `pass`)
26
+ - **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`)
27
+ - **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)
28
+
29
+ ### Modes
30
+
31
+ * **insert**:
32
+ * 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.
33
+ * Transactional: Yes. This mode successfully writes all rows, or fails with writing zero rows.
34
+ * Resumable: Yes.
35
+ * **insert_direct**:
36
+ * Behavior: This mode inserts rows to the target table directly.
37
+ * Transactional: No. If fails, the target table could have some rows inserted.
38
+ * Resumable: No.
39
+ * **truncate_insert**:
40
+ * Behavior: Same with `insert` mode excepting that it truncates the target table right before the last `INSERT ...` query.
41
+ * Transactional: Yes.
42
+ * Resumable: Yes.
43
+ * **merge**:
44
+ * 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 ... ON DUPLICATE KEY UPDATE ...` query.
45
+ * Transactional: Yes.
46
+ * Resumable: Yes.
47
+ * **merge_direct**:
48
+ * Behavior: This mode inserts rows to the target table directory using `INSERT INTO ... ON DUPLICATE KEY UPDATE ...` query.
49
+ * Transactional: No.
50
+ * Resumable: No.
51
+ * **replace**:
52
+ * Behavior: Same with `insert` mode excepting that it truncates the target table right before the last `INSERT ...` query.
53
+ * Transactional: Yes.
54
+ * Resumable: No.
55
+
56
+ ### Example
57
+
58
+ ```yaml
59
+ out:
60
+ type: mysql
61
+ host: localhost
62
+ user: root
63
+ password: ""
64
+ database: my_database
65
+ table: my_table
66
+ mode: insert
67
+ ```
68
+
69
+ Advanced configuration:
70
+
71
+ ```yaml
72
+ out:
73
+ type: mysql
74
+ host: localhost
75
+ user: root
76
+ password: ""
77
+ database: my_database
78
+ table: my_table
79
+ options: {connectTimeout: 20000}
80
+ mode: insert_direct
81
+ column_options:
82
+ my_col_1: {type: 'TEXT'}
83
+ my_col_3: {type: 'INT NOT NULL'}
84
+ my_col_4: {value_type: string, timestamp_format: `%Y-%m-%d %H:%M:%S %z`, timezone: '-0700'}
85
+ my_col_5: {type: 'DECIMAL(18,9)', value_type: pass}
86
+ ```
87
+
88
+ ### Build
89
+
90
+ ```
91
+ $ ./gradlew gem
92
+ ```
@@ -1,7 +1,7 @@
1
- dependencies {
2
- compile project(':embulk-output-jdbc')
3
-
4
- compile 'mysql:mysql-connector-java:5.1.34'
5
-
6
- testCompile project(':embulk-output-jdbc').sourceSets.test.output
7
- }
1
+ dependencies {
2
+ compile project(':embulk-output-jdbc')
3
+
4
+ compile 'mysql:mysql-connector-java:5.1.34'
5
+
6
+ testCompile project(':embulk-output-jdbc').sourceSets.test.output
7
+ }
@@ -1,3 +1,3 @@
1
- Embulk::JavaPlugin.register_output(
2
- :mysql, "org.embulk.output.MySQLOutputPlugin",
3
- File.expand_path('../../../../classpath', __FILE__))
1
+ Embulk::JavaPlugin.register_output(
2
+ :mysql, "org.embulk.output.MySQLOutputPlugin",
3
+ File.expand_path('../../../../classpath', __FILE__))
@@ -1,111 +1,111 @@
1
- package org.embulk.output;
2
-
3
- import java.util.List;
4
- import java.util.Properties;
5
- import java.io.IOException;
6
- import java.sql.SQLException;
7
- import com.google.common.base.Optional;
8
- import org.embulk.config.Config;
9
- import org.embulk.config.ConfigDefault;
10
- import org.embulk.output.jdbc.AbstractJdbcOutputPlugin;
11
- import org.embulk.output.jdbc.BatchInsert;
12
- import org.embulk.output.mysql.MySQLOutputConnector;
13
- import org.embulk.output.mysql.MySQLBatchInsert;
14
-
15
- public class MySQLOutputPlugin
16
- extends AbstractJdbcOutputPlugin
17
- {
18
- public interface MySQLPluginTask
19
- extends PluginTask
20
- {
21
- @Config("host")
22
- public String getHost();
23
-
24
- @Config("port")
25
- @ConfigDefault("3306")
26
- public int getPort();
27
-
28
- @Config("user")
29
- public String getUser();
30
-
31
- @Config("password")
32
- @ConfigDefault("\"\"")
33
- public String getPassword();
34
-
35
- @Config("database")
36
- public String getDatabase();
37
- }
38
-
39
- @Override
40
- protected Class<? extends PluginTask> getTaskClass()
41
- {
42
- return MySQLPluginTask.class;
43
- }
44
-
45
- @Override
46
- protected Features getFeatures(PluginTask task)
47
- {
48
- return new Features()
49
- .setMaxTableNameLength(64)
50
- .setIgnoreMergeKeys(true);
51
- }
52
-
53
- @Override
54
- protected MySQLOutputConnector getConnector(PluginTask task, boolean retryableMetadataOperation)
55
- {
56
- MySQLPluginTask t = (MySQLPluginTask) task;
57
-
58
- String url = String.format("jdbc:mysql://%s:%d/%s",
59
- t.getHost(), t.getPort(), t.getDatabase());
60
-
61
- Properties props = new Properties();
62
-
63
- props.setProperty("rewriteBatchedStatements", "true");
64
- props.setProperty("useCompression", "true");
65
-
66
- props.setProperty("connectTimeout", "300000"); // milliseconds
67
- props.setProperty("socketTimeout", "1800000"); // smillieconds
68
-
69
- // Enable keepalive based on tcp_keepalive_time, tcp_keepalive_intvl and tcp_keepalive_probes kernel parameters.
70
- // Socket options TCP_KEEPCNT, TCP_KEEPIDLE, and TCP_KEEPINTVL are not configurable.
71
- props.setProperty("tcpKeepAlive", "true");
72
-
73
- // TODO
74
- //switch t.getSssl() {
75
- //when "disable":
76
- // break;
77
- //when "enable":
78
- // props.setProperty("useSSL", "true");
79
- // props.setProperty("requireSSL", "false");
80
- // props.setProperty("verifyServerCertificate", "false");
81
- // break;
82
- //when "verify":
83
- // props.setProperty("useSSL", "true");
84
- // props.setProperty("requireSSL", "true");
85
- // props.setProperty("verifyServerCertificate", "true");
86
- // break;
87
- //}
88
-
89
- if (!retryableMetadataOperation) {
90
- // non-retryable batch operation uses longer timeout
91
- props.setProperty("connectTimeout", "300000"); // milliseconds
92
- props.setProperty("socketTimeout", "2700000"); // milliseconds
93
- }
94
-
95
- props.putAll(t.getOptions());
96
-
97
- // TODO validate task.getMergeKeys is null
98
-
99
- props.setProperty("user", t.getUser());
100
- logger.info("Connecting to {} options {}", url, props);
101
- props.setProperty("password", t.getPassword());
102
-
103
- return new MySQLOutputConnector(url, props);
104
- }
105
-
106
- @Override
107
- protected BatchInsert newBatchInsert(PluginTask task, Optional<List<String>> mergeKeys) throws IOException, SQLException
108
- {
109
- return new MySQLBatchInsert(getConnector(task, true), mergeKeys);
110
- }
111
- }
1
+ package org.embulk.output;
2
+
3
+ import java.util.List;
4
+ import java.util.Properties;
5
+ import java.io.IOException;
6
+ import java.sql.SQLException;
7
+ import com.google.common.base.Optional;
8
+ import org.embulk.config.Config;
9
+ import org.embulk.config.ConfigDefault;
10
+ import org.embulk.output.jdbc.AbstractJdbcOutputPlugin;
11
+ import org.embulk.output.jdbc.BatchInsert;
12
+ import org.embulk.output.mysql.MySQLOutputConnector;
13
+ import org.embulk.output.mysql.MySQLBatchInsert;
14
+
15
+ public class MySQLOutputPlugin
16
+ extends AbstractJdbcOutputPlugin
17
+ {
18
+ public interface MySQLPluginTask
19
+ extends PluginTask
20
+ {
21
+ @Config("host")
22
+ public String getHost();
23
+
24
+ @Config("port")
25
+ @ConfigDefault("3306")
26
+ public int getPort();
27
+
28
+ @Config("user")
29
+ public String getUser();
30
+
31
+ @Config("password")
32
+ @ConfigDefault("\"\"")
33
+ public String getPassword();
34
+
35
+ @Config("database")
36
+ public String getDatabase();
37
+ }
38
+
39
+ @Override
40
+ protected Class<? extends PluginTask> getTaskClass()
41
+ {
42
+ return MySQLPluginTask.class;
43
+ }
44
+
45
+ @Override
46
+ protected Features getFeatures(PluginTask task)
47
+ {
48
+ return new Features()
49
+ .setMaxTableNameLength(64)
50
+ .setIgnoreMergeKeys(true);
51
+ }
52
+
53
+ @Override
54
+ protected MySQLOutputConnector getConnector(PluginTask task, boolean retryableMetadataOperation)
55
+ {
56
+ MySQLPluginTask t = (MySQLPluginTask) task;
57
+
58
+ String url = String.format("jdbc:mysql://%s:%d/%s",
59
+ t.getHost(), t.getPort(), t.getDatabase());
60
+
61
+ Properties props = new Properties();
62
+
63
+ props.setProperty("rewriteBatchedStatements", "true");
64
+ props.setProperty("useCompression", "true");
65
+
66
+ props.setProperty("connectTimeout", "300000"); // milliseconds
67
+ props.setProperty("socketTimeout", "1800000"); // smillieconds
68
+
69
+ // Enable keepalive based on tcp_keepalive_time, tcp_keepalive_intvl and tcp_keepalive_probes kernel parameters.
70
+ // Socket options TCP_KEEPCNT, TCP_KEEPIDLE, and TCP_KEEPINTVL are not configurable.
71
+ props.setProperty("tcpKeepAlive", "true");
72
+
73
+ // TODO
74
+ //switch t.getSssl() {
75
+ //when "disable":
76
+ // break;
77
+ //when "enable":
78
+ // props.setProperty("useSSL", "true");
79
+ // props.setProperty("requireSSL", "false");
80
+ // props.setProperty("verifyServerCertificate", "false");
81
+ // break;
82
+ //when "verify":
83
+ // props.setProperty("useSSL", "true");
84
+ // props.setProperty("requireSSL", "true");
85
+ // props.setProperty("verifyServerCertificate", "true");
86
+ // break;
87
+ //}
88
+
89
+ if (!retryableMetadataOperation) {
90
+ // non-retryable batch operation uses longer timeout
91
+ props.setProperty("connectTimeout", "300000"); // milliseconds
92
+ props.setProperty("socketTimeout", "2700000"); // milliseconds
93
+ }
94
+
95
+ props.putAll(t.getOptions());
96
+
97
+ // TODO validate task.getMergeKeys is null
98
+
99
+ props.setProperty("user", t.getUser());
100
+ logger.info("Connecting to {} options {}", url, props);
101
+ props.setProperty("password", t.getPassword());
102
+
103
+ return new MySQLOutputConnector(url, props);
104
+ }
105
+
106
+ @Override
107
+ protected BatchInsert newBatchInsert(PluginTask task, Optional<List<String>> mergeKeys) throws IOException, SQLException
108
+ {
109
+ return new MySQLBatchInsert(getConnector(task, true), mergeKeys);
110
+ }
111
+ }
@@ -1,38 +1,37 @@
1
- package org.embulk.output.mysql;
2
-
3
- import java.util.List;
4
- import java.io.IOException;
5
- import java.sql.Types;
6
- import java.sql.PreparedStatement;
7
- import java.sql.SQLException;
8
- import com.google.common.base.Optional;
9
- import org.embulk.output.jdbc.StandardBatchInsert;
10
-
11
- public class MySQLBatchInsert
12
- extends StandardBatchInsert
13
- {
14
- public MySQLBatchInsert(MySQLOutputConnector connector, Optional<List<String>> mergeKeys) throws IOException, SQLException
15
- {
16
- super(connector, mergeKeys);
17
- }
18
-
19
- @Override
20
- public void setFloat(float v) throws IOException, SQLException
21
- {
22
- if (Float.isNaN(v) || Float.isInfinite(v)) {
23
- setNull(Types.REAL); // TODO get through argument
24
- } else {
25
- super.setFloat(v);
26
- }
27
- }
28
-
29
- @Override
30
- public void setDouble(double v) throws IOException, SQLException
31
- {
32
- if (Double.isNaN(v) || Double.isInfinite(v)) {
33
- setNull(Types.DOUBLE); // TODO get through argument
34
- } else {
35
- super.setDouble(v);
36
- }
37
- }
38
- }
1
+ package org.embulk.output.mysql;
2
+
3
+ import java.util.List;
4
+ import java.io.IOException;
5
+ import java.sql.Types;
6
+ import java.sql.SQLException;
7
+ import com.google.common.base.Optional;
8
+ import org.embulk.output.jdbc.StandardBatchInsert;
9
+
10
+ public class MySQLBatchInsert
11
+ extends StandardBatchInsert
12
+ {
13
+ public MySQLBatchInsert(MySQLOutputConnector connector, Optional<List<String>> mergeKeys) throws IOException, SQLException
14
+ {
15
+ super(connector, mergeKeys);
16
+ }
17
+
18
+ @Override
19
+ public void setFloat(float v) throws IOException, SQLException
20
+ {
21
+ if (Float.isNaN(v) || Float.isInfinite(v)) {
22
+ setNull(Types.REAL); // TODO get through argument
23
+ } else {
24
+ super.setFloat(v);
25
+ }
26
+ }
27
+
28
+ @Override
29
+ public void setDouble(double v) throws IOException, SQLException
30
+ {
31
+ if (Double.isNaN(v) || Double.isInfinite(v)) {
32
+ setNull(Types.DOUBLE); // TODO get through argument
33
+ } else {
34
+ super.setDouble(v);
35
+ }
36
+ }
37
+ }
@@ -1,91 +1,91 @@
1
- package org.embulk.output.mysql;
2
-
3
- import java.util.List;
4
- import java.sql.Connection;
5
- import java.sql.SQLException;
6
- import org.embulk.output.jdbc.JdbcColumn;
7
- import org.embulk.output.jdbc.JdbcSchema;
8
- import org.embulk.output.jdbc.JdbcOutputConnection;
9
-
10
- public class MySQLOutputConnection
11
- extends JdbcOutputConnection
12
- {
13
- public MySQLOutputConnection(Connection connection, boolean autoCommit)
14
- throws SQLException
15
- {
16
- super(connection, null);
17
- connection.setAutoCommit(autoCommit);
18
- }
19
-
20
- @Override
21
- protected String buildPreparedMergeSql(String toTable, JdbcSchema toTableSchema, List<String> mergeKeys) throws SQLException
22
- {
23
- StringBuilder sb = new StringBuilder();
24
-
25
- sb.append("INSERT INTO ");
26
- quoteIdentifierString(sb, toTable);
27
- sb.append(" (");
28
- for (int i=0; i < toTableSchema.getCount(); i++) {
29
- if(i != 0) { sb.append(", "); }
30
- quoteIdentifierString(sb, toTableSchema.getColumnName(i));
31
- }
32
- sb.append(") VALUES (");
33
- for(int i=0; i < toTableSchema.getCount(); i++) {
34
- if(i != 0) { sb.append(", "); }
35
- sb.append("?");
36
- }
37
- sb.append(")");
38
- sb.append(" ON DUPLICATE KEY UPDATE ");
39
- for (int i=0; i < toTableSchema.getCount(); i++) {
40
- if(i != 0) { sb.append(", "); }
41
- String columnName = quoteIdentifierString(toTableSchema.getColumnName(i));
42
- sb.append(columnName).append(" = VALUES(").append(columnName).append(")");
43
- }
44
-
45
- return sb.toString();
46
- }
47
-
48
- @Override
49
- protected String buildCollectMergeSql(List<String> fromTables, JdbcSchema schema, String toTable, List<String> mergeKeys) throws SQLException
50
- {
51
- StringBuilder sb = new StringBuilder();
52
-
53
- sb.append("INSERT INTO ");
54
- quoteIdentifierString(sb, toTable);
55
- sb.append(" (");
56
- for (int i=0; i < schema.getCount(); i++) {
57
- if (i != 0) { sb.append(", "); }
58
- quoteIdentifierString(sb, schema.getColumnName(i));
59
- }
60
- sb.append(") ");
61
- for (int i=0; i < fromTables.size(); i++) {
62
- if (i != 0) { sb.append(" UNION ALL "); }
63
- sb.append("SELECT ");
64
- for (int j=0; j < schema.getCount(); j++) {
65
- if (j != 0) { sb.append(", "); }
66
- quoteIdentifierString(sb, schema.getColumnName(j));
67
- }
68
- sb.append(" FROM ");
69
- quoteIdentifierString(sb, fromTables.get(i));
70
- }
71
- sb.append(" ON DUPLICATE KEY UPDATE ");
72
- for (int i=0; i < schema.getCount(); i++) {
73
- if(i != 0) { sb.append(", "); }
74
- String columnName = quoteIdentifierString(schema.getColumnName(i));
75
- sb.append(columnName).append(" = VALUES(").append(columnName).append(")");
76
- }
77
-
78
- return sb.toString();
79
- }
80
-
81
- @Override
82
- protected String buildColumnTypeName(JdbcColumn c)
83
- {
84
- switch(c.getSimpleTypeName()) {
85
- case "CLOB":
86
- return "TEXT";
87
- default:
88
- return super.buildColumnTypeName(c);
89
- }
90
- }
91
- }
1
+ package org.embulk.output.mysql;
2
+
3
+ import java.util.List;
4
+ import java.sql.Connection;
5
+ import java.sql.SQLException;
6
+ import org.embulk.output.jdbc.JdbcColumn;
7
+ import org.embulk.output.jdbc.JdbcSchema;
8
+ import org.embulk.output.jdbc.JdbcOutputConnection;
9
+
10
+ public class MySQLOutputConnection
11
+ extends JdbcOutputConnection
12
+ {
13
+ public MySQLOutputConnection(Connection connection, boolean autoCommit)
14
+ throws SQLException
15
+ {
16
+ super(connection, null);
17
+ connection.setAutoCommit(autoCommit);
18
+ }
19
+
20
+ @Override
21
+ protected String buildPreparedMergeSql(String toTable, JdbcSchema toTableSchema, List<String> mergeKeys) throws SQLException
22
+ {
23
+ StringBuilder sb = new StringBuilder();
24
+
25
+ sb.append("INSERT INTO ");
26
+ quoteIdentifierString(sb, toTable);
27
+ sb.append(" (");
28
+ for (int i=0; i < toTableSchema.getCount(); i++) {
29
+ if(i != 0) { sb.append(", "); }
30
+ quoteIdentifierString(sb, toTableSchema.getColumnName(i));
31
+ }
32
+ sb.append(") VALUES (");
33
+ for(int i=0; i < toTableSchema.getCount(); i++) {
34
+ if(i != 0) { sb.append(", "); }
35
+ sb.append("?");
36
+ }
37
+ sb.append(")");
38
+ sb.append(" ON DUPLICATE KEY UPDATE ");
39
+ for (int i=0; i < toTableSchema.getCount(); i++) {
40
+ if(i != 0) { sb.append(", "); }
41
+ String columnName = quoteIdentifierString(toTableSchema.getColumnName(i));
42
+ sb.append(columnName).append(" = VALUES(").append(columnName).append(")");
43
+ }
44
+
45
+ return sb.toString();
46
+ }
47
+
48
+ @Override
49
+ protected String buildCollectMergeSql(List<String> fromTables, JdbcSchema schema, String toTable, List<String> mergeKeys) throws SQLException
50
+ {
51
+ StringBuilder sb = new StringBuilder();
52
+
53
+ sb.append("INSERT INTO ");
54
+ quoteIdentifierString(sb, toTable);
55
+ sb.append(" (");
56
+ for (int i=0; i < schema.getCount(); i++) {
57
+ if (i != 0) { sb.append(", "); }
58
+ quoteIdentifierString(sb, schema.getColumnName(i));
59
+ }
60
+ sb.append(") ");
61
+ for (int i=0; i < fromTables.size(); i++) {
62
+ if (i != 0) { sb.append(" UNION ALL "); }
63
+ sb.append("SELECT ");
64
+ for (int j=0; j < schema.getCount(); j++) {
65
+ if (j != 0) { sb.append(", "); }
66
+ quoteIdentifierString(sb, schema.getColumnName(j));
67
+ }
68
+ sb.append(" FROM ");
69
+ quoteIdentifierString(sb, fromTables.get(i));
70
+ }
71
+ sb.append(" ON DUPLICATE KEY UPDATE ");
72
+ for (int i=0; i < schema.getCount(); i++) {
73
+ if(i != 0) { sb.append(", "); }
74
+ String columnName = quoteIdentifierString(schema.getColumnName(i));
75
+ sb.append(columnName).append(" = VALUES(").append(columnName).append(")");
76
+ }
77
+
78
+ return sb.toString();
79
+ }
80
+
81
+ @Override
82
+ protected String buildColumnTypeName(JdbcColumn c)
83
+ {
84
+ switch(c.getSimpleTypeName()) {
85
+ case "CLOB":
86
+ return "TEXT";
87
+ default:
88
+ return super.buildColumnTypeName(c);
89
+ }
90
+ }
91
+ }
@@ -1,42 +1,41 @@
1
- package org.embulk.output.mysql;
2
-
3
- import java.util.Properties;
4
- import java.sql.Driver;
5
- import java.sql.Connection;
6
- import java.sql.SQLException;
7
- import org.embulk.output.jdbc.JdbcOutputConnector;
8
- import org.embulk.output.jdbc.JdbcOutputConnection;
9
-
10
- public class MySQLOutputConnector
11
- implements JdbcOutputConnector
12
- {
13
- private final Driver driver;
14
- private final String url;
15
- private final Properties properties;
16
-
17
- public MySQLOutputConnector(String url, Properties properties)
18
- {
19
- try {
20
- this.driver = new com.mysql.jdbc.Driver(); // new com.mysql.jdbc.Driver throws SQLException
21
- } catch (SQLException ex) {
22
- throw new RuntimeException(ex);
23
- }
24
- this.url = url;
25
- this.properties = properties;
26
- }
27
-
28
- @Override
29
- public MySQLOutputConnection connect(boolean autoCommit) throws SQLException
30
- {
31
- Connection c = driver.connect(url, properties);
32
- try {
33
- MySQLOutputConnection con = new MySQLOutputConnection(c, autoCommit);
34
- c = null;
35
- return con;
36
- } finally {
37
- if (c != null) {
38
- c.close();
39
- }
40
- }
41
- }
42
- }
1
+ package org.embulk.output.mysql;
2
+
3
+ import java.util.Properties;
4
+ import java.sql.Driver;
5
+ import java.sql.Connection;
6
+ import java.sql.SQLException;
7
+ import org.embulk.output.jdbc.JdbcOutputConnector;
8
+
9
+ public class MySQLOutputConnector
10
+ implements JdbcOutputConnector
11
+ {
12
+ private final Driver driver;
13
+ private final String url;
14
+ private final Properties properties;
15
+
16
+ public MySQLOutputConnector(String url, Properties properties)
17
+ {
18
+ try {
19
+ this.driver = new com.mysql.jdbc.Driver(); // new com.mysql.jdbc.Driver throws SQLException
20
+ } catch (SQLException ex) {
21
+ throw new RuntimeException(ex);
22
+ }
23
+ this.url = url;
24
+ this.properties = properties;
25
+ }
26
+
27
+ @Override
28
+ public MySQLOutputConnection connect(boolean autoCommit) throws SQLException
29
+ {
30
+ Connection c = driver.connect(url, properties);
31
+ try {
32
+ MySQLOutputConnection con = new MySQLOutputConnection(c, autoCommit);
33
+ c = null;
34
+ return con;
35
+ } finally {
36
+ if (c != null) {
37
+ c.close();
38
+ }
39
+ }
40
+ }
41
+ }
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.4.1
4
+ version: 0.4.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: 2015-07-06 00:00:00.000000000 Z
11
+ date: 2015-12-08 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.4.1.jar
28
- - classpath/embulk-output-mysql-0.4.1.jar
27
+ - classpath/embulk-output-jdbc-0.4.2.jar
28
+ - classpath/embulk-output-mysql-0.4.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: