embulk-output-postgresql 0.6.1 → 0.6.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: 4779498654aaae70ab01a04cebca45eb702f0d55
4
- data.tar.gz: 30c43767822c55f73e0d58443ba1a5e5615222e0
3
+ metadata.gz: 8613dcf9023886902ee147f03579177c56d7c456
4
+ data.tar.gz: 6c5967b4f4a805964b6a75e3eb79354b2e0068e3
5
5
  SHA512:
6
- metadata.gz: ec2a3b15338f630ba5e047a8f0c1916ae9c6a0bf2e66b528ab715ca57e4fd874ca3347f9e60027671ef61496eb9d930478dc60ca64a931b9890354a370744aad
7
- data.tar.gz: f52e2cb4b329f77f87c253b1a3874b2ebb5905180c29704457c8455c487d3886545e214f1326206f3d8500dba46f4c4c02e1b00128d09fb05e3dbccc97e0e222
6
+ metadata.gz: cb0c90dfe2353d952410c6eab6bb32d740c22e35f41fe13aced146af9cee5ab263b1a6a35c3a96fbcd163793072882a9ccd613b932b34dd16893bc9454e50167
7
+ data.tar.gz: dbdf6e39dc58639559e6035e7f935e74d401c8600ca739904e264037de034672420809d452147d6cad16faf733af41189ff6972656a5706eca88c1214eba2a8e
data/README.md CHANGED
@@ -5,8 +5,8 @@ PostgreSQL output plugins for Embulk loads records to PostgreSQL.
5
5
  ## Overview
6
6
 
7
7
  * **Plugin type**: output
8
- * **Load all or nothing**: depnds on the mode. see below.
9
- * **Resume supported**: depnds on the mode. see below.
8
+ * **Load all or nothing**: depends on the mode. see below.
9
+ * **Resume supported**: depends on the mode. see below.
10
10
 
11
11
  ## Configuration
12
12
 
@@ -18,8 +18,12 @@ PostgreSQL output plugins for Embulk loads records to PostgreSQL.
18
18
  - **schema**: destination schema name (string, default: "public")
19
19
  - **table**: destination table name (string, required)
20
20
  - **options**: extra connection properties (hash, default: {})
21
+ - **retry_limit** max retry count for database operations (integer, default: 12)
22
+ - **retry_wait** initial retry wait time in milliseconds (integer, default: 1000 (1 second))
23
+ - **max_retry_wait** upper limit of retry wait, which will be doubled at every retry (integer, default: 1800000 (30 minutes))
21
24
  - **mode**: "insert", "insert_direct", "truncate_insert", "replace" or "merge". See below. (string, required)
22
25
  - **merge_keys**: key column names for merging records in merge mode (string array, required in merge mode)
26
+ - **merge_rule**: list of column assignments for updating existing records used in merge mode, for example `foo = foo + S.foo`. (string array, default: always overwrites with new values)
23
27
  - **ssl**: enables SSL. data will be encrypted but CA or certification will not be verified (boolean, default: false)
24
28
  - **batch_size**: size of a single batch insert (integer, default: 16777216)
