embulk-input-oracle 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 +7 -0
- data/README.md +93 -0
- data/build.gradle +5 -0
- data/classpath/embulk-input-jdbc-0.5.0.jar +0 -0
- data/classpath/embulk-input-oracle-0.5.0.jar +0 -0
- data/lib/embulk/input/oracle.rb +3 -0
- data/src/main/java/org/embulk/input/OracleInputPlugin.java +105 -0
- data/src/main/java/org/embulk/input/oracle/OracleInputConnection.java +21 -0
- metadata +51 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f72a6a78e5dbfc26d82184d49ac814a895dcf618
|
4
|
+
data.tar.gz: 4dc9ad16ed3027e889add065039d8aceda3e02ed
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: abe4d88d1401129bf7d59867470656a8c7b54bd2bcd15d47d9592a78c956daf6e9a6c6181c086c09b20f47c12a678d3cd9473c8d1b130a9e3ec9bdd8b1cdd281
|
7
|
+
data.tar.gz: ac78869b2fcf9fd18c6362c32efd7fedcc76a0a64f9074c3f23a9fd7c9e5e429b106532db57681d16f1950618d34aba02d7b8ffcc44ed12e14a28c728992d5a9
|
data/README.md
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
# Oracle input plugins for Embulk
|
2
|
+
|
3
|
+
Oracle input plugins for Embulk loads records from Oracle.
|
4
|
+
|
5
|
+
## Overview
|
6
|
+
|
7
|
+
* **Plugin type**: input
|
8
|
+
* **Resume supported**: yes
|
9
|
+
|
10
|
+
## Configuration
|
11
|
+
|
12
|
+
- **driver_path**: path to the jar file of the Oracle JDBC driver (string)
|
13
|
+
- **host**: database host name (string, required if url is not set)
|
14
|
+
- **port**: database port number (integer, default: 1521)
|
15
|
+
- **user**: database login user name (string, required)
|
16
|
+
- **password**: database login password (string, default: "")
|
17
|
+
- **database**: destination database name (string, required if url is not set)
|
18
|
+
- **url**: URL of the JDBC connection (string, optional)
|
19
|
+
- If you write SQL directly,
|
20
|
+
- **query**: SQL to run (string)
|
21
|
+
- If **query** is not set,
|
22
|
+
- **table**: destination table name (string, required)
|
23
|
+
- **select**: comma-separated list of columns to select (string, default: "*")
|
24
|
+
- **where**: WHERE condition to filter the rows (string, default: no-condition)
|
25
|
+
- **fetch_rows**: number of rows to fetch one time (used for java.sql.Statement#setFetchSize) (integer, default: 10000)
|
26
|
+
- **options**: extra JDBC properties (hash, default: {})
|
27
|
+
- **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`)
|
28
|
+
- **column_options**: advanced: a key-value pairs where key is a column name and value is options for the column.
|
29
|
+
- **value_type**: embulk get values from database as this value_type. Typically, the value_type determines `getXXX` method of `java.sql.PreparedStatement`.
|
30
|
+
(string, default: depends on the sql type of the column. Available values options are: `long`, `double`, `float`, `decimal`, `boolean`, `string`, `date`, `time`, `timestamp`)
|
31
|
+
- **type**: Column values are converted to this embulk type.
|
32
|
+
Available values options are: `boolean`, `long`, `double`, `string`, `timestamp`).
|
33
|
+
By default, the embulk type is determined according to the sql type of the column (or value_type if specified).
|
34
|
+
- **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`)
|
35
|
+
- **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.
|
36
|
+
(string, value of default_timezone option is used by default)
|
37
|
+
|
38
|
+
## Example
|
39
|
+
|
40
|
+
```yaml
|
41
|
+
in:
|
42
|
+
type: oracle
|
43
|
+
driver_path: /opt/oracle/ojdbc7.jar
|
44
|
+
host: localhost
|
45
|
+
user: myuser
|
46
|
+
password: ""
|
47
|
+
database: my_database
|
48
|
+
table: my_table
|
49
|
+
select: "col1, col2, col3"
|
50
|
+
where: "col4 != 'a'"
|
51
|
+
```
|
52
|
+
|
53
|
+
If you need a complex SQL,
|
54
|
+
|
55
|
+
```yaml
|
56
|
+
in:
|
57
|
+
type: oracle
|
58
|
+
driver_path: /opt/oracle/ojdbc7.jar
|
59
|
+
host: localhost
|
60
|
+
user: myuser
|
61
|
+
password: ""
|
62
|
+
database: my_database
|
63
|
+
query: |
|
64
|
+
SELECT t1.id, t1.name, t2.id AS t2_id, t2.name AS t2_name
|
65
|
+
FROM table1 AS t1
|
66
|
+
LEFT JOIN table2 AS t2
|
67
|
+
ON t1.id = t2.t1_id
|
68
|
+
```
|
69
|
+
|
70
|
+
Advanced configuration:
|
71
|
+
|
72
|
+
```yaml
|
73
|
+
in:
|
74
|
+
type: oracle
|
75
|
+
driver_path: /opt/oracle/ojdbc7.jar
|
76
|
+
host: localhost
|
77
|
+
user: myuser
|
78
|
+
password: ""
|
79
|
+
database: my_database
|
80
|
+
table: "my_table"
|
81
|
+
select: "col1, col2, col3"
|
82
|
+
where: "col4 != 'a'"
|
83
|
+
column_options:
|
84
|
+
col1: {type: long}
|
85
|
+
col3: {type: string, timestamp_format: "%Y/%m/%d", timezone: "+0900"}
|
86
|
+
|
87
|
+
```
|
88
|
+
|
89
|
+
## Build
|
90
|
+
|
91
|
+
```
|
92
|
+
$ ./gradlew gem
|
93
|
+
```
|
data/build.gradle
ADDED
Binary file
|
Binary file
|
@@ -0,0 +1,105 @@
|
|
1
|
+
package org.embulk.input;
|
2
|
+
|
3
|
+
import java.sql.Connection;
|
4
|
+
import java.sql.DriverManager;
|
5
|
+
import java.sql.SQLException;
|
6
|
+
import java.util.Properties;
|
7
|
+
|
8
|
+
import org.embulk.config.Config;
|
9
|
+
import org.embulk.config.ConfigDefault;
|
10
|
+
import org.embulk.input.jdbc.AbstractJdbcInputPlugin;
|
11
|
+
import org.embulk.input.jdbc.JdbcInputConnection;
|
12
|
+
import org.embulk.input.oracle.OracleInputConnection;
|
13
|
+
|
14
|
+
import com.google.common.base.Optional;
|
15
|
+
|
16
|
+
public class OracleInputPlugin
|
17
|
+
extends AbstractJdbcInputPlugin
|
18
|
+
{
|
19
|
+
public interface OraclePluginTask
|
20
|
+
extends PluginTask
|
21
|
+
{
|
22
|
+
@Config("driver_path")
|
23
|
+
@ConfigDefault("null")
|
24
|
+
public Optional<String> getDriverPath();
|
25
|
+
|
26
|
+
@Config("host")
|
27
|
+
@ConfigDefault("null")
|
28
|
+
public Optional<String> getHost();
|
29
|
+
|
30
|
+
@Config("port")
|
31
|
+
@ConfigDefault("1521")
|
32
|
+
public int getPort();
|
33
|
+
|
34
|
+
@Config("database")
|
35
|
+
@ConfigDefault("null")
|
36
|
+
public Optional<String> getDatabase();
|
37
|
+
|
38
|
+
@Config("url")
|
39
|
+
@ConfigDefault("null")
|
40
|
+
public Optional<String> getUrl();
|
41
|
+
|
42
|
+
@Config("user")
|
43
|
+
public String getUser();
|
44
|
+
|
45
|
+
@Config("password")
|
46
|
+
@ConfigDefault("\"\"")
|
47
|
+
public String getPassword();
|
48
|
+
}
|
49
|
+
|
50
|
+
@Override
|
51
|
+
protected Class<? extends PluginTask> getTaskClass()
|
52
|
+
{
|
53
|
+
return OraclePluginTask.class;
|
54
|
+
}
|
55
|
+
|
56
|
+
@Override
|
57
|
+
protected JdbcInputConnection newConnection(PluginTask task) throws SQLException
|
58
|
+
{
|
59
|
+
OraclePluginTask oracleTask = (OraclePluginTask) task;
|
60
|
+
|
61
|
+
String url;
|
62
|
+
if (oracleTask.getUrl().isPresent()) {
|
63
|
+
if (oracleTask.getHost().isPresent() || oracleTask.getDatabase().isPresent()) {
|
64
|
+
throw new IllegalArgumentException("'host', 'port' and 'database' parameters are invalid if 'url' parameter is set.");
|
65
|
+
}
|
66
|
+
url = oracleTask.getUrl().get();
|
67
|
+
} else {
|
68
|
+
if (!oracleTask.getHost().isPresent()) {
|
69
|
+
throw new IllegalArgumentException("Field 'host' is not set.");
|
70
|
+
}
|
71
|
+
if (!oracleTask.getDatabase().isPresent()) {
|
72
|
+
throw new IllegalArgumentException("Field 'database' is not set.");
|
73
|
+
}
|
74
|
+
url = String.format("jdbc:oracle:thin:@%s:%d:%s",
|
75
|
+
oracleTask.getHost().get(), oracleTask.getPort(), oracleTask.getDatabase().get());
|
76
|
+
}
|
77
|
+
|
78
|
+
Properties props = new Properties();
|
79
|
+
props.setProperty("user", oracleTask.getUser());
|
80
|
+
props.setProperty("password", oracleTask.getPassword());
|
81
|
+
props.putAll(oracleTask.getOptions());
|
82
|
+
|
83
|
+
if (oracleTask.getDriverPath().isPresent()) {
|
84
|
+
loadDriverJar(oracleTask.getDriverPath().get());
|
85
|
+
}
|
86
|
+
|
87
|
+
try {
|
88
|
+
Class.forName("oracle.jdbc.OracleDriver");
|
89
|
+
} catch (Exception ex) {
|
90
|
+
throw new RuntimeException(ex);
|
91
|
+
}
|
92
|
+
|
93
|
+
Connection con = DriverManager.getConnection(url, props);
|
94
|
+
try {
|
95
|
+
OracleInputConnection c = new OracleInputConnection(con, oracleTask.getUser());
|
96
|
+
con = null;
|
97
|
+
return c;
|
98
|
+
} finally {
|
99
|
+
if (con != null) {
|
100
|
+
con.close();
|
101
|
+
}
|
102
|
+
}
|
103
|
+
}
|
104
|
+
|
105
|
+
}
|
@@ -0,0 +1,21 @@
|
|
1
|
+
package org.embulk.input.oracle;
|
2
|
+
|
3
|
+
import java.sql.Connection;
|
4
|
+
import java.sql.SQLException;
|
5
|
+
|
6
|
+
import org.embulk.input.jdbc.JdbcInputConnection;
|
7
|
+
|
8
|
+
public class OracleInputConnection extends JdbcInputConnection {
|
9
|
+
|
10
|
+
public OracleInputConnection(Connection connection, String schemaName) throws SQLException
|
11
|
+
{
|
12
|
+
super(connection, schemaName);
|
13
|
+
}
|
14
|
+
|
15
|
+
@Override
|
16
|
+
protected void setSearchPath(String schema) throws SQLException
|
17
|
+
{
|
18
|
+
// NOP
|
19
|
+
}
|
20
|
+
|
21
|
+
}
|
metadata
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: embulk-input-oracle
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sadayuki Furuhashi
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-06-17 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Selects records from a table.
|
14
|
+
email:
|
15
|
+
- frsyuki@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- README.md
|
21
|
+
- build.gradle
|
22
|
+
- lib/embulk/input/oracle.rb
|
23
|
+
- src/main/java/org/embulk/input/OracleInputPlugin.java
|
24
|
+
- src/main/java/org/embulk/input/oracle/OracleInputConnection.java
|
25
|
+
- classpath/embulk-input-jdbc-0.5.0.jar
|
26
|
+
- classpath/embulk-input-oracle-0.5.0.jar
|
27
|
+
homepage: https://github.com/embulk/embulk-input-jdbc
|
28
|
+
licenses:
|
29
|
+
- Apache 2.0
|
30
|
+
metadata: {}
|
31
|
+
post_install_message:
|
32
|
+
rdoc_options: []
|
33
|
+
require_paths:
|
34
|
+
- lib
|
35
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - '>='
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - '>='
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
requirements: []
|
46
|
+
rubyforge_project:
|
47
|
+
rubygems_version: 2.1.9
|
48
|
+
signing_key:
|
49
|
+
specification_version: 4
|
50
|
+
summary: JDBC input plugin for Embulk
|
51
|
+
test_files: []
|