embulk-input-mysql 0.8.2 → 0.8.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ebead2dca4a8dbea335179c858c50dbcd1839f4f
4
- data.tar.gz: d0d6b855062b4dd108736bb9d8265ea5d7852dca
3
+ metadata.gz: ad515b3eb8f28906f971b7f53e5c509334955fa0
4
+ data.tar.gz: 10475eac9234df6f9849b4d548ae19cb25db7994
5
5
  SHA512:
6
- metadata.gz: 50a90da1581b48b554c0251d14696429a3009c4da03f770770381121464c785d2fdfc9af9e2a1d9d7fbb1c5f74547fbe24ec2e05bb817ef56089b3c490fa9735
7
- data.tar.gz: 818c791ca3394d1463c1b113a0ad163061d94eb69de93cfe4c0fef3fc2e80c90c029a2de5f0924be099844af4474977395dd2eca93e52e386f6adc2df88af427
6
+ metadata.gz: 99f8149f1a4b3ea926b17a1e2739050b410b4cbf8199ca2313bece1ded494e197f84bc9ed37c9830197232e30fa99578eb70f3202b232ac2813964c60faa3474
7
+ data.tar.gz: c794a8d86163720dc1c625f2fc2ea21a501004af2324a75fd065fdfdc0205cb5d29138ebec8a87b0ec8610bbbd3d488621e2e3ffb31730b2c3bd4c9e5d50b2b8
@@ -12,10 +12,12 @@ import com.mysql.jdbc.TimeUtil;
12
12
  import org.embulk.config.Config;
13
13
  import org.embulk.config.ConfigDefault;
14
14
  import org.embulk.input.jdbc.AbstractJdbcInputPlugin;
15
+ import org.embulk.input.jdbc.JdbcInputConnection;
15
16
  import org.embulk.input.jdbc.getter.ColumnGetterFactory;
16
17
  import org.embulk.input.mysql.MySQLInputConnection;
17
18
  import org.embulk.input.mysql.getter.MySQLColumnGetterFactory;
18
19
  import org.embulk.spi.PageBuilder;
20
+ import org.embulk.spi.Schema;
19
21
  import org.joda.time.DateTimeZone;
20
22
 
21
23
  public class MySQLInputPlugin
@@ -163,4 +165,13 @@ public class MySQLInputPlugin
163
165
  }
164
166
  }
165
167
  }
168
+
169
+ @Override
170
+ protected Schema setupTask(JdbcInputConnection con, PluginTask task) throws SQLException
171
+ {
172
+ MySQLInputConnection mySQLCon = (MySQLInputConnection)con;
173
+ mySQLCon.compareTimeZone();
174
+ return super.setupTask(con,task);
175
+ }
176
+
166
177
  }
@@ -0,0 +1,104 @@
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
+ }
@@ -9,6 +9,7 @@ import java.util.TimeZone;
9
9
 
10
10
  import com.mysql.jdbc.ConnectionImpl;
11
11
  import com.mysql.jdbc.ConnectionProperties;
12
+ import org.embulk.input.MySQLTimeZoneComparison;
12
13
  import org.embulk.input.jdbc.JdbcInputConnection;
13
14
  import org.embulk.input.jdbc.JdbcLiteral;
14
15
  import org.embulk.input.jdbc.getter.ColumnGetter;
@@ -59,4 +60,11 @@ public class MySQLInputConnection
59
60
  {
60
61
  return ((ConnectionImpl) connection).getServerTimezoneTZ();
61
62
  }
63
+
64
+ public void compareTimeZone() throws SQLException
65
+ {
66
+ MySQLTimeZoneComparison timeZoneComparison = new MySQLTimeZoneComparison(connection);
67
+ timeZoneComparison.compareTimeZone();
68
+ }
69
+
62
70
  }
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.2
4
+ version: 0.8.3
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-02-10 00:00:00.000000000 Z
11
+ date: 2017-05-26 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Selects records from a table.
14
14
  email:
@@ -19,11 +19,12 @@ extra_rdoc_files: []
19
19
  files:
20
20
  - README.md
21
21
  - build.gradle
22
- - classpath/embulk-input-jdbc-0.8.2.jar
23
- - classpath/embulk-input-mysql-0.8.2.jar
22
+ - classpath/embulk-input-jdbc-0.8.3.jar
23
+ - classpath/embulk-input-mysql-0.8.3.jar
24
24
  - classpath/mysql-connector-java-5.1.34.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
27
28
  - src/main/java/org/embulk/input/mysql/MySQLInputConnection.java
28
29
  - src/main/java/org/embulk/input/mysql/getter/AbstractMySQLTimestampIncrementalHandler.java
29
30
  - src/main/java/org/embulk/input/mysql/getter/MySQLColumnGetterFactory.java
Binary file