embulk-input-mysql 0.8.6 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (27) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -1
  3. data/build.gradle +2 -2
  4. data/classpath/{embulk-input-jdbc-0.8.6.jar → embulk-input-jdbc-0.9.0.jar} +0 -0
  5. data/classpath/embulk-input-mysql-0.9.0.jar +0 -0
  6. data/default_jdbc_driver/mysql-connector-java-5.1.44.jar +0 -0
  7. data/src/main/java/org/embulk/input/MySQLInputPlugin.java +8 -10
  8. data/src/main/java/org/embulk/input/mysql/MySQLInputConnection.java +19 -21
  9. data/src/main/java/org/embulk/input/mysql/getter/MySQLTimestampTimestampIncrementalHandler.java +1 -2
  10. data/src/test/resources/org/embulk/input/mysql/test/expect/basic/test_boolean_expected.csv +2 -2
  11. data/src/test/resources/org/embulk/input/mysql/test/expect/basic/test_double_expected.csv +2 -2
  12. data/src/test/resources/org/embulk/input/mysql/test/expect/basic/test_expected.csv +2 -2
  13. data/src/test/resources/org/embulk/input/mysql/test/expect/basic/test_long_expected.csv +2 -2
  14. data/src/test/resources/org/embulk/input/mysql/test/expect/basic/test_string_expected.csv +2 -2
  15. data/src/test/resources/org/embulk/input/mysql/test/expect/basic/test_timestamp1_expected.csv +2 -2
  16. data/src/test/resources/org/embulk/input/mysql/test/expect/basic/test_timestamp2_expected.csv +2 -2
  17. data/src/test/resources/org/embulk/input/mysql/test/expect/basic/test_timestamp3_expected.csv +2 -2
  18. data/src/test/resources/org/embulk/input/mysql/test/expect/basic/test_valuetype_decimal_expected.csv +2 -2
  19. data/src/test/resources/org/embulk/input/mysql/test/expect/basic/test_valuetype_string_expected.csv +2 -2
  20. data/src/test/resources/org/embulk/input/mysql/test/expect/incremental/dt/config_1.yml +0 -1
  21. data/src/test/resources/org/embulk/input/mysql/test/expect/incremental/dt/config_2.yml +0 -1
  22. data/src/test/resources/org/embulk/input/mysql/test/expect/incremental/ts/config_1.yml +0 -1
  23. data/src/test/resources/org/embulk/input/mysql/test/expect/incremental/ts/config_2.yml +0 -1
  24. metadata +5 -6
  25. data/classpath/embulk-input-mysql-0.8.6.jar +0 -0
  26. data/default_jdbc_driver/mysql-connector-java-5.1.34.jar +0 -0
  27. data/src/main/java/org/embulk/input/MySQLTimeZoneComparison.java +0 -104
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 82ffc53340f2ef0742c4aa00830de1b59f22dd99
4
- data.tar.gz: f33c36841481d1dc53d1aa4691492cbb0d21b147
3
+ metadata.gz: b521bd3bf2c7c3af6fa853b40fc0bd7f683f2738
4
+ data.tar.gz: 4d57d69e285042efb51258bf07f8549d0c633f45
5
5
  SHA512:
6
- metadata.gz: f293f9ac8219eef1ec152ce8637357132a3be1dd1708a777b2d8331936af8d2d4381ac8fe763a780fcf7a818070d96537f3eee191e7ebe30d1cbd199f857c7de
7
- data.tar.gz: c404695b1c2d45d810ff892848ea679c039e8009f0c73d2c26f68127d3666c93114f70f4baecf7edb5797409f9270e450bf1be2afda400fab490b48c39e510f2
6
+ metadata.gz: 638469a4ddaf6c601382e43747790e9aa7c39b8c61940605234dc5fe75ee784d2285c45f484f93ca0aa35ec16007b46a406b5c0b580d55c01a08d5a9dba72e02
7
+ data.tar.gz: fbd4b7a01f882844ef3d0efaabd6ea545fafaaaafbfa26167282d0f5da6085da720fad5c41a677d89a5b83e33c6a15068464a68d59f1b6c55470285e97791112
data/README.md CHANGED
@@ -9,7 +9,7 @@ MySQL input plugin for Embulk loads records from MySQL.
9
9
 
10
10
  ## Configuration
11
11
 
