embulk-input-postgresql 0.4.0 → 0.5.0

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: 36e483eaadb50c1495f7ca4af1e39b35b9fe53c3
4
- data.tar.gz: 438714d06d86d73a47b107e1d9c6a013a68b56f5
3
+ metadata.gz: 6dcf39b8987aa913c05ae4784056021b1c18cb50
4
+ data.tar.gz: 345e58de19952c8d778f4ca4cc445207d6bd5e2c
5
5
  SHA512:
6
- metadata.gz: 2d899f67bc54eac6cb39578f939d46f216bb09484d20be08979658c767a6a8419fc9a7f6f26da17fdb4a26a5ce311b5c8f7ab315d8da8e57755fd5b147c2cbf6
7
- data.tar.gz: 07c6da64532ed9b5a9bdccfe15cd7de84351859839ae08fa6cccf858e085f9504fed8cb73ed603d7dfca78a976540bbb054e64c39d5a17d67bd616dfa05e2b20
6
+ metadata.gz: 868809537b9dcf5eb2449d10c12bc10354673da9f59f47b20106d76fab6d6bb466a64b2a7d9c44a4bf7af4e740e017a1bb3c3395010553eeabce5abd73651f95
7
+ data.tar.gz: 71079908e53545eea4e48725f7468b379f447ec49cb0ee2436d99e231ff9db625229290fd2c090a7d0a9c8aa0549a840cbe72d340225a8c7abc7318161049ea8
data/README.md CHANGED
@@ -1,61 +1,89 @@
1
- # PostgreSQL input plugins for Embulk
2
-
3
- PostgreSQL input plugins for Embulk loads records from PostgreSQL.
4
-
5
- ## Overview
6
-
7
- * **Plugin type**: input
8
- * **Resume supported**: yes
9
-
10
- ## Configuration
11
-
12
- - **host**: database host name (string, required)
13
- - **port**: database port number (integer, 5432)
14
- - **user**: database login user name (string, required)
15
- - **password**: database login password (string, default: "")
16
- - **database**: destination database name (string, required)
17
- - **schema**: destination schema name (string, default: "public")
18
- - **fetch_rows**: number of rows to fetch one time (used for java.sql.Statement#setFetchSize) (integer, default: 10000)
19
- - **options**: extra JDBC properties (hash, default: {})
20
- - If you write SQL directly,
21
- - **query**: SQL to run (string)
22
- - If **query** is not set,
23
- - **table**: destination table name (string, required)
24
- - **select**: comma-separated list of columns to select (string, default: "*")
25
- - **where**: WHERE condition to filter the rows (string, default: no-condition)
26
-
27
- ## Example
28
-
29
- ```yaml
30
- in:
31
- type: postgresql
32
- host: localhost
33
- user: myuser
34
- password: ""
35
- database: my_database
36
- table: my_table
37
- select: "col1, col2, col3"
38
- where: "col4 != 'a'"
39
- ```
40
-
41
- If you need a complex SQL,
42
-
43
- ```yaml
44
- in:
45
- type: postgresql
46
- host: localhost
47
- user: myuser
48
- password: ""
49
- database: my_database
50
- query: |
51
- SELECT t1.id, t1.name, t2.id AS t2_id, t2.name AS t2_name
52
- FROM table1 AS t1
53
- LEFT JOIN table2 AS t2
54
- ON t1.id = t2.t1_id
55
- ```
56
-
57
- ## Build
58
-
59
- ```
60
- $ ./gradlew gem
61
- ```
1
+ # PostgreSQL input plugins for Embulk
2
+
3
+ PostgreSQL input plugins for Embulk loads records from PostgreSQL.
4
+
5
+ ## Overview
6
+
7
+ * **Plugin type**: input
8
+ * **Resume supported**: yes
9
+
10
+ ## Configuration
11
+
12
+ - **host**: database host name (string, required)
13
+ - **port**: database port number (integer, 5432)
14
+ - **user**: database login user name (string, required)
15
+ - **password**: database login password (string, default: "")
16
+ - **database**: destination database name (string, required)
17
+ - **schema**: destination schema name (string, default: "public")
18
+ - **fetch_rows**: number of rows to fetch one time (used for java.sql.Statement#setFetchSize) (integer, default: 10000)
19
+ - **options**: extra JDBC properties (hash, default: {})
20
+ - If you write SQL directly,
21
+ - **query**: SQL to run (string)
22
+ - If **query** is not set,
23
+ - **table**: destination table name (string, required)
24
+ - **select**: comma-separated list of columns to select (string, default: "*")
25
+ - **where**: WHERE condition to filter the rows (string, default: no-condition)
26
+ - **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`)
27
+ - **column_options**: advanced: a key-value pairs where key is a column name and value is options for the column.
28
+ - **value_type**: embulk get values from database as this value_type. Typically, the value_type determines `getXXX` method of `java.sql.PreparedStatement`.
29
+ (string, default: depends on the sql type of the column. Available values options are: `long`, `double`, `float`, `decimal`, `boolean`, `string`, `date`, `time`, `timestamp`)
30
+ - **type**: Column values are converted to this embulk type.
31
+ Available values options are: `boolean`, `long`, `double`, `string`, `timestamp`).
32
+ By default, the embulk type is determined according to the sql type of the column (or value_type if specified).
33
+ - **timestamp_format**: If the sql type of the column is `date`/`time`/`datetime` and the embulk type is `string`, column values are formatted by this timestamp_format. And if the embulk type is `timestamp`, this timestamp_format will be used in the output plugin. (string, default : `%Y-%m-%d` for `date`, `%H:%M:%S` for `time`, `%Y-%m-%d %H:%M:%S` for `timestamp`)
34
+ - **timezone**: If the sql type of the column is `date`/`time`/`datetime` and the embulk type is `string`, column values are formatted in this timezone.
35
+ (string, value of default_timezone option is used by default)
36
+
37
+ ## Example
38
+
39
+ ```yaml
40
+ in:
41
+ type: postgresql
42
+ host: localhost
43
+ user: myuser
44
+ password: ""
45
+ database: my_database
46
+ table: my_table
47
+ select: "col1, col2, col3"
48
+ where: "col4 != 'a'"
49
+ ```
50
+
51
+ If you need a complex SQL,
52
+
53
+ ```yaml
54
+ in:
55
+ type: postgresql
56
+ host: localhost
57
+ user: myuser
58
+ password: ""
59
+ database: my_database
60
+ query: |
61
+ SELECT t1.id, t1.name, t2.id AS t2_id, t2.name AS t2_name
62
+ FROM table1 AS t1
63
+ LEFT JOIN table2 AS t2
64
+ ON t1.id = t2.t1_id
65
+ ```
66
+
67
+ Advanced configuration:
68
+
69
+ ```yaml
70
+ in:
71
+ type: postgresql
72
+ host: localhost
73
+ user: myuser
74
+ password: ""
75
+ database: my_database
76
+ table: "my_table"
77
+ select: "col1, col2, col3"
78
+ where: "col4 != 'a'"
79
+ column_options:
80
+ col1: {type: long}
81
+ col3: {type: string, timestamp_format: "%Y/%m/%d", timezone: "+0900"}
82
+
83
+ ```
84
+
85
+ ## Build
86
+
87
+ ```
88
+ $ ./gradlew gem
89
+ ```
data/build.gradle CHANGED
@@ -1,7 +1,7 @@
1
- dependencies {
2
- compile project(':embulk-input-jdbc')
3
-
4
- compile 'org.postgresql:postgresql:9.4-1200-jdbc41'
5
-
6
- testCompile project(':embulk-input-jdbc').sourceSets.test.output
7
- }
1
+ dependencies {
2
+ compile project(':embulk-input-jdbc')
3
+
4
+ compile 'org.postgresql:postgresql:9.4-1200-jdbc41'
5
+
6
+ testCompile project(':embulk-input-jdbc').sourceSets.test.output
7
+ }
@@ -1,3 +1,3 @@
1
- Embulk::JavaPlugin.register_input(
2
- :postgresql, "org.embulk.input.PostgreSQLInputPlugin",
3
- File.expand_path('../../../../classpath', __FILE__))
1
+ Embulk::JavaPlugin.register_input(
2
+ :postgresql, "org.embulk.input.PostgreSQLInputPlugin",
3
+ File.expand_path('../../../../classpath', __FILE__))
@@ -1,91 +1,91 @@
1
- package org.embulk.input;
2
-
3
- import java.util.Properties;
4
- import java.sql.Connection;
5
- import java.sql.Driver;
6
- import java.sql.SQLException;
7
- import com.google.common.base.Throwables;
8
- import org.embulk.config.Config;
9
- import org.embulk.config.ConfigDefault;
10
- import org.embulk.input.jdbc.AbstractJdbcInputPlugin;
11
- import org.embulk.input.postgresql.PostgreSQLInputConnection;
12
-
13
- public class PostgreSQLInputPlugin
14
- extends AbstractJdbcInputPlugin
15
- {
16
- private static final Driver driver = new org.postgresql.Driver();
17
-
18
- public interface PostgreSQLPluginTask
19
- extends PluginTask
20
- {
21
- @Config("host")
22
- public String getHost();
23
-
24
- @Config("port")
25
- @ConfigDefault("5432")
26
- public int getPort();
27
-
28
- @Config("user")
29
- public String getUser();
30
-
31
- @Config("password")
32
- @ConfigDefault("\"\"")
33
- public String getPassword();
34
-
35
- @Config("database")
36
- public String getDatabase();
37
-
38
- @Config("schema")
39
- @ConfigDefault("\"public\"")
40
- public String getSchema();
41
- }
42
-
43
- @Override
44
- protected Class<? extends PluginTask> getTaskClass()
45
- {
46
- return PostgreSQLPluginTask.class;
47
- }
48
-
49
- @Override
50
- protected PostgreSQLInputConnection newConnection(PluginTask task) throws SQLException
51
- {
52
- PostgreSQLPluginTask t = (PostgreSQLPluginTask) task;
53
-
54
- String url = String.format("jdbc:postgresql://%s:%d/%s",
55
- t.getHost(), t.getPort(), t.getDatabase());
56
-
57
- Properties props = new Properties();
58
- props.setProperty("user", t.getUser());
59
- props.setProperty("password", t.getPassword());
60
- props.setProperty("loginTimeout", "300"); // seconds
61
- props.setProperty("socketTimeout", "1800"); // seconds
62
-
63
- // Enable keepalive based on tcp_keepalive_time, tcp_keepalive_intvl and tcp_keepalive_probes kernel parameters.
64
- // Socket options TCP_KEEPCNT, TCP_KEEPIDLE, and TCP_KEEPINTVL are not configurable.
65
- props.setProperty("tcpKeepAlive", "true");
66
-
67
- // TODO
68
- //switch t.getSssl() {
69
- //when "disable":
70
- // break;
71
- //when "enable":
72
- // props.setProperty("sslfactory", "org.postgresql.ssl.NonValidatingFactory"); // disable server-side validation
73
- //when "verify":
74
- // props.setProperty("ssl", "true");
75
- // break;
76
- //}
77
-
78
- props.putAll(t.getOptions());
79
-
80
- Connection con = driver.connect(url, props);
81
- try {
82
- PostgreSQLInputConnection c = new PostgreSQLInputConnection(con, t.getSchema());
83
- con = null;
84
- return c;
85
- } finally {
86
- if (con != null) {
87
- con.close();
88
- }
89
- }
90
- }
91
- }
1
+ package org.embulk.input;
2
+
3
+ import java.util.Properties;
4
+ import java.sql.Connection;
5
+ import java.sql.Driver;
6
+ import java.sql.SQLException;
7
+ import com.google.common.base.Throwables;
8
+ import org.embulk.config.Config;
9
+ import org.embulk.config.ConfigDefault;
10
+ import org.embulk.input.jdbc.AbstractJdbcInputPlugin;
11
+ import org.embulk.input.postgresql.PostgreSQLInputConnection;
12
+
13
+ public class PostgreSQLInputPlugin
14
+ extends AbstractJdbcInputPlugin
15
+ {
16
+ private static final Driver driver = new org.postgresql.Driver();
17
+
18
+ public interface PostgreSQLPluginTask
19
+ extends PluginTask
20
+ {
21
+ @Config("host")
22
+ public String getHost();
23
+
24
+ @Config("port")
25
+ @ConfigDefault("5432")
26
+ public int getPort();
27
+
28
+ @Config("user")
29
+ public String getUser();
30
+
31
+ @Config("password")
32
+ @ConfigDefault("\"\"")
33
+ public String getPassword();
34
+
35
+ @Config("database")
36
+ public String getDatabase();
37
+
38
+ @Config("schema")
39
+ @ConfigDefault("\"public\"")
40
+ public String getSchema();
41
+ }
42
+
43
+ @Override
44
+ protected Class<? extends PluginTask> getTaskClass()
45
+ {
46
+ return PostgreSQLPluginTask.class;
47
+ }
48
+
49
+ @Override
50
+ protected PostgreSQLInputConnection newConnection(PluginTask task) throws SQLException
51
+ {
52
+ PostgreSQLPluginTask t = (PostgreSQLPluginTask) task;
53
+
54
+ String url = String.format("jdbc:postgresql://%s:%d/%s",
55
+ t.getHost(), t.getPort(), t.getDatabase());
56
+
57
+ Properties props = new Properties();
58
+ props.setProperty("user", t.getUser());
59
+ props.setProperty("password", t.getPassword());
60
+ props.setProperty("loginTimeout", "300"); // seconds
61
+ props.setProperty("socketTimeout", "1800"); // seconds
62
+
63
+ // Enable keepalive based on tcp_keepalive_time, tcp_keepalive_intvl and tcp_keepalive_probes kernel parameters.
64
+ // Socket options TCP_KEEPCNT, TCP_KEEPIDLE, and TCP_KEEPINTVL are not configurable.
65
+ props.setProperty("tcpKeepAlive", "true");
66
+
67
+ // TODO
68
+ //switch t.getSssl() {
69
+ //when "disable":
70
+ // break;
71
+ //when "enable":
72
+ // props.setProperty("sslfactory", "org.postgresql.ssl.NonValidatingFactory"); // disable server-side validation
73
+ //when "verify":
74
+ // props.setProperty("ssl", "true");
75
+ // break;
76
+ //}
77
+
78
+ props.putAll(t.getOptions());
79
+
80
+ Connection con = driver.connect(url, props);
81
+ try {
82
+ PostgreSQLInputConnection c = new PostgreSQLInputConnection(con, t.getSchema());
83
+ con = null;
84
+ return c;
85
+ } finally {
86
+ if (con != null) {
87
+ con.close();
88
+ }
89
+ }
90
+ }
91
+ }
@@ -1,60 +1,60 @@
1
- package org.embulk.input.postgresql;
2
-
3
- import java.sql.Connection;
4
- import java.sql.PreparedStatement;
5
- import java.sql.ResultSet;
6
- import java.sql.SQLException;
7
- import org.slf4j.Logger;
8
- import org.embulk.spi.Exec;
9
- import org.embulk.input.jdbc.JdbcInputConnection;
10
-
11
- public class PostgreSQLInputConnection
12
- extends JdbcInputConnection
13
- {
14
- private final Logger logger = Exec.getLogger(PostgreSQLInputConnection.class);
15
-
16
- public PostgreSQLInputConnection(Connection connection, String schemaName)
17
- throws SQLException
18
- {
19
- super(connection, schemaName);
20
- }
21
-
22
- @Override
23
- protected CursorSelect newBatchSelect(String select, int fetchRows) throws SQLException
24
- {
25
- executeUpdate("DECLARE cur NO SCROLL CURSOR FOR "+select);
26
-
27
- String fetchSql = "FETCH FORWARD "+fetchRows+" FROM cur";
28
- return new CursorSelect(fetchSql, connection.prepareStatement(fetchSql));
29
- }
30
-
31
- public class CursorSelect
32
- implements BatchSelect
33
- {
34
- private final String fetchSql;
35
- private final PreparedStatement fetchStatement;
36
-
37
- public CursorSelect(String fetchSql, PreparedStatement fetchStatement) throws SQLException
38
- {
39
- this.fetchSql = fetchSql;
40
- this.fetchStatement = fetchStatement;
41
- }
42
-
43
- public ResultSet fetch() throws SQLException
44
- {
45
- logger.info("SQL: " + fetchSql);
46
- long startTime = System.currentTimeMillis();
47
-
48
- ResultSet rs = fetchStatement.executeQuery();
49
-
50
- double seconds = (System.currentTimeMillis() - startTime) / 1000.0;
51
- logger.info(String.format("> %.2f seconds", seconds));
52
- return rs;
53
- }
54
-
55
- public void close() throws SQLException
56
- {
57
- // TODO close?
58
- }
59
- }
60
- }
1
+ package org.embulk.input.postgresql;
2
+
3
+ import java.sql.Connection;
4
+ import java.sql.PreparedStatement;
5
+ import java.sql.ResultSet;
6
+ import java.sql.SQLException;
7
+ import org.slf4j.Logger;
8
+ import org.embulk.spi.Exec;
9
+ import org.embulk.input.jdbc.JdbcInputConnection;
10
+
11
+ public class PostgreSQLInputConnection
12
+ extends JdbcInputConnection
13
+ {
14
+ private final Logger logger = Exec.getLogger(PostgreSQLInputConnection.class);
15
+
16
+ public PostgreSQLInputConnection(Connection connection, String schemaName)
17
+ throws SQLException
18
+ {
19
+ super(connection, schemaName);
20
+ }
21
+
22
+ @Override
23
+ protected CursorSelect newBatchSelect(String select, int fetchRows) throws SQLException
24
+ {
25
+ executeUpdate("DECLARE cur NO SCROLL CURSOR FOR "+select);
26
+
27
+ String fetchSql = "FETCH FORWARD "+fetchRows+" FROM cur";
28
+ return new CursorSelect(fetchSql, connection.prepareStatement(fetchSql));
29
+ }
30
+
31
+ public class CursorSelect
32
+ implements BatchSelect
33
+ {
34
+ private final String fetchSql;
35
+ private final PreparedStatement fetchStatement;
36
+
37
+ public CursorSelect(String fetchSql, PreparedStatement fetchStatement) throws SQLException
38
+ {
39
+ this.fetchSql = fetchSql;
40
+ this.fetchStatement = fetchStatement;
41
+ }
42
+
43
+ public ResultSet fetch() throws SQLException
44
+ {
45
+ logger.info("SQL: " + fetchSql);
46
+ long startTime = System.currentTimeMillis();
47
+
48
+ ResultSet rs = fetchStatement.executeQuery();
49
+
50
+ double seconds = (System.currentTimeMillis() - startTime) / 1000.0;
51
+ logger.info(String.format("> %.2f seconds", seconds));
52
+ return rs;
53
+ }
54
+
55
+ public void close() throws SQLException
56
+ {
57
+ // TODO close?
58
+ }
59
+ }
60
+ }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: embulk-input-postgresql
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.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: 2015-03-06 00:00:00.000000000 Z
11
+ date: 2015-06-17 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Selects records from a table.
14
14
  email:
@@ -22,8 +22,8 @@ files:
22
22
  - lib/embulk/input/postgresql.rb
23
23
  - src/main/java/org/embulk/input/PostgreSQLInputPlugin.java
24
24
  - src/main/java/org/embulk/input/postgresql/PostgreSQLInputConnection.java
25
- - classpath/embulk-input-jdbc-0.4.0.jar
26
- - classpath/embulk-input-postgresql-0.4.0.jar
25
+ - classpath/embulk-input-jdbc-0.5.0.jar
26
+ - classpath/embulk-input-postgresql-0.5.0.jar
27
27
  - classpath/jna-4.1.0.jar
28
28
  - classpath/jna-platform-4.1.0.jar
29
29
  - classpath/postgresql-9.4-1200-jdbc41.jar
Binary file