25
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`)
@@ -3,15 +3,11 @@ package org.embulk.output;
3
3
  import java.io.IOException;
4
4
  import java.sql.SQLException;
5
5
  import java.sql.Types;
6
- import java.util.List;
7
6
  import java.util.Properties;
8
7
 
9
8
  import org.embulk.config.Config;
10
9
  import org.embulk.config.ConfigDefault;
11
- import org.embulk.output.jdbc.AbstractJdbcOutputPlugin;
12
- import org.embulk.output.jdbc.BatchInsert;
13
- import org.embulk.output.jdbc.JdbcColumn;
14
- import org.embulk.output.jdbc.JdbcSchema;
10
+ import org.embulk.output.jdbc.*;
15
11
  import org.embulk.output.jdbc.setter.ColumnSetterFactory;
16
12
  import org.embulk.output.postgresql.PostgreSQLCopyBatchInsert;
17
13
  import org.embulk.output.postgresql.PostgreSQLOutputConnector;
@@ -112,9 +108,9 @@ public class PostgreSQLOutputPlugin
112
108
  }
113
109
 
114
110
  @Override
115
- protected BatchInsert newBatchInsert(PluginTask task, Optional<List<String>> mergeKeys) throws IOException, SQLException
111
+ protected BatchInsert newBatchInsert(PluginTask task, Optional<MergeConfig> mergeConfig) throws IOException, SQLException
116
112
  {
117
- if (mergeKeys.isPresent()) {
113
+ if (mergeConfig.isPresent()) {
118
114
  throw new UnsupportedOperationException("PostgreSQL output plugin doesn't support 'merge_direct' mode. Use 'merge' mode instead.");
119
115
  }
120
116
  return new PostgreSQLCopyBatchInsert(getConnector(task, true));
@@ -4,6 +4,8 @@ import java.util.List;
4
4
  import java.sql.Connection;
5
5
  import java.sql.SQLException;
6
6
  import java.sql.Statement;
7
+
8
+ import org.embulk.output.jdbc.MergeConfig;
7
9
  import org.postgresql.copy.CopyManager;
8
10
  import org.postgresql.core.BaseConnection;
9
11
  import org.embulk.output.jdbc.JdbcOutputConnection;
@@ -27,7 +29,7 @@ public class PostgreSQLOutputConnection
27
29
  sb.append("COPY ");
28
30
  quoteIdentifierString(sb, toTable);
29
31
  sb.append(" (");
30
- for (int i=0; i < toTableSchema.getCount(); i++) {
32
+ for (int i = 0; i < toTableSchema.getCount(); i++) {
31
33
  if (i != 0) { sb.append(", "); }
32
34
  quoteIdentifierString(sb, toTableSchema.getColumnName(i));
33
35
  }
@@ -43,7 +45,7 @@ public class PostgreSQLOutputConnection
43
45
  }
44
46
 
45
47
  @Override
46
- protected String buildCollectMergeSql(List<String> fromTables, JdbcSchema schema, String toTable, List<String> mergeKeys) throws SQLException
48
+ protected String buildCollectMergeSql(List<String> fromTables, JdbcSchema schema, String toTable, MergeConfig mergeConfig) throws SQLException
47
49
  {
48
50
  StringBuilder sb = new StringBuilder();
49
51
 
@@ -51,17 +53,29 @@ public class PostgreSQLOutputConnection
51
53
  sb.append("UPDATE ");
52
54
  quoteIdentifierString(sb, toTable);
53
55
  sb.append(" SET ");
54
- for (int i=0; i < schema.getCount(); i++) {
55
- if (i != 0) { sb.append(", "); }
56
- quoteIdentifierString(sb, schema.getColumnName(i));
57
- sb.append(" = S.");
58
- quoteIdentifierString(sb, schema.getColumnName(i));
56
+ if (mergeConfig.getMergeRule().isPresent()) {
57
+ List<String> rule = mergeConfig.getMergeRule().get();
58
+ for (int i = 0; i < rule.size(); i++) {
59
+ if (i != 0) {
60
+ sb.append(", ");
61
+ }
62
+ sb.append(rule.get(i));
63
+ }
64
+ } else {
65
+ for (int i = 0; i < schema.getCount(); i++) {
66
+ if (i != 0) {
67
+ sb.append(", ");
68
+ }
69
+ quoteIdentifierString(sb, schema.getColumnName(i));
70
+ sb.append(" = S.");
71
+ quoteIdentifierString(sb, schema.getColumnName(i));
72
+ }
59
73
  }
60
74
  sb.append(" FROM (");
61
- for (int i=0; i < fromTables.size(); i++) {
75
+ for (int i = 0; i < fromTables.size(); i++) {
62
76
  if (i != 0) { sb.append(" UNION ALL "); }
63
77
  sb.append("SELECT ");
64
- for(int j=0; j < schema.getCount(); j++) {
78
+ for(int j = 0; j < schema.getCount(); j++) {
65
79
  if (j != 0) { sb.append(", "); }
66
80
  quoteIdentifierString(sb, schema.getColumnName(j));
67
81
  }
@@ -70,7 +84,8 @@ public class PostgreSQLOutputConnection
70
84
  }
71
85
  sb.append(") S");
72
86
  sb.append(" WHERE ");
73
- for (int i=0; i < mergeKeys.size(); i++) {
87
+ List<String> mergeKeys = mergeConfig.getMergeKeys();
88
+ for (int i = 0; i < mergeKeys.size(); i++) {
74
89
  if (i != 0) { sb.append(" AND "); }
75
90
  quoteIdentifierString(sb, toTable);
76
91
  sb.append(".");
@@ -80,7 +95,7 @@ public class PostgreSQLOutputConnection
80
95
  quoteIdentifierString(sb, mergeKeys.get(i));
81
96
  }
82
97
  sb.append(" RETURNING ");
83
- for (int i=0; i < mergeKeys.size(); i++) {
98
+ for (int i = 0; i < mergeKeys.size(); i++) {
84
99
  if (i != 0) { sb.append(", "); }
85
100
  sb.append("S.");
86
101
  quoteIdentifierString(sb, mergeKeys.get(i));
@@ -90,21 +105,21 @@ public class PostgreSQLOutputConnection
90
105
  sb.append("INSERT INTO ");
91
106
  quoteIdentifierString(sb, toTable);
92
107
  sb.append(" (");
93
- for (int i=0; i < schema.getCount(); i++) {
108
+ for (int i = 0; i < schema.getCount(); i++) {
94
109
  if (i != 0) { sb.append(", "); }
95
110
  quoteIdentifierString(sb, schema.getColumnName(i));
96
111
  }
97
112
  sb.append(") ");
98
113
  sb.append("SELECT DISTINCT ON (");
99
- for (int i=0; i < mergeKeys.size(); i++) {
114
+ for (int i = 0; i < mergeKeys.size(); i++) {
100
115
  if (i != 0) { sb.append(", "); }
101
116
  quoteIdentifierString(sb, mergeKeys.get(i));
102
117
  }
103
118
  sb.append(") * FROM (");
104
- for (int i=0; i < fromTables.size(); i++) {
119
+ for (int i = 0; i < fromTables.size(); i++) {
105
120
  if (i != 0) { sb.append(" UNION ALL "); }
106
121
  sb.append("SELECT ");
107
- for(int j=0; j < schema.getCount(); j++) {
122
+ for(int j = 0; j < schema.getCount(); j++) {
108
123
  if (j != 0) { sb.append(", "); }
109
124
  quoteIdentifierString(sb, schema.getColumnName(j));
110
125
  }
@@ -114,7 +129,7 @@ public class PostgreSQLOutputConnection
114
129
  sb.append(") S ");
115
130
  sb.append("WHERE NOT EXISTS (");
116
131
  sb.append("SELECT 1 FROM updated WHERE ");
117
- for (int i=0; i < mergeKeys.size(); i++) {
132
+ for (int i = 0; i < mergeKeys.size(); i++) {
118
133
  if (i != 0) { sb.append(" AND "); }
119
134
  sb.append("S.");
120
135
  quoteIdentifierString(sb, mergeKeys.get(i));
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: embulk-output-postgresql
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.6.2
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-06-23 00:00:00.000000000 Z
11
+ date: 2016-08-10 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Inserts or updates records to a table.
14
14
  email:
@@ -26,8 +26,8 @@ files:
26
26
  - src/main/java/org/embulk/output/postgresql/PostgreSQLOutputConnection.java
27
27
  - src/main/java/org/embulk/output/postgresql/PostgreSQLOutputConnector.java
28
28
  - src/main/java/org/embulk/output/postgresql/setter/PostgreSQLColumnSetterFactory.java
29
- - classpath/embulk-output-jdbc-0.6.1.jar
30
- - classpath/embulk-output-postgresql-0.6.1.jar
29
+ - classpath/embulk-output-jdbc-0.6.2.jar
30
+ - classpath/embulk-output-postgresql-0.6.2.jar
31
31
  - classpath/postgresql-9.4-1205-jdbc41.jar
32
32
  homepage: https://github.com/embulk/embulk-output-jdbc
33
33
  licenses:
Binary file