12
- - **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)
12
+ - **driver_path**: path to the jar file of the MySQL JDBC driver. If not set, the bundled JDBC driver (MySQL Connector/J 5.1.44) will be used (string). NOTE: embulk-input-mysql 0.9.0 upgraded the bundled MySQL Connector/J version from 5.1.34 to 5.1.44 . And set useLegacyDatetimeCode=false by default in order to get correct datetime value when the server timezone and the client timezone are different. Set useLegacyDatetimeCode=true if you need to get datetime value same as older embulk-input-mysql.
13
13
  - **host**: database host name (string, required)
14
14
  - **port**: database port number (integer, 3306)
15
15
  - **user**: database login user name (string, required)
@@ -39,6 +39,7 @@ MySQL input plugin for Embulk loads records from MySQL.
39
39
  - **incremental_columns**: column names for incremental loading (array of strings, default: use primary keys)
40
40
  - **last_record**: values of the last record for incremental loading (array of objects, default: load all records)
41
41
  - **default_timezone**: If the sql type of a column is `date`/`time`/`datetime` and the embulk type is `string`, column values are formatted int this default_timezone. You can overwrite timezone for each columns using column_options option. (string, default: `UTC`)
42
+ - **use_legacy_datetime_code**: recommended not to set the property (boolean, default: false). If true, embulk-output-mysql will get wrong datetime values when the server timezone and the client server timezone are different as older embulk-output-mysql did.
42
43
  - **column_options**: advanced: a key-value pairs where key is a column name and value is options for the column.
43
44
  - **value_type**: embulk get values from database as this value_type. Typically, the value_type determines `getXXX` method of `java.sql.PreparedStatement`.
44
45
  (string, default: depends on the sql type of the column. Available values options are: `long`, `double`, `float`, `decimal`, `boolean`, `string`, `json`, `date`, `time`, `timestamp`)
@@ -1,8 +1,8 @@
1
1
  dependencies {
2
2
  compile project(':embulk-input-jdbc')
3
3
 
4
- compile 'mysql:mysql-connector-java:5.1.34'
5
- defaultJdbcDriver 'mysql:mysql-connector-java:5.1.34'
4
+ compile 'mysql:mysql-connector-java:5.1.44'
5
+ defaultJdbcDriver 'mysql:mysql-connector-java:5.1.44'
6
6
 
7
7
  testCompile 'org.embulk:embulk-standards:0.8.15'
8
8
  }
@@ -14,12 +14,10 @@ import org.embulk.config.Config;
14
14
  import org.embulk.config.ConfigDefault;
15
15
  import org.embulk.input.jdbc.AbstractJdbcInputPlugin;
16
16
  import org.embulk.input.jdbc.Ssl;
17
- import org.embulk.input.jdbc.JdbcInputConnection;
18
17
  import org.embulk.input.jdbc.getter.ColumnGetterFactory;
19
18
  import org.embulk.input.mysql.MySQLInputConnection;
20
19
  import org.embulk.input.mysql.getter.MySQLColumnGetterFactory;
21
20
  import org.embulk.spi.PageBuilder;
22
- import org.embulk.spi.Schema;
23
21
  import org.joda.time.DateTimeZone;
24
22
 
25
23
  public class MySQLInputPlugin
@@ -52,6 +50,10 @@ public class MySQLInputPlugin
52
50
  @Config("ssl")
53
51
  @ConfigDefault("\"disable\"") // backward compatibility
54
52
  public Ssl getSsl();
53
+
54
+ @Config("use_legacy_datetime_code")
55
+ @ConfigDefault("false")
56
+ public boolean getUseLegacyDatetimeCode();
55
57
  }
56
58
 
57
59
  @Override
@@ -103,6 +105,9 @@ public class MySQLInputPlugin
103
105
  break;
104
106
  }
105
107
 
108
+ // NOTE:The useLegacyDatetimeCode option is obsolete in the MySQL Connector/J 6.
109
+ props.setProperty("useLegacyDatetimeCode", String.valueOf(t.getUseLegacyDatetimeCode()));
110
+
106
111
  if (t.getFetchRows() == 1) {
107
112
  logger.info("Fetch size is 1. Fetching rows one by one.");
108
113
  } else if (t.getFetchRows() <= 0) {
@@ -113,6 +118,7 @@ public class MySQLInputPlugin
113
118
  }
114
119
 
115
120
  props.putAll(t.getOptions());
121
+ logConnectionProperties(url, props);
116
122
 
117
123
  // load timezone mappings
118
124
  loadTimeZoneMappings();
@@ -172,12 +178,4 @@ public class MySQLInputPlugin
172
178
  }
173
179
  }
174
180
 
175
- @Override
176
- protected Schema setupTask(JdbcInputConnection con, PluginTask task) throws SQLException
177
- {
178
- MySQLInputConnection mySQLCon = (MySQLInputConnection)con;
179
- mySQLCon.compareTimeZone();
180
- return super.setupTask(con,task);
181
- }
182
-
183
181
  }
@@ -1,15 +1,13 @@
1
1
  package org.embulk.input.mysql;
2
2
 
3
3
  import java.util.List;
4
+ import java.lang.reflect.Method;
4
5
  import java.sql.Connection;
5
6
  import java.sql.PreparedStatement;
6
7
  import java.sql.SQLException;
7
8
  import java.sql.ResultSet;
8
9
  import java.util.TimeZone;
9
10
 
10
- import com.mysql.jdbc.ConnectionImpl;
11
- import com.mysql.jdbc.ConnectionProperties;
12
- import org.embulk.input.MySQLTimeZoneComparison;
13
11
  import org.embulk.input.jdbc.JdbcInputConnection;
14
12
  import org.embulk.input.jdbc.JdbcLiteral;
15
13
  import org.embulk.input.jdbc.getter.ColumnGetter;
@@ -53,33 +51,33 @@ public class MySQLInputConnection
53
51
 
54
52
  public boolean getUseLegacyDatetimeCode()
55
53
  {
56
- return ((ConnectionProperties) connection).getUseLegacyDatetimeCode();
54
+ try {
55
+ Class<?> connectionPropertiesClass = Class.forName("com.mysql.jdbc.ConnectionProperties");
56
+ Method getUseLegacyDatetimeCodeMethod = connectionPropertiesClass.getMethod("getUseLegacyDatetimeCode");
57
+ return (Boolean)getUseLegacyDatetimeCodeMethod.invoke(connection);
58
+
59
+ } catch (Exception e) {
60
+ throw new RuntimeException(e);
61
+ }
57
62
  }
58
63
 
59
64
  public TimeZone getServerTimezoneTZ()
60
65
  {
61
- return ((ConnectionImpl) connection).getServerTimezoneTZ();
62
- }
66
+ try {
67
+ Class<?> connectionImplClass = Class.forName("com.mysql.jdbc.ConnectionImpl");
68
+ Method getServerTimezoneTZMethod = connectionImplClass.getMethod("getServerTimezoneTZ");
69
+ return (TimeZone)getServerTimezoneTZMethod.invoke(connection);
63
70
 
64
- public void compareTimeZone() throws SQLException
65
- {
66
- MySQLTimeZoneComparison timeZoneComparison = new MySQLTimeZoneComparison(connection);
67
- timeZoneComparison.compareTimeZone();
71
+ } catch (Exception e) {
72
+ throw new RuntimeException(e);
73
+ }
68
74
  }
69
75
 
70
- //
71
- //
72
- // The MySQL Connector/J 5.1.35 introduce new option `Current MySQL Connect`.
73
- // It has incompatibility behavior current version and 5.1.35.
74
- //
75
- // This method announces users about this change before the update driver version.
76
- //
77
76
  @Override
78
77
  public void showDriverVersion() throws SQLException {
79
78
  super.showDriverVersion();
80
- logger.warn("This plugin will update MySQL Connector/J version in the near future release.");
81
- logger.warn("It has some incompatibility changes.");
82
- logger.warn("For example, the 5.1.35 introduced `noTimezoneConversionForDateType` and `cacheDefaultTimezone` options.");
83
- logger.warn("Please read a document and make sure configuration carefully before updating the plugin.");
79
+ logger.warn("embulk-input-mysql 0.9.0 upgraded the bundled MySQL Connector/J version from 5.1.34 to 5.1.44 .");
80
+ logger.warn("And set useLegacyDatetimeCode=false by default in order to get correct datetime value when the server timezone and the client timezone are different.");
81
+ logger.warn("Set useLegacyDatetimeCode=true if you need to get datetime value same as older embulk-input-mysql.");
84
82
  }
