embulk-output-mysql 0.7.12 → 0.7.13

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: fe4b5952e11bde0ca8410bc18d9ce6bfe8cdc481
4
- data.tar.gz: 6b3184a514edc1e931fc6f325c71b2e3c2e1136c
3
+ metadata.gz: cc3ab6f3a5bfb39779736584783e384b4decd8c8
4
+ data.tar.gz: 2288573b82a2e38062a5315ac0e0035838af84b0
5
5
  SHA512:
6
- metadata.gz: 4d564b1e498ecc0db5059b0a00d5030bce0fe8f65ac4544b8be23ebeb29d503ca6c318130dd52506eef03bf4c89bab9e6d1e94c2ad20464334e0d3adb144735a
7
- data.tar.gz: c191d46f1edba132f007cab5a3450430ea5b13a82ae33e6da245ffb8f1a4ee18b7a760e808458a66c68bfad4aff5322a6e7e361b32689aa3881d0feb46797daf
6
+ metadata.gz: fd5382b3fd1051adc59d959c5f0d1ad0b39e2f4801d32a1879942035ebf01a74e375f4b2e856722885d070e03389ba6fd440b86f16f115a51554d1a79aa83708
7
+ data.tar.gz: 14f2a76d0917eb363a988eb7ee0384c302222d0a2eb71ac34435f89b488954c2aa20999cd1c03ea751bafc602d902628ff1bd533cd41dbc478bf3821e3a1523d
data/README.md CHANGED
@@ -10,6 +10,7 @@ MySQL output plugin for Embulk loads records to MySQL.
10
10
 
11
11
  ## Configuration
12
12
 
13
+ - **driver_path**: path to the jar file of the MySQL JDBC driver. If not set, the bundled JDBC driver (MySQL Connector/J 5.1.34) will be used. (string)
13
14
  - **host**: database host name (string, required)
14
15
  - **port**: database port number (integer, default: 3306)
15
16
  - **user**: database login user name (string, required)
@@ -18,6 +19,8 @@ MySQL output plugin for Embulk loads records to MySQL.
18
19
  - **database**: destination database name (string, required)
19
20
  - **temp_database**: database name for intermediate tables. by default, intermediate tables will be created in the database specified by `database`. (string, optional)
20
21
  - **table**: destination table name (string, required)
22
+ - **create_table_constraint** table constraint added to `CREATE TABLE` statement, like `CREATE TABLE <table_name> (<column1> <type1>, <column2> <type2>, ..., <create_table_constraint>) <create_table_option>`.
23
+ - **create_table_option** table option added to `CREATE TABLE` statement, like `CREATE TABLE <table_name> (<column1> <type1>, <column2> <type2>, ..., <create_table_constraint>) <create_table_option>`.
21
24
  - **options**: extra connection properties (hash, default: {})
22
25
  - **retry_limit** max retry count for database operations (integer, default: 12)
23
26
  - **retry_wait** initial retry wait time in milliseconds (integer, default: 1000 (1 second))
@@ -1,6 +1,7 @@
1
1
  dependencies {
2
2
  compile project(':embulk-output-jdbc')
3
3
  compile 'mysql:mysql-connector-java:5.1.34'
4
+ defaultJdbcDriver 'mysql:mysql-connector-java:5.1.34'
4
5
 
5
6
  testCompile 'org.embulk:embulk-standards:0.8.22'
6
7
  }
@@ -25,6 +25,10 @@ public class MySQLOutputPlugin
25
25
  public interface MySQLPluginTask
26
26
  extends PluginTask
