embulk-input-mysql 0.9.2 → 0.9.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +34 -0
- data/classpath/embulk-input-jdbc-0.9.3.jar +0 -0
- data/classpath/{embulk-input-mysql-0.9.2.jar → embulk-input-mysql-0.9.3.jar} +0 -0
- data/src/test/java/org/embulk/input/mysql/IncrementalTest.java +40 -0
- data/src/test/resources/org/embulk/input/mysql/test/expect/incremental/query/config_1.yml +14 -0
- data/src/test/resources/org/embulk/input/mysql/test/expect/incremental/query/config_2.yml +14 -0
- data/src/test/resources/org/embulk/input/mysql/test/expect/incremental/query/expected_1.csv +4 -0
- data/src/test/resources/org/embulk/input/mysql/test/expect/incremental/query/expected_1.diff +3 -0
- data/src/test/resources/org/embulk/input/mysql/test/expect/incremental/query/expected_2.csv +2 -0
- data/src/test/resources/org/embulk/input/mysql/test/expect/incremental/query/expected_2.diff +3 -0
- data/src/test/resources/org/embulk/input/mysql/test/expect/incremental/query/insert_more.sql +6 -0
- data/src/test/resources/org/embulk/input/mysql/test/expect/incremental/query/multi_columns_config_1.yml +16 -0
- data/src/test/resources/org/embulk/input/mysql/test/expect/incremental/query/multi_columns_config_2.yml +17 -0
- data/src/test/resources/org/embulk/input/mysql/test/expect/incremental/query/multi_columns_expected_1.csv +4 -0
- data/src/test/resources/org/embulk/input/mysql/test/expect/incremental/query/multi_columns_expected_1.diff +3 -0
- data/src/test/resources/org/embulk/input/mysql/test/expect/incremental/query/multi_columns_expected_2.csv +2 -0
- data/src/test/resources/org/embulk/input/mysql/test/expect/incremental/query/multi_columns_expected_2.diff +3 -0
- data/src/test/resources/org/embulk/input/mysql/test/expect/incremental/query/setup.sql +13 -0
- metadata +18 -4
- data/classpath/embulk-input-jdbc-0.9.2.jar +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 744e51df72489a3bf53272c5df5d459ba838489e
|
4
|
+
data.tar.gz: 9df128d4fa0b33718b3db3c6407a184bc3f699b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5951714019851189f8992454620fcbeb8ed070aabf8051f480764a9b39dfbaa8fa73dcd2eb1f4442dab9d6b428363881cce9ca50f67c5ed435ca7ab63a646e38
|
7
|
+
data.tar.gz: ca3690c6eed9cff67728fd99e65afe21a57a74e05919a9fb72c8538e7b4de7136777b90a05793d60098d8dbfdeabbb91cefbab712a15ddb86b139f1d06b5aea5
|
data/README.md
CHANGED
@@ -17,6 +17,7 @@ MySQL input plugin for Embulk loads records from MySQL.
|
|
17
17
|
- **database**: destination database name (string, required)
|
18
18
|
- If you write SQL directly,
|
19
19
|
- **query**: SQL to run (string)
|
20
|
+
- **use_raw_query_with_incremental**: If true, you can write optimized query using prepared statement by yourself. See [Use incremental loading with raw query](#use-incremental-loading-with-raw-query) for more detail (boolean, default: false)
|
20
21
|
- If **query** is not set,
|
21
22
|
- **table**: destination table name (string, required)
|
22
23
|
- **select**: expression of select (e.g. `id, created_at`) (string, default: "*")
|
@@ -92,6 +93,39 @@ Recommended usage is to leave `incremental_columns` unset and let this plugin au
|
|
92
93
|
|
93
94
|
- If you get an exception 'The server time zone value XXX is unrecognized ...', please set proper time zone to the MySQL server or set `true` to the `use_legacy_datetime_code` property.
|
94
95
|
|
96
|
+
### Use incremental loading with raw query
|
97
|
+
|
98
|
+
**IMPORTANT**: This is an advanced feature and assume you have an enough knowledge about incremental loading using Embulk and this plugin
|
99
|
+
|
100
|
+
Normally, you can't write your own query for incremental loading.
|
101
|
+
`use_raw_query_with_incremental` option allow you to write raw query for incremental loading. It might be well optimized and faster than SQL statement which is automatically generated by plugin.
|
102
|
+
|
103
|
+
Prepared statement starts with `:` is available instead of fixed value.
|
104
|
+
`last_record` value is necessary when you use this option.
|
105
|
+
Please use prepared statement that is well distinguishable in SQL statement. Using too simple prepared statement like `:a` might cause SQL parse failure.
|
106
|
+
|
107
|
+
In the following example, prepared statement `:foo_id` will be replaced with value "1" which is specified in `last_record`.
|
108
|
+
|
109
|
+
```yaml
|
110
|
+
in:
|
111
|
+
type: mysql
|
112
|
+
query:
|
113
|
+
SELECT
|
114
|
+
foo.id as foo_id, bar.name
|
115
|
+
FROM
|
116
|
+
foo LEFT JOIN bar ON foo.id = bar.id
|
117
|
+
WHERE
|
118
|
+
foo.hoge IS NOT NULL
|
119
|
+
AND foo.id > :foo_id
|
120
|
+
ORDER BY
|
121
|
+
foo.id ASC
|
122
|
+
use_raw_query_with_incremental: true
|
123
|
+
incremental_columns:
|
124
|
+
- foo_id
|
125
|
+
incremental: true
|
126
|
+
last_record: [1]
|
127
|
+
```
|
128
|
+
|
95
129
|
## Example
|
96
130
|
|
97
131
|
```yaml
|
Binary file
|
Binary file
|
@@ -104,4 +104,44 @@ public class IncrementalTest
|
|
104
104
|
assertThat(readSortedFile(out2), is(readResource("ts/expected_2.csv")));
|
105
105
|
assertThat(result2.getConfigDiff(), is((ConfigDiff) loadYamlResource(embulk, "ts/expected_2.diff")));
|
106
106
|
}
|
107
|
+
|
108
|
+
@Test
|
109
|
+
public void testQueryWithPlaceholder() throws Exception
|
110
|
+
{
|
111
|
+
// setup first rows
|
112
|
+
execute(readResource("query/setup.sql"));
|
113
|
+
|
114
|
+
Path out1 = embulk.createTempFile("csv");
|
115
|
+
RunResult result1 = embulk.runInput(baseConfig.merge(loadYamlResource(embulk, "query/config_1.yml")), out1);
|
116
|
+
assertThat(readSortedFile(out1), is(readResource("query/expected_1.csv")));
|
117
|
+
assertThat(result1.getConfigDiff(), is((ConfigDiff) loadYamlResource(embulk, "query/expected_1.diff")));
|
118
|
+
|
119
|
+
// insert more rows
|
120
|
+
execute(readResource("query/insert_more.sql"));
|
121
|
+
|
122
|
+
Path out2 = embulk.createTempFile("csv");
|
123
|
+
RunResult result2 = embulk.runInput(baseConfig.merge(loadYamlResource(embulk, "query/config_2.yml")), out2);
|
124
|
+
assertThat(readSortedFile(out2), is(readResource("query/expected_2.csv")));
|
125
|
+
assertThat(result2.getConfigDiff(), is((ConfigDiff) loadYamlResource(embulk, "query/expected_2.diff")));
|
126
|
+
}
|
127
|
+
|
128
|
+
@Test
|
129
|
+
public void testQueryWithPlaceholderAndMultiColumns() throws Exception
|
130
|
+
{
|
131
|
+
// setup first rows
|
132
|
+
execute(readResource("query/setup.sql"));
|
133
|
+
|
134
|
+
Path out1 = embulk.createTempFile("csv");
|
135
|
+
RunResult result1 = embulk.runInput(baseConfig.merge(loadYamlResource(embulk, "query/multi_columns_config_1.yml")), out1);
|
136
|
+
assertThat(readSortedFile(out1), is(readResource("query/multi_columns_expected_1.csv")));
|
137
|
+
assertThat(result1.getConfigDiff(), is((ConfigDiff) loadYamlResource(embulk, "query/multi_columns_expected_1.diff")));
|
138
|
+
|
139
|
+
// insert more rows
|
140
|
+
execute(readResource("query/insert_more.sql"));
|
141
|
+
|
142
|
+
Path out2 = embulk.createTempFile("csv");
|
143
|
+
RunResult result2 = embulk.runInput(baseConfig.merge(loadYamlResource(embulk, "query/multi_columns_config_2.yml")), out2);
|
144
|
+
assertThat(readSortedFile(out2), is(readResource("query/multi_columns_expected_2.csv")));
|
145
|
+
assertThat(result2.getConfigDiff(), is((ConfigDiff) loadYamlResource(embulk, "query/multi_columns_expected_2.diff")));
|
146
|
+
}
|
107
147
|
}
|
@@ -0,0 +1,16 @@
|
|
1
|
+
last_record: [0,0]
|
2
|
+
incremental: true
|
3
|
+
incremental_columns: [num,num2]
|
4
|
+
use_raw_query_with_incremental: true
|
5
|
+
query: |
|
6
|
+
SELECT
|
7
|
+
*
|
8
|
+
FROM
|
9
|
+
query_load
|
10
|
+
WHERE
|
11
|
+
num IS NOT NULL
|
12
|
+
AND num > :num
|
13
|
+
OR (num = :num AND num2 > :num2)
|
14
|
+
ORDER BY
|
15
|
+
num ASC,
|
16
|
+
num2 ASC
|
@@ -0,0 +1,17 @@
|
|
1
|
+
last_record: [4,104]
|
2
|
+
incremental: true
|
3
|
+
incremental_columns: [num,num2]
|
4
|
+
use_raw_query_with_incremental: true
|
5
|
+
query: |
|
6
|
+
SELECT
|
7
|
+
*
|
8
|
+
FROM
|
9
|
+
query_load
|
10
|
+
WHERE
|
11
|
+
num IS NOT NULL
|
12
|
+
AND num > :num
|
13
|
+
AND num2 IS NOT NULL
|
14
|
+
OR (num = :num AND num2 > :num2)
|
15
|
+
ORDER BY
|
16
|
+
num ASC,
|
17
|
+
num2 ASC
|
@@ -0,0 +1,13 @@
|
|
1
|
+
drop table if exists query_load;
|
2
|
+
|
3
|
+
create table query_load (
|
4
|
+
num int not null,
|
5
|
+
num2 int not null,
|
6
|
+
note text
|
7
|
+
);
|
8
|
+
|
9
|
+
insert into query_load (num, num2, note) values
|
10
|
+
(3, 103, 'first'),
|
11
|
+
(4, 104, 'first'),
|
12
|
+
(2, 102, 'first'),
|
13
|
+
(1, 101, 'first');
|
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.9.
|
4
|
+
version: 0.9.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: 2018-
|
11
|
+
date: 2018-08-10 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Selects records from a table.
|
14
14
|
email:
|
@@ -19,8 +19,8 @@ extra_rdoc_files: []
|
|
19
19
|
files:
|
20
20
|
- README.md
|
21
21
|
- build.gradle
|
22
|
-
- classpath/embulk-input-jdbc-0.9.
|
23
|
-
- classpath/embulk-input-mysql-0.9.
|
22
|
+
- classpath/embulk-input-jdbc-0.9.3.jar
|
23
|
+
- classpath/embulk-input-mysql-0.9.3.jar
|
24
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
|
@@ -79,6 +79,20 @@ files:
|
|
79
79
|
- src/test/resources/org/embulk/input/mysql/test/expect/incremental/int/expected_2.diff
|
80
80
|
- src/test/resources/org/embulk/input/mysql/test/expect/incremental/int/insert_more.sql
|
81
81
|
- src/test/resources/org/embulk/input/mysql/test/expect/incremental/int/setup.sql
|
82
|
+
- src/test/resources/org/embulk/input/mysql/test/expect/incremental/query/config_1.yml
|
83
|
+
- src/test/resources/org/embulk/input/mysql/test/expect/incremental/query/config_2.yml
|
84
|
+
- src/test/resources/org/embulk/input/mysql/test/expect/incremental/query/expected_1.csv
|
85
|
+
- src/test/resources/org/embulk/input/mysql/test/expect/incremental/query/expected_1.diff
|
86
|
+
- src/test/resources/org/embulk/input/mysql/test/expect/incremental/query/expected_2.csv
|
87
|
+
- src/test/resources/org/embulk/input/mysql/test/expect/incremental/query/expected_2.diff
|
88
|
+
- src/test/resources/org/embulk/input/mysql/test/expect/incremental/query/insert_more.sql
|
89
|
+
- src/test/resources/org/embulk/input/mysql/test/expect/incremental/query/multi_columns_config_1.yml
|
90
|
+
- src/test/resources/org/embulk/input/mysql/test/expect/incremental/query/multi_columns_config_2.yml
|
91
|
+
- src/test/resources/org/embulk/input/mysql/test/expect/incremental/query/multi_columns_expected_1.csv
|
92
|
+
- src/test/resources/org/embulk/input/mysql/test/expect/incremental/query/multi_columns_expected_1.diff
|
93
|
+
- src/test/resources/org/embulk/input/mysql/test/expect/incremental/query/multi_columns_expected_2.csv
|
94
|
+
- src/test/resources/org/embulk/input/mysql/test/expect/incremental/query/multi_columns_expected_2.diff
|
95
|
+
- src/test/resources/org/embulk/input/mysql/test/expect/incremental/query/setup.sql
|
82
96
|
- src/test/resources/org/embulk/input/mysql/test/expect/incremental/ts/config_1.yml
|
83
97
|
- src/test/resources/org/embulk/input/mysql/test/expect/incremental/ts/config_2.yml
|
84
98
|
- src/test/resources/org/embulk/input/mysql/test/expect/incremental/ts/expected_1.csv
|
Binary file
|