embulk-input-mysql 0.2.1 → 0.2.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: 4f416fe2b7b01cb603bcdc330f0d956988f2756b
4
- data.tar.gz: 73e22f9633062e6f85bd55c1e231295c332acaaa
3
+ metadata.gz: a09bee0f3126d679f39ab5f84f1eff085565f573
4
+ data.tar.gz: 216094c890843f89ede7e06717029f729e2d3f74
5
5
  SHA512:
6
- metadata.gz: 4d4519bc01ab852dc20dd8ed219c460b163a524c097e9362e80575ffbb3e3b18bb989c8b2eeb4908eb3c535b36278d4537f6d8d0135b22eea3335f520e0abe94
7
- data.tar.gz: 5c2b2044aa61697b7fac315d7077838267d24f56147ca0f31f9d039ef2692e5b7b433629550e25356c5accfcc0a6861c996ba8ddc65aa871b67118f72769227b
6
+ metadata.gz: 66b22834a187504875f27de487f1e994d2e8f7bf7e27a4da4a8ef7e00aae67005db73b05c0e81383947170016ab9c00c665d6955489babc511ec0845eedceb33
7
+ data.tar.gz: f802830a593f06048d37dd710b7e178e3efe7c2dfd1f0ab6e53f6e29d28a70f026402a6e2675ac13fb65ef608f41e2f812ddae0e65ffe8bf83bbcdc5730495db
data/README.md CHANGED
@@ -17,7 +17,16 @@ MySQL input plugins for Embulk loads records from MySQL.
17
17
  - **table**: destination name (string, required)
18
18
  - **select**: comma-separated list of columns to select (string, default: "*")
19
19
  - **where**: WHERE condition to filter the rows (string, default: no-condition)
20
- - **fetch_rows**: number of rows to fetch one time (used for java.sql.Statement#setFetchSize) (integer, default: 10000)
20
+ - **fetch_rows**: number of rows to fetch one time (integer, default: 10000)
21
+ - If this value is set to > 1:
22
+ - It uses a server-side prepared statement and fetches rows by chunks.
23
+ - Internally, `useCursorFetch=true` is enabled and `java.sql.Statement.setFetchSize` is set to the configured value.
24
+ - If this value is set to 1:
25
+ - It uses a client-side built statement and fetches rows one by one.
26
+ - Internally, `useCursorFetch=false` is used and `java.sql.Statement.setFetchSize` is set to Integer.MIN_VALUE.
27
+ - If this value is set to -1:
28
+ - It uses a client-side built statement and fetches all rows at once. This may cause OutOfMemoryError.
29
+ - Internally, `useCursorFetch=false` is used and `java.sql.Statement.setFetchSize` is not set.
21
30
  - **options**: extra JDBC properties (hash, default: {})
22
31
 
23
32
  ## Example
@@ -6,6 +6,7 @@ import java.sql.Driver;
6
6
  import java.sql.SQLException;
7
7
  import com.google.common.base.Throwables;
8
8
  import org.embulk.config.Config;
9
+ import org.embulk.config.ConfigDefault;
9
10
  import org.embulk.input.jdbc.AbstractJdbcInputPlugin;
10
11
  import org.embulk.input.mysql.MySQLInputConnection;
11
12
 
@@ -53,6 +54,15 @@ public class MySQLInputPlugin
53
54
  // break;
54
55
  //}
55
56
 
57
+ if (task.getFetchRows() == 1) {
58
+ logger.info("Fetch size is 1. Fetching rows one by one.");
59
+ } else if (task.getFetchRows() <= 0) {
60
+ logger.info("Fetch size is set to -1. Fetching all rows at once.");
61
+ } else {
62
+ logger.info("Fetch size is {}. Using server-side prepared statement.", task.getFetchRows());
63
+ props.setProperty("useCursorFetch", "true");
64
+ }
65
+
56
66
  props.putAll(task.getOptions());
57
67
 
58
68
  Driver driver;
@@ -3,6 +3,7 @@ package org.embulk.input.mysql;
3
3
  import java.sql.Connection;
4
4
  import java.sql.PreparedStatement;
5
5
  import java.sql.SQLException;
6
+ import java.sql.ResultSet;
6
7
  import org.embulk.input.jdbc.JdbcInputConnection;
7
8
 
8
9
  public class MySQLInputConnection
@@ -13,4 +14,22 @@ public class MySQLInputConnection
13
14
  {
14
15
  super(connection, null);
15
16
  }
17
+
18
+ @Override
19
+ protected BatchSelect newBatchSelect(String select, int fetchRows) throws SQLException
20
+ {
21
+ logger.info("SQL: " + select);
22
+ PreparedStatement stmt = connection.prepareStatement(select, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); // TYPE_FORWARD_ONLY and CONCUR_READ_ONLY are default
23
+ if (fetchRows == 1) {
24
+ // See MySQLInputPlugin.newConnection doesn't set useCursorFetch=true when fetchRows=1
25
+ // MySQL Connector/J keeps the connection opened and process rows one by one with Integer.MIN_VALUE.
26
+ stmt.setFetchSize(Integer.MIN_VALUE);
27
+ } else if (fetchRows <= 0) {
28
+ // uses the default behavior. MySQL Connector/J fetches the all rows in memory.
29
+ } else {
30
+ // useCursorFetch=true is enabled. MySQL creates temporary table and uses multiple select statements to fetch rows.
31
+ stmt.setFetchSize(fetchRows);
32
+ }
33
+ return new SingleSelect(stmt);
34
+ }
16
35
  }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: embulk-input-mysql
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - FURUHASHI Sadayuki
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-18 00:00:00.000000000 Z
11
+ date: 2015-02-19 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: JDBC input plugin is an Embulk plugin that loads records from JDBC so that any output plugins can receive the records. Search the output plugins by "embulk-output" keyword.
14
14
  email:
@@ -22,8 +22,8 @@ files:
22
22
  - lib/embulk/input/mysql.rb
23
23
  - src/main/java/org/embulk/input/MySQLInputPlugin.java
24
24
  - src/main/java/org/embulk/input/mysql/MySQLInputConnection.java
25
- - classpath/embulk-input-jdbc-0.2.1.jar
26
- - classpath/embulk-input-mysql-0.2.1.jar
25
+ - classpath/embulk-input-jdbc-0.2.2.jar
26
+ - classpath/embulk-input-mysql-0.2.2.jar
27
27
  - classpath/mysql-connector-java-5.1.34.jar
28
28
  homepage: https://github.com/embulk/embulk-input-jdbc
29
29
  licenses: