embulk-output-redshift 0.6.0 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -1
- data/classpath/embulk-output-jdbc-0.6.1.jar +0 -0
- data/classpath/{embulk-output-postgresql-0.6.0.jar → embulk-output-postgresql-0.6.1.jar} +0 -0
- data/classpath/{embulk-output-redshift-0.6.0.jar → embulk-output-redshift-0.6.1.jar} +0 -0
- data/src/main/java/org/embulk/output/RedshiftOutputPlugin.java +1 -1
- data/src/main/java/org/embulk/output/redshift/RedshiftOutputConnection.java +49 -0
- metadata +5 -5
- data/classpath/embulk-output-jdbc-0.6.0.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: 4befc609ebdd8278a0dc58d63c464d710bde3ed7
|
4
|
+
data.tar.gz: d65e65a04861aba8e25b33d3ccb5ae6f0a406bc9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5675fe7972621547f61caa17f303461c98c5bee60f5354f06ae42ae0e1546a22ccf1ae339b08436fc1b49ac9022228f8192ccdcfbbe956d50ff74a7cbfc45b56
|
7
|
+
data.tar.gz: 63b40e72eed84caa98c178fefa3e603ef7ee2661af0d65126ec9ce38181a428a7072ce6fe6fe5995c7f3643ca539b7aba7138dd81b06497b3ffa5230b5cb0bcb
|
data/README.md
CHANGED
@@ -23,7 +23,8 @@ Redshift output plugins for Embulk loads records to Redshift.
|
|
23
23
|
- **s3_bucket**: S3 bucket name for temporary files
|
24
24
|
- **s3_key_prefix**: S3 key prefix for temporary files (string, default:"")
|
25
25
|
- **options**: extra connection properties (hash, default: {})
|
26
|
-
- **mode**: "insert", "insert_direct", "truncate_insert", or "
|
26
|
+
- **mode**: "insert", "insert_direct", "truncate_insert", "replace" or "merge". See below. (string, required)
|
27
|
+
- **merge_keys**: key column names for merging records in merge mode (string array, required in merge mode)
|
27
28
|
- **batch_size**: size of a single batch insert (integer, default: 16777216)
|
28
29
|
- **default_timezone**: If input column type (embulk type) is timestamp, this plugin needs to format the timestamp into a SQL string. This default_timezone option is used to control the timezone. You can overwrite timezone for each columns using column_options option. (string, default: `UTC`)
|
29
30
|
- **column_options**: advanced: a key-value pairs where key is a column name and value is options for the column.
|
@@ -51,6 +52,10 @@ Redshift output plugins for Embulk loads records to Redshift.
|
|
51
52
|
* Behavior: This mode writes rows to an intermediate table first. If all those tasks run correctly, drops the target table and alters the name of the intermediate table into the target table name.
|
52
53
|
* Transactional: Yes.
|
53
54
|
* Resumable: No.
|
55
|
+
* **merge**:
|
56
|
+
* Behavior: This mode writes rows to some intermediate tables first. If all those tasks run correctly, inserts records from intermediate tables after deleting records whose keys exist in intermediate tables. Namely, if merge keys of a record in the intermediate tables already exist in the target table, the target record is updated by the intermediate record, otherwise the intermediate record is inserted. If the target table doesn't exist, it is created automatically.
|
57
|
+
* Transactional: Yes.
|
58
|
+
* Resumable: Yes.
|
54
59
|
|
55
60
|
### Supported types
|
56
61
|
|
Binary file
|
Binary file
|
Binary file
|
@@ -75,7 +75,7 @@ public class RedshiftOutputPlugin
|
|
75
75
|
{
|
76
76
|
return new Features()
|
77
77
|
.setMaxTableNameLength(30)
|
78
|
-
.setSupportedModes(ImmutableSet.of(Mode.INSERT, Mode.INSERT_DIRECT, Mode.TRUNCATE_INSERT, Mode.REPLACE))
|
78
|
+
.setSupportedModes(ImmutableSet.of(Mode.INSERT, Mode.INSERT_DIRECT, Mode.TRUNCATE_INSERT, Mode.REPLACE, Mode.MERGE))
|
79
79
|
.setIgnoreMergeKeys(false);
|
80
80
|
}
|
81
81
|
|
@@ -1,5 +1,6 @@
|
|
1
1
|
package org.embulk.output.redshift;
|
2
2
|
|
3
|
+
import java.util.List;
|
3
4
|
import java.sql.Connection;
|
4
5
|
import java.sql.SQLException;
|
5
6
|
import java.sql.Statement;
|
@@ -119,4 +120,52 @@ public class RedshiftOutputConnection
|
|
119
120
|
stmt.close();
|
120
121
|
}
|
121
122
|
}
|
123
|
+
|
124
|
+
@Override
|
125
|
+
protected String buildCollectMergeSql(List<String> fromTables, JdbcSchema schema, String toTable, List<String> mergeKeys) throws SQLException
|
126
|
+
{
|
127
|
+
StringBuilder sb = new StringBuilder();
|
128
|
+
|
129
|
+
sb.append("BEGIN TRANSACTION;");
|
130
|
+
|
131
|
+
sb.append("DELETE FROM ");
|
132
|
+
quoteIdentifierString(sb, toTable);
|
133
|
+
sb.append(" USING (");
|
134
|
+
for(int i=0; i < fromTables.size(); i++) {
|
135
|
+
if(i != 0) { sb.append(" UNION ALL "); }
|
136
|
+
sb.append("SELECT * FROM ");
|
137
|
+
quoteIdentifierString(sb, fromTables.get(i));
|
138
|
+
}
|
139
|
+
sb.append(") S WHERE (");
|
140
|
+
for(int i=0; i < mergeKeys.size(); i++) {
|
141
|
+
if (i != 0) { sb.append(" AND "); }
|
142
|
+
sb.append("S.");
|
143
|
+
quoteIdentifierString(sb, mergeKeys.get(i));
|
144
|
+
sb.append(" = ");
|
145
|
+
quoteIdentifierString(sb, toTable);
|
146
|
+
sb.append(".");
|
147
|
+
quoteIdentifierString(sb, mergeKeys.get(i));
|
148
|
+
}
|
149
|
+
sb.append(");");
|
150
|
+
|
151
|
+
sb.append("INSERT INTO ");
|
152
|
+
quoteIdentifierString(sb, toTable);
|
153
|
+
sb.append(" (");
|
154
|
+
for(int i=0; i < fromTables.size(); i++) {
|
155
|
+
if(i != 0) { sb.append(" UNION ALL "); }
|
156
|
+
sb.append("SELECT ");
|
157
|
+
for(int j=0; j < schema.getCount(); j++) {
|
158
|
+
if (j != 0) { sb.append(", "); }
|
159
|
+
quoteIdentifierString(sb, schema.getColumnName(j));
|
160
|
+
}
|
161
|
+
sb.append(" FROM ");
|
162
|
+
quoteIdentifierString(sb, fromTables.get(i));
|
163
|
+
}
|
164
|
+
sb.append(");");
|
165
|
+
|
166
|
+
sb.append("END TRANSACTION;");
|
167
|
+
|
168
|
+
return sb.toString();
|
169
|
+
}
|
170
|
+
|
122
171
|
}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: embulk-output-redshift
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sadayuki Furuhashi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-06-23 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Inserts or updates records to a table.
|
14
14
|
email:
|
@@ -30,9 +30,9 @@ files:
|
|
30
30
|
- classpath/aws-java-sdk-sts-1.10.33.jar
|
31
31
|
- classpath/commons-codec-1.6.jar
|
32
32
|
- classpath/commons-logging-1.1.3.jar
|
33
|
-
- classpath/embulk-output-jdbc-0.6.
|
34
|
-
- classpath/embulk-output-postgresql-0.6.
|
35
|
-
- classpath/embulk-output-redshift-0.6.
|
33
|
+
- classpath/embulk-output-jdbc-0.6.1.jar
|
34
|
+
- classpath/embulk-output-postgresql-0.6.1.jar
|
35
|
+
- classpath/embulk-output-redshift-0.6.1.jar
|
36
36
|
- classpath/httpclient-4.3.6.jar
|
37
37
|
- classpath/httpcore-4.3.3.jar
|
38
38
|
- classpath/postgresql-9.4-1205-jdbc41.jar
|
Binary file
|