85
83
  }
@@ -22,8 +22,7 @@ public class MySQLTimestampTimestampIncrementalHandler
22
22
  @Override
23
23
  public org.embulk.spi.time.Timestamp utcTimestampFromSessionTime(long epochSecond, int nano)
24
24
  {
25
- long sec = sessionTimeZone.convertLocalToUTC(epochSecond * 1000, false) / 1000;
26
- return org.embulk.spi.time.Timestamp.ofEpochSecond(sec, nano);
25
+ return org.embulk.spi.time.Timestamp.ofEpochSecond(epochSecond, nano);
27
26
  }
28
27
 
29
28
  @Override
@@ -1,2 +1,2 @@
1
- 10,,,,,,,,,,,,,2015-06-04 20:45:06.000000 +0000,,
2
- 11,true,true,false,false,true,true,false,true,,,2015-06-03 21:00:00.000000 +0000,2015-06-04 09:34:56.000000 +0000,2015-06-04 20:45:06.000000 +0000,1970-01-01 06:04:02.000000 +0000,2015-06-03 22:02:03.123456 +0000
1
+ 10,,,,,,,,,,,,,2015-06-04 23:45:06.000000 +0000,,
2
+ 11,true,true,false,false,true,true,false,true,,,2015-06-03 21:00:00.000000 +0000,2015-06-04 12:34:56.000000 +0000,2015-06-04 23:45:06.000000 +0000,1970-01-01 06:04:02.000000 +0000,2015-06-04 01:02:03.123456 +0000
@@ -1,2 +1,2 @@
1
- 10,,,,,,,,,,,,,2015-06-04 20:45:06.000000 +0000,,
2
- 11,99.0,9999.0,-9.9999999E7,-1.0E16,1.2345000505447388,1.234567890123,-1234.0,1.2345678901234568E17,5678.0,,2015-06-03 21:00:00.000000 +0000,2015-06-04 09:34:56.000000 +0000,2015-06-04 20:45:06.000000 +0000,1970-01-01 06:04:02.000000 +0000,2015-06-03 22:02:03.123456 +0000
1
+ 10,,,,,,,,,,,,,2015-06-04 23:45:06.000000 +0000,,
2
+ 11,99.0,9999.0,-9.9999999E7,-1.0E16,1.2345000505447388,1.234567890123,-1234.0,1.2345678901234568E17,5678.0,,2015-06-03 21:00:00.000000 +0000,2015-06-04 12:34:56.000000 +0000,2015-06-04 23:45:06.000000 +0000,1970-01-01 06:04:02.000000 +0000,2015-06-04 01:02:03.123456 +0000
@@ -1,2 +1,2 @@
1
- 10,,,,,,,,,,,,,2015-06-04 20:45:06.000000 +0000,,
2
- 11,99,9999,-99999999,-9999999999999999,1.2345000505447388,1.234567890123,-1234.0,1.2345678901234568E17,5678,xy,2015-06-03 21:00:00.000000 +0000,2015-06-04 09:34:56.000000 +0000,2015-06-04 20:45:06.000000 +0000,1970-01-01 06:04:02.000000 +0000,2015-06-03 22:02:03.123456 +0000
1
+ 10,,,,,,,,,,,,,2015-06-04 23:45:06.000000 +0000,,
2
+ 11,99,9999,-99999999,-9999999999999999,1.2345000505447388,1.234567890123,-1234.0,1.2345678901234568E17,5678,xy,2015-06-03 21:00:00.000000 +0000,2015-06-04 12:34:56.000000 +0000,2015-06-04 23:45:06.000000 +0000,1970-01-01 06:04:02.000000 +0000,2015-06-04 01:02:03.123456 +0000
@@ -1,2 +1,2 @@
1
- 10,,,,,,,,,,,,,2015-06-04 20:45:06.000000 +0000,,
2
- 11,99,9999,-99999999,-9999999999999999,1,1,-1234,123456789012345678,5678,,2015-06-03 21:00:00.000000 +0000,2015-06-04 09:34:56.000000 +0000,2015-06-04 20:45:06.000000 +0000,1970-01-01 06:04:02.000000 +0000,2015-06-03 22:02:03.123456 +0000
1
+ 10,,,,,,,,,,,,,2015-06-04 23:45:06.000000 +0000,,
2
+ 11,99,9999,-99999999,-9999999999999999,1,1,-1234,123456789012345678,5678,,2015-06-03 21:00:00.000000 +0000,2015-06-04 12:34:56.000000 +0000,2015-06-04 23:45:06.000000 +0000,1970-01-01 06:04:02.000000 +0000,2015-06-04 01:02:03.123456 +0000
@@ -1,2 +1,2 @@
1
- 10,,,,,,,,,,,,,2015-06-04 20:45:06.000000 +0000,,
2
- 11,99,9999,-99999999,-9999999999999999,1.2345,1.234567890123,-1234,123456789012345678.12,5678,xy,2015-06-03 21:00:00.000000 +0000,2015-06-04 09:34:56.000000 +0000,2015-06-04 20:45:06.000000 +0000,1970-01-01 06:04:02.000000 +0000,2015-06-03 22:02:03.123456 +0000
1
+ 10,,,,,,,,,,,,,2015-06-04 23:45:06.000000 +0000,,
2
+ 11,99,9999,-99999999,-9999999999999999,1.2345,1.234567890123,-1234,123456789012345678.12,5678,xy,2015-06-03 21:00:00.000000 +0000,2015-06-04 12:34:56.000000 +0000,2015-06-04 23:45:06.000000 +0000,1970-01-01 06:04:02.000000 +0000,2015-06-04 01:02:03.123456 +0000
@@ -1,2 +1,2 @@
1
- 10,,,,,,,,,,,,,2015-06-04 20:45:06.000000 +0000,,
2
- 11,99,9999,-99999999,-9999999999999999,1.2345000505447388,1.234567890123,-1234.0,1.2345678901234568E17,5678,xy,2015-06-03 21:00:00.000000 +0000,2015-06-04 09:34:56.000000 +0000,2015-06-04 20:45:06.000000 +0000,1970-01-01 06:04:02.000000 +0000,2015-06-03 22:02:03.123456 +0000
1
+ 10,,,,,,,,,,,,,2015-06-04 23:45:06.000000 +0000,,
2
+ 11,99,9999,-99999999,-9999999999999999,1.2345000505447388,1.234567890123,-1234.0,1.2345678901234568E17,5678,xy,2015-06-03 21:00:00.000000 +0000,2015-06-04 12:34:56.000000 +0000,2015-06-04 23:45:06.000000 +0000,1970-01-01 06:04:02.000000 +0000,2015-06-04 01:02:03.123456 +0000
@@ -1,2 +1,2 @@
1
- 10,,,,,,,,,,,,,2015/06/05 05:45:06,,
2
- 11,99,9999,-99999999,-9999999999999999,1.2345000505447388,1.234567890123,-1234.0,1.2345678901234568E17,5678,xy,2015/06/03,2015/06/04 09:34:56,2015/06/05 05:45:06,15-04-02,2015/06/03 22:02:03.123456
1
+ 10,,,,,,,,,,,,,2015/06/05 08:45:06,,
2
+ 11,99,9999,-99999999,-9999999999999999,1.2345000505447388,1.234567890123,-1234.0,1.2345678901234568E17,5678,xy,2015/06/03,2015/06/04 12:34:56,2015/06/05 08:45:06,15-04-02,2015/06/04 01:02:03.123456
@@ -1,2 +1,2 @@
1
- 10,,,,,,,,,,,,,2015/06/05 05:45:06,,
2
- 11,99,9999,-99999999,-9999999999999999,1.2345000505447388,1.234567890123,-1234.0,1.2345678901234568E17,5678,xy,2015/06/04,2015/06/04 18:34:56,2015/06/05 05:45:06,09-04-02,2015/06/04 07:02:03.123456
1
+ 10,,,,,,,,,,,,,2015/06/05 08:45:06,,
2
+ 11,99,9999,-99999999,-9999999999999999,1.2345000505447388,1.234567890123,-1234.0,1.2345678901234568E17,5678,xy,2015/06/04,2015/06/04 21:34:56,2015/06/05 08:45:06,09-04-02,2015/06/04 10:02:03.123456
@@ -1,2 +1,2 @@
1
- 10,,,,,,,,,,,,,2015-06-04 20:45:06.000000 +0000,,
2
- 11,99.0,9999,-99999999,-9999999999999999,1.2345000505447388,1.234567890123,-1234.0,1.2345678901234568E17,5678,xy,2015-06-03 21:00:00.000000 +0000,2015-06-04 09:34:56.000000 +0000,2015-06-04 20:45:06.000000 +0000,1970-01-01 06:04:02.000000 +0000,2015-06-03 22:02:03.123456 +0000
1
+ 10,,,,,,,,,,,,,2015-06-04 23:45:06.000000 +0000,,
2
+ 11,99.0,9999,-99999999,-9999999999999999,1.2345000505447388,1.234567890123,-1234.0,1.2345678901234568E17,5678,xy,2015-06-03 21:00:00.000000 +0000,2015-06-04 12:34:56.000000 +0000,2015-06-04 23:45:06.000000 +0000,1970-01-01 06:04:02.000000 +0000,2015-06-04 01:02:03.123456 +0000
@@ -1,2 +1,2 @@
1
- 10,,,,,,,,,,,,,2015-06-04 20:45:06.000000 +0000,,
2
- 11,99,9999,-99999999,-9999999999999999,1.2345000505447388,1.234567890123,-1234.0,1.2345678901234568E17,5678,xy,2015-06-03 21:00:00.000000 +0000,2015-06-04 09:34:56.000000 +0000,2015-06-04 20:45:06.000000 +0000,1970-01-01 06:04:02.000000 +0000,2015-06-03 22:02:03.123456 +0000
1
+ 10,,,,,,,,,,,,,2015-06-04 23:45:06.000000 +0000,,
2
+ 11,99,9999,-99999999,-9999999999999999,1.2345000505447388,1.234567890123,-1234.0,1.2345678901234568E17,5678,xy,2015-06-03 21:00:00.000000 +0000,2015-06-04 12:34:56.000000 +0000,2015-06-04 23:45:06.000000 +0000,1970-01-01 06:04:02.000000 +0000,2015-06-04 01:02:03.123456 +0000
@@ -1,5 +1,4 @@
1
1
  table: dt_load