27
27
  {
28
+ @Config("driver_path")
29
+ @ConfigDefault("null")
30
+ public Optional<String> getDriverPath();
31
+
28
32
  @Config("host")
29
33
  public String getHost();
30
34
 
@@ -71,6 +75,8 @@ public class MySQLOutputPlugin
71
75
  {
72
76
  MySQLPluginTask t = (MySQLPluginTask) task;
73
77
 
78
+ loadDriver("com.mysql.jdbc.Driver", t.getDriverPath());
79
+
74
80
  String url = String.format("jdbc:mysql://%s:%d/%s",
75
81
  t.getHost(), t.getPort(), t.getDatabase());
76
82
 
@@ -1,25 +1,20 @@
1
1
  package org.embulk.output.mysql;
2
2
 
3
3
  import java.util.Properties;
4
- import java.sql.Driver;
5
4
  import java.sql.Connection;
5
+ import java.sql.DriverManager;
6
6
  import java.sql.SQLException;
7
+
7
8
  import org.embulk.output.jdbc.JdbcOutputConnector;
8
9
 
9
10
  public class MySQLOutputConnector
10
11
  implements JdbcOutputConnector
11
12
  {
12
- private final Driver driver;
13
13
  private final String url;
14
14
  private final Properties properties;
15
15
 
16
16
  public MySQLOutputConnector(String url, Properties properties)
17
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
18
  this.url = url;
24
19
  this.properties = properties;
25
20
  }
@@ -27,7 +22,7 @@ public class MySQLOutputConnector
27
22
  @Override
28
23
  public MySQLOutputConnection connect(boolean autoCommit) throws SQLException
29
24
  {
30
- Connection c = driver.connect(url, properties);
25
+ Connection c = DriverManager.getConnection(url, properties);
31
26
  try {
32
27
  MySQLOutputConnection con = new MySQLOutputConnection(c, autoCommit);
33
28
  c = null;
@@ -0,0 +1,79 @@
1
+ package org.embulk.output.mysql;
2
+
3
+ import static org.embulk.output.mysql.MySQLTests.execute;
4
+ import static org.embulk.output.mysql.MySQLTests.selectRecords;
5
+ import static org.hamcrest.Matchers.is;
6
+ import static org.junit.Assert.assertThat;
7
+
8
+ import java.io.File;
9
+ import java.net.URISyntaxException;
10
+ import java.net.URL;
11
+ import java.nio.file.FileSystems;
12
+ import java.nio.file.Path;
13
+
14
+ import org.embulk.config.ConfigDiff;
15
+ import org.embulk.config.ConfigSource;
16
+ import org.embulk.output.MySQLOutputPlugin;
17
+ import org.embulk.spi.OutputPlugin;
18
+ import org.embulk.test.EmbulkTests;
19
+ import org.embulk.test.TestingEmbulk;
20
+ import org.junit.Before;
21
+ import org.junit.Rule;
22
+ import org.junit.Test;
23
+
24
+ import com.google.common.io.Resources;
25
+
26
+ public class CreateTableTest
27
+ {
28
+ private static final String BASIC_RESOURCE_PATH = "org/embulk/output/mysql/test/expect/create_table/";
29
+
30
+ private static ConfigSource loadYamlResource(TestingEmbulk embulk, String fileName)
31
+ {
32
+ return embulk.loadYamlResource(BASIC_RESOURCE_PATH + fileName);
33
+ }
34
+
35
+ private static String readResource(String fileName)
36
+ {
37
+ return EmbulkTests.readResource(BASIC_RESOURCE_PATH + fileName);
38
+ }
39
+
40
+ @Rule
41
+ public TestingEmbulk embulk = TestingEmbulk.builder()
42
+ .registerPlugin(OutputPlugin.class, "mysql", MySQLOutputPlugin.class)
43
+ .build();
44
+
45
+ private ConfigSource baseConfig;
46
+
47
+ @Before
48
+ public void setup()
49
+ {
50
+ baseConfig = MySQLTests.baseConfig();
51
+ execute(readResource("setup.sql")); // setup rows
52
+ }
53
+
54
+ @Test
55
+ public void testTableOption() throws Exception
56
+ {
57
+ Path in1 = toPath("test1.csv");
58
+ TestingEmbulk.RunResult result1 = embulk.runOutput(baseConfig.merge(loadYamlResource(embulk, "test_table_option.yml")), in1);
59
+ assertThat(selectRecords(embulk, "test1"), is(readResource("test_table_option_expected.csv")));
60
+ //assertThat(result1.getConfigDiff(), is((ConfigDiff) loadYamlResource(embulk, "test_expected.diff")));
61
+ }
62
+
63
+ @Test
64
+ public void testTableConstraint() throws Exception
65
+ {
66
+ Path in1 = toPath("test1.csv");
67
+ // exception will be thrown without table constraint because auto column must be defined as a key.
68
+ TestingEmbulk.RunResult result1 = embulk.runOutput(baseConfig.merge(loadYamlResource(embulk, "test_table_constraint.yml")), in1);
69
+ assertThat(selectRecords(embulk, "test1"), is(readResource("test_table_constraint_expected.csv")));
70
+ //assertThat(result1.getConfigDiff(), is((ConfigDiff) loadYamlResource(embulk, "test_expected.diff")));
71
+ }
72
+
73
+ private Path toPath(String fileName) throws URISyntaxException
74
+ {
75
+ URL url = Resources.getResource(BASIC_RESOURCE_PATH + fileName);
76
+ return FileSystems.getDefault().getPath(new File(url.toURI()).getAbsolutePath());
77
+ }
78
+
79
+ }
@@ -0,0 +1,5 @@
1
+ table: test1
2
+ mode: insert
3
+ create_table_constraint: 'primary key(id)'
4
+ column_options:
5
+ id: {type: 'int auto_increment'}
@@ -0,0 +1,5 @@
1
+ table: test1
2
+ mode: insert
3
+ create_table_option: 'auto_increment=100'
4
+ column_options:
5
+ id: {type: 'int auto_increment primary key'}
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.7.12
4
+ version: 0.7.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sadayuki Furuhashi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-24 00:00:00.000000000 Z
11
+ date: 2017-12-08 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Inserts or updates records to a table.
14
14
  email:
@@ -19,9 +19,9 @@ extra_rdoc_files: []
19
19
  files:
20
20
  - README.md
21
21
  - build.gradle
22
- - classpath/embulk-output-jdbc-0.7.12.jar
23
- - classpath/embulk-output-mysql-0.7.12.jar
24
- - classpath/mysql-connector-java-5.1.34.jar
22
+ - classpath/embulk-output-jdbc-0.7.13.jar
23
+ - classpath/embulk-output-mysql-0.7.13.jar
24
+ - default_jdbc_driver/mysql-connector-java-5.1.34.jar
25
25
  - lib/embulk/output/mysql.rb
26
26
  - src/main/java/org/embulk/output/MySQLOutputPlugin.java
27
27
  - src/main/java/org/embulk/output/MySQLTimeZoneComparison.java
@@ -30,6 +30,7 @@ files:
30
30
  - src/main/java/org/embulk/output/mysql/MySQLOutputConnector.java
31
31
  - src/test/java/org/embulk/output/mysql/AfterLoadTest.java
32
32
  - src/test/java/org/embulk/output/mysql/BeforeLoadTest.java
33
+ - src/test/java/org/embulk/output/mysql/CreateTableTest.java
33
34
  - src/test/java/org/embulk/output/mysql/MySQLTests.java
34
35
  - src/test/resources/org/embulk/output/mysql/test/expect/after_load/setup.sql
35
36
  - src/test/resources/org/embulk/output/mysql/test/expect/after_load/test1.csv
@@ -55,6 +56,12 @@ files:
55
56
  - src/test/resources/org/embulk/output/mysql/test/expect/before_load/test_merge_direct_before_load.yml
56
57
  - src/test/resources/org/embulk/output/mysql/test/expect/before_load/test_truncate_insert_before_load.yml
57
58
  - src/test/resources/org/embulk/output/mysql/test/expect/before_load/test_truncate_insert_before_load_expected.csv
59
+ - src/test/resources/org/embulk/output/mysql/test/expect/create_table/setup.sql
60
+ - src/test/resources/org/embulk/output/mysql/test/expect/create_table/test1.csv
61
+ - src/test/resources/org/embulk/output/mysql/test/expect/create_table/test_table_constraint.yml
62
+ - src/test/resources/org/embulk/output/mysql/test/expect/create_table/test_table_constraint_expected.csv
63
+ - src/test/resources/org/embulk/output/mysql/test/expect/create_table/test_table_option.yml
64
+ - src/test/resources/org/embulk/output/mysql/test/expect/create_table/test_table_option_expected.csv
58
65
  homepage: https://github.com/embulk/embulk-output-jdbc
59
66
  licenses:
60
67
  - Apache 2.0