embulk-output-mysql 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c687ef3905d12e4eb083d8c8e9a94f792dce1682
4
+ data.tar.gz: c7dbe040a2b18064d4bf271f38a99489f557e32b
5
+ SHA512:
6
+ metadata.gz: 40b00128822e262fe26428f6810f3a4eb4aaad591216511204b66894237a949a12df411fc37826762e67db7f700dc06d017962915c74434a1ec0a5eb8f9e7474
7
+ data.tar.gz: cb7f383e3c5c15f9350bab9c7b0410880aace46a6719b6f0e7f86ba1bc54cfbc53994e4c2217232bed02404c4b014c2ee804e46b731f712ddfb02a7b023ac683
@@ -0,0 +1,42 @@
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:
9
+ * **insert**: no
10
+ * **replace**: yes
11
+ * **Resume supported**: no
12
+
13
+ ## Configuration
14
+
15
+ - **host**: database host name (string, required)
16
+ - **port**: database port number (integer, default: 3306)
17
+ - **user**: database login user name (string, required)
18
+ - **password**: database login password (string, default: "")
19
+ - **database**: destination database name (string, required)
20
+ - **table**: destination name (string, required)
21
+ - **mode**: "replace" or "insert" (string, required)
22
+ - **batch_size**: size of a single batch insert (integer, default: 16777216)
23
+ - **options**: extra connection properties (hash, default: {})
24
+
25
+ ### Example
26
+
27
+ ```yaml
28
+ out:
29
+ type: mysql
30
+ host: localhost
31
+ user: root
32
+ password: ""
33
+ database: my_database
34
+ table: my_table
35
+ mode: insert
36
+ ```
37
+
38
+ ### Build
39
+
40
+ ```
41
+ $ ./gradlew gem
42
+ ```
@@ -0,0 +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
+ }
@@ -0,0 +1,3 @@
1
+ Embulk::JavaPlugin.register_output(
2
+ :mysql, "org.embulk.output.MySQLOutputPlugin",
3
+ File.expand_path('../../../../classpath', __FILE__))
@@ -0,0 +1,72 @@
1
+ package org.embulk.output;
2
+
3
+ import java.util.Properties;
4
+ import java.io.IOException;
5
+ import java.sql.SQLException;
6
+ import java.sql.Connection;
7
+ import org.embulk.spi.Exec;
8
+ import org.embulk.output.jdbc.AbstractJdbcOutputPlugin;
9
+ import org.embulk.output.jdbc.JdbcOutputConnection;
10
+ import org.embulk.output.jdbc.BatchInsert;
11
+ import org.embulk.output.jdbc.JdbcOutputConnector;
12
+ import org.embulk.output.mysql.MySQLOutputConnector;
13
+ import org.embulk.output.mysql.MySQLBatchInsert;
14
+
15
+ public class MySQLOutputPlugin
16
+ extends AbstractJdbcOutputPlugin
17
+ {
18
+ private static final int DEFAULT_PORT = 3306;
19
+
20
+ @Override
21
+ protected MySQLOutputConnector getConnector(PluginTask task, boolean retryableMetadataOperation)
22
+ {
23
+ String url = String.format("jdbc:mysql://%s:%d/%s",
24
+ task.getHost(), task.getPort().or(DEFAULT_PORT), task.getDatabase());
25
+
26
+ Properties props = new Properties();
27
+ props.setProperty("user", task.getUser());
28
+ props.setProperty("password", task.getPassword());
29
+
30
+ props.setProperty("rewriteBatchedStatements", "true");
31
+ props.setProperty("useCompression", "true");
32
+
33
+ props.setProperty("connectTimeout", "300000"); // milliseconds
34
+ props.setProperty("socketTimeout", "1800000"); // smillieconds
35
+
36
+ // Enable keepalive based on tcp_keepalive_time, tcp_keepalive_intvl and tcp_keepalive_probes kernel parameters.
37
+ // Socket options TCP_KEEPCNT, TCP_KEEPIDLE, and TCP_KEEPINTVL are not configurable.
38
+ props.setProperty("tcpKeepAlive", "true");
39
+
40
+ // TODO
41
+ //switch task.getSssl() {
42
+ //when "disable":
43
+ // break;
44
+ //when "enable":
45
+ // props.setProperty("useSSL", "true");
46
+ // props.setProperty("requireSSL", "false");
47
+ // props.setProperty("verifyServerCertificate", "false");
48
+ // break;
49
+ //when "verify":
50
+ // props.setProperty("useSSL", "true");
51
+ // props.setProperty("requireSSL", "true");
52
+ // props.setProperty("verifyServerCertificate", "true");
53
+ // break;
54
+ //}
55
+
56
+ if (!retryableMetadataOperation) {
57
+ // non-retryable batch operation uses longer timeout
58
+ props.setProperty("connectTimeout", "300000"); // milliseconds
59
+ props.setProperty("socketTimeout", "2700000"); // milliseconds
60
+ }
61
+
62
+ props.putAll(task.getOptions());
63
+
64
+ return new MySQLOutputConnector(url, props);
65
+ }
66
+
67
+ @Override
68
+ protected BatchInsert newBatchInsert(PluginTask task) throws IOException, SQLException
69
+ {
70
+ return new MySQLBatchInsert(getConnector(task, true));
71
+ }
72
+ }
@@ -0,0 +1,36 @@
1
+ package org.embulk.output.mysql;
2
+
3
+ import java.io.IOException;
4
+ import java.sql.Types;
5
+ import java.sql.PreparedStatement;
6
+ import java.sql.SQLException;
7
+ import org.embulk.output.jdbc.StandardBatchInsert;
8
+
9
+ public class MySQLBatchInsert
10
+ extends StandardBatchInsert
11
+ {
12
+ public MySQLBatchInsert(MySQLOutputConnector connector) throws IOException, SQLException
13
+ {
14
+ super(connector);
15
+ }
16
+
17
+ @Override
18
+ public void setFloat(float v) throws IOException, SQLException
19
+ {
20
+ if (Float.isNaN(v) || Float.isInfinite(v)) {
21
+ setNull(Types.REAL); // TODO get through argument
22
+ } else {
23
+ super.setFloat(v);
24
+ }
25
+ }
26
+
27
+ @Override
28
+ public void setDouble(double v) throws IOException, SQLException
29
+ {
30
+ if (Double.isNaN(v) || Double.isInfinite(v)) {
31
+ setNull(Types.DOUBLE); // TODO get through argument
32
+ } else {
33
+ super.setDouble(v);
34
+ }
35
+ }
36
+ }
@@ -0,0 +1,30 @@
1
+ package org.embulk.output.mysql;
2
+
3
+ import java.sql.Connection;
4
+ import java.sql.SQLException;
5
+ import org.embulk.spi.Exec;
6
+ import org.embulk.output.jdbc.BatchInsert;
7
+ import org.embulk.output.jdbc.JdbcOutputConnection;
8
+ import org.embulk.output.jdbc.JdbcColumn;
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 convertTypeName(String typeName)
22
+ {
23
+ switch(typeName) {
24
+ case "CLOB":
25
+ return "TEXT";
26
+ default:
27
+ return typeName;
28
+ }
29
+ }
30
+ }
@@ -0,0 +1,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
+ 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
+ }
metadata ADDED
@@ -0,0 +1,54 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: embulk-output-mysql
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - FURUHASHI Sadayuki
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-16 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: JDBC output plugin is an Embulk plugin that loads records to JDBC read by any input plugins. Search the input plugins by "embulk-input" keyword.
14
+ email:
15
+ - frsyuki@users.sourceforge.jp
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - README.md
21
+ - build.gradle
22
+ - lib/embulk/output/mysql.rb
23
+ - src/main/java/org/embulk/output/MySQLOutputPlugin.java
24
+ - src/main/java/org/embulk/output/mysql/MySQLBatchInsert.java
25
+ - src/main/java/org/embulk/output/mysql/MySQLOutputConnection.java
26
+ - src/main/java/org/embulk/output/mysql/MySQLOutputConnector.java
27
+ - classpath/embulk-output-jdbc-0.1.0.jar
28
+ - classpath/embulk-output-mysql-0.1.0.jar
29
+ - classpath/mysql-connector-java-5.1.34.jar
30
+ homepage: https://github.com/embulk/embulk-output-jdbc
31
+ licenses:
32
+ - Apache 2.0
33
+ metadata: {}
34
+ post_install_message:
35
+ rdoc_options: []
36
+ require_paths:
37
+ - lib
38
+ required_ruby_version: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - '>='
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ required_rubygems_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ requirements: []
49
+ rubyforge_project:
50
+ rubygems_version: 2.1.9
51
+ signing_key:
52
+ specification_version: 4
53
+ summary: JDBC output plugin for Embulk
54
+ test_files: []