2
2
  default_time_zone: +0300 # should be ignored
3
- options: {useLegacyDatetimeCode: false}
4
3
  incremental: true
5
4
  incremental_columns: [time]
@@ -1,5 +1,4 @@
1
1
  table: dt_load
2
- options: {useLegacyDatetimeCode: false}
3
2
  last_record: ['2016-11-02T04:00:05.333003']
4
3
  incremental: true
5
4
  incremental_columns: [time]
@@ -1,5 +1,4 @@
1
1
  table: ts_load
2
2
  default_time_zone: +0300 # should be ignored
3
- options: {useLegacyDatetimeCode: false}
4
3
  incremental: true
5
4
  incremental_columns: [time]
@@ -1,5 +1,4 @@
1
1
  table: ts_load
2
- options: {useLegacyDatetimeCode: false}
3
2
  last_record: ['2016-11-02T04:00:05.333003Z']
4
3
  incremental: true
5
4
  incremental_columns: [time]
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.8.6
4
+ version: 0.9.0
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-27 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Selects records from a table.
14
14
  email:
@@ -19,12 +19,11 @@ extra_rdoc_files: []
19
19
  files:
20
20
  - README.md
21
21
  - build.gradle
22
- - classpath/embulk-input-jdbc-0.8.6.jar
23
- - classpath/embulk-input-mysql-0.8.6.jar
24
- - default_jdbc_driver/mysql-connector-java-5.1.34.jar
22
+ - classpath/embulk-input-jdbc-0.9.0.jar
23
+ - classpath/embulk-input-mysql-0.9.0.jar
24
+ - default_jdbc_driver/mysql-connector-java-5.1.44.jar
25
25
  - lib/embulk/input/mysql.rb
26
26
  - src/main/java/org/embulk/input/MySQLInputPlugin.java
27
- - src/main/java/org/embulk/input/MySQLTimeZoneComparison.java
28
27
  - src/main/java/org/embulk/input/mysql/MySQLInputConnection.java
29
28
  - src/main/java/org/embulk/input/mysql/getter/AbstractMySQLTimestampIncrementalHandler.java
30
29
  - src/main/java/org/embulk/input/mysql/getter/MySQLColumnGetterFactory.java
@@ -1,104 +0,0 @@
1
- package org.embulk.input;
2
-
3
- import org.embulk.spi.Exec;
4
- import org.slf4j.Logger;
5
-
6
- import java.sql.Connection;
7
- import java.sql.ResultSet;
8
- import java.sql.SQLException;
9
- import java.sql.Statement;
10
- import java.util.Date;
11
- import java.util.Locale;
12
- import java.util.TimeZone;
13
-
14
- public class MySQLTimeZoneComparison
15
- {
16
- private static final int ONE_HOUR_SEC = 3600;
17
- private static final int ONE_MIN_SEC = 60;
18
-
19
- private Connection connection;
20
-
21
- private final Logger logger = Exec.getLogger(getClass());
22
-
23
- public MySQLTimeZoneComparison(Connection connection)
24
- {
25
- this.connection = connection;
26
- }
27
-
28
- public void compareTimeZone()
29
- throws SQLException
30
- {
31
- TimeZone serverTimeZone = null;
32
- try {
33
- serverTimeZone = getServerTimeZone();
34
- }
35
- catch (SQLException ex) {
36
- logger.warn("Can't get server TimeZone.");
37
- logger.warn(String.format(Locale.ENGLISH, "SQLException raised %s", ex.toString()));
38
- }
39
-
40
- TimeZone clientTimeZone = TimeZone.getDefault();
41
- Date today = new Date();
42
- int clientOffset = clientTimeZone.getRawOffset();
43
-
44
- if (clientTimeZone.inDaylightTime(today)) {
45
- clientOffset += clientTimeZone.getDSTSavings();
46
- }
47
-
48
- //
49
- // Compare offset only. Although I expect to return true, the following code return false,
50
- //
51
- // TimeZone tz_jst = TimeZone.getTimeZone("JST");
52
- // TimeZone tz_gmt9 = TimeZone.getTimeZone("GMT+9");
53
- // tz_jst.hasSameRules(tz_gmt9) // return false.
54
- //
55
- if (clientOffset != serverTimeZone.getRawOffset()) {
56
- logger.warn(String.format(Locale.ENGLISH,
57
- "The client timezone(%s) is different from the server timezone(%s). The plugin will fetch wrong datetime values.",
58
- clientTimeZone.getID(), serverTimeZone.getID()));
59
- logger.warn(String.format(Locale.ENGLISH,
60
- "You may need to set options `useLegacyDatetimeCode` and `serverTimezone`"));
61
- logger.warn(String.format(Locale.ENGLISH,
62
- "Example. `options: { useLegacyDatetimeCode: false, serverTimezone: UTC }`"));
63
- }
64
- logger.warn(String.format(Locale.ENGLISH, "The plugin will set `useLegacyDatetimeCode=false` by default in future."));
65
- }
66
-
67
- private TimeZone getServerTimeZone()
68
- throws SQLException
69
- {
70
- //
71
- // First, I used `@@system_time_zone`. but It return non Time Zone Abbreviations name on a specific platform.
72
- // So, This method calculate GMT offset with query.
73
- //
74
- String query = "select TIME_TO_SEC(timediff(now(),utc_timestamp()));";
75
- Statement stmt = connection.createStatement();
76
-
77
- try {
78
- ResultSet rs = stmt.executeQuery(query);
79
- if (rs.next()) {
80
- int offsetSeconds = rs.getInt(1);
81
- return fromGMTOffsetSeconds(offsetSeconds);
82
- }
83
- throw new SQLException(String.format(Locale.ENGLISH,
84
- "The timezone comparison query(%s) doesn't return the result.",query));
85
- }
86
- finally {
87
- stmt.close();
88
- }
89
- }
90
-
91
- private TimeZone fromGMTOffsetSeconds(int offsetSeconds)
92
- {
93
- if (offsetSeconds == 0) {
94
- return TimeZone.getTimeZone("UTC");
95
- }
96
-
97
- String sign = offsetSeconds > 0 ? "+" : "-";
98
- int absOffsetSec = Math.abs(offsetSeconds);
99
- int tzHour = absOffsetSec / ONE_HOUR_SEC;
100
- int tzMin = absOffsetSec % ONE_HOUR_SEC / ONE_MIN_SEC;
101
- String tzName = String.format(Locale.ENGLISH, "GMT%s%02d:%02d", sign, tzHour, tzMin);
102
- return TimeZone.getTimeZone(tzName);
103
- }
104
- }