embulk-input-sqlserver 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a5a1730a2670e28e2dda5ba09c2e9709ff9a84a3
4
+ data.tar.gz: dc4ce4f5a11f96f0f78abe0a0fa17a38305a6e64
5
+ SHA512:
6
+ metadata.gz: 50c65fc5f5e5a37efc03480c953ee266cb5816d7d90ba0fa60923271baef2791d234db0ec9966f18aac8bda9adb896c954acee3f179eb4e1e885149608e218aa
7
+ data.tar.gz: 8466efeb12ebd8fa0356fbf622a7d6d07092bf7030bc5f00ae605d8cc689f304346316bbf84f1ef888f058e718d6f7317b224eff0eff6d3fdc7a8dc053e64679
data/README.md ADDED
@@ -0,0 +1,102 @@
1
+ # SQL Server input plugins for Embulk
2
+
3
+ SQL Server input plugins for Embulk loads records from SQL Server.
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 SQL Server JDBC driver (string)
13
+ - **host**: database host name (string, required if url is not set)
14
+ - **port**: database port number (integer, default: 1433)
15
+ - **integratedSecutiry**: whether to use integrated authentication or not. The `sqljdbc_auth.dll` must be located on Java library path if using integrated authentication. : (boolean, default: false)
16
+ ```
17
+ rem C:\drivers\sqljdbc_auth.dll
18
+ embulk "-J-Djava.library.path=C:\drivers" run input-sqlserver.yml
19
+ ```
20
+ - **user**: database login user name (string, required if not using integrated authentication)
21
+ - **password**: database login password (string, default: "")
22
+ - **instance**: destination instance name (string, default: use the default instance)
23
+ - **database**: destination database name (string, default: use the default database)
24
+ - **url**: URL of the JDBC connection (string, optional)
25
+ - If you write SQL directly,
26
+ - **query**: SQL to run (string)
27
+ - If **query** is not set,
28
+ - **table**: destination table name (string, required)
29
+ - **select**: comma-separated list of columns to select (string, default: "*")
30
+ - **where**: WHERE condition to filter the rows (string, default: no-condition)
31
+ - **fetch_rows**: number of rows to fetch one time (used for java.sql.Statement#setFetchSize) (integer, default: 10000)
32
+ - **options**: extra JDBC properties (hash, default: {})
33
+ - **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`)
34
+ - **column_options**: advanced: a key-value pairs where key is a column name and value is options for the column.
35
+ - **value_type**: embulk get values from database as this value_type. Typically, the value_type determines `getXXX` method of `java.sql.PreparedStatement`.
36
+ (string, default: depends on the sql type of the column. Available values options are: `long`, `double`, `float`, `decimal`, `boolean`, `string`, `date`, `time`, `timestamp`)
37
+ - **type**: Column values are converted to this embulk type.
38
+ Available values options are: `boolean`, `long`, `double`, `string`, `timestamp`).
39
+ By default, the embulk type is determined according to the sql type of the column (or value_type if specified).
40
+ - **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 may be used in the output plugin. For example, stdout plugin use the timestamp_format, but *csv formatter plugin doesn't use*. (string, default : `%Y-%m-%d` for `date`, `%H:%M:%S` for `time`, `%Y-%m-%d %H:%M:%S` for `timestamp`)
41
+ - **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.
42
+ (string, value of default_timezone option is used by default)
43
+
44
+ ## Example
45
+
46
+ ```yaml
47
+ in:
48
+ type: sqlserver
49
+ driver_path: C:\drivers\sqljdbc41.jar
50
+ host: localhost
51
+ user: myuser
52
+ password: ""
53
+ instance: MSSQLSERVER
54
+ database: my_database
55
+ table: my_table
56
+ select: "col1, col2, col3"
57
+ where: "col4 != 'a'"
58
+ ```
59
+
60
+ If you need a complex SQL,
61
+
62
+ ```yaml
63
+ in:
64
+ type: sqlserver
65
+ driver_path: C:\drivers\sqljdbc41.jar
66
+ host: localhost
67
+ user: myuser
68
+ password: ""
69
+ instance: MSSQLSERVER
70
+ database: my_database
71
+ query: |
72
+ SELECT t1.id, t1.name, t2.id AS t2_id, t2.name AS t2_name
73
+ FROM table1 AS t1
74
+ LEFT JOIN table2 AS t2
75
+ ON t1.id = t2.t1_id
76
+ ```
77
+
78
+ Advanced configuration:
79
+
80
+ ```yaml
81
+ in:
82
+ type: sqlserver
83
+ driver_path: C:\drivers\sqljdbc41.jar
84
+ host: localhost
85
+ user: myuser
86
+ password: ""
87
+ instance: MSSQLSERVER
88
+ database: my_database
89
+ table: "my_table"
90
+ select: "col1, col2, col3"
91
+ where: "col4 != 'a'"
92
+ column_options:
93
+ col1: {type: long}
94
+ col3: {type: string, timestamp_format: "%Y/%m/%d", timezone: "+0900"}
95
+
96
+ ```
97
+
98
+ ## Build
99
+
100
+ ```
101
+ $ ./gradlew gem
102
+ ```
data/build.gradle ADDED
@@ -0,0 +1,5 @@
1
+ dependencies {
2
+ compile project(':embulk-input-jdbc')
3
+
4
+ testCompile project(':embulk-input-jdbc').sourceSets.test.output
5
+ }
@@ -0,0 +1,3 @@
1
+ Embulk::JavaPlugin.register_input(
2
+ :sqlserver, "org.embulk.input.SQLServerInputPlugin",
3
+ File.expand_path('../../../../classpath', __FILE__))
@@ -0,0 +1,145 @@
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.sqlserver.SQLServerInputConnection;
13
+
14
+ import com.google.common.base.Optional;
15
+
16
+ public class SQLServerInputPlugin
17
+ extends AbstractJdbcInputPlugin
18
+ {
19
+ public interface SQLServerPluginTask
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("1433")
32
+ public int getPort();
33
+
34
+ @Config("instance")
35
+ @ConfigDefault("null")
36
+ public Optional<String> getInstance();
37
+
38
+ @Config("database")
39
+ @ConfigDefault("null")
40
+ public Optional<String> getDatabase();
41
+
42
+ @Config("integratedSecurity")
43
+ @ConfigDefault("null")
44
+ public Optional<Boolean> getIntegratedSecurity();
45
+
46
+ @Config("url")
47
+ @ConfigDefault("null")
48
+ public Optional<String> getUrl();
49
+
50
+ @Config("user")
51
+ @ConfigDefault("null")
52
+ public Optional<String> getUser();
53
+
54
+ @Config("password")
55
+ @ConfigDefault("\"\"")
56
+ public Optional<String> getPassword();
57
+
58
+ @Config("schema")
59
+ @ConfigDefault("null")
60
+ public Optional<String> getSchema();
61
+ }
62
+
63
+ @Override
64
+ protected Class<? extends PluginTask> getTaskClass()
65
+ {
66
+ return SQLServerPluginTask.class;
67
+ }
68
+
69
+ @Override
70
+ protected JdbcInputConnection newConnection(PluginTask task) throws SQLException
71
+ {
72
+ SQLServerPluginTask sqlServerTask = (SQLServerPluginTask) task;
73
+
74
+ String url;
75
+ if (sqlServerTask.getUrl().isPresent()) {
76
+ if (sqlServerTask.getHost().isPresent()
77
+ || sqlServerTask.getInstance().isPresent()
78
+ || sqlServerTask.getDatabase().isPresent()
79
+ || sqlServerTask.getIntegratedSecurity().isPresent()) {
80
+ throw new IllegalArgumentException("'host', 'port', 'instance', 'database' and 'integratedSecurity' parameters are invalid if 'url' parameter is set.");
81
+ }
82
+ url = sqlServerTask.getUrl().get();
83
+ } else {
84
+ if (!sqlServerTask.getHost().isPresent()) {
85
+ throw new IllegalArgumentException("Field 'host' is not set.");
86
+ }
87
+ if (!sqlServerTask.getDatabase().isPresent()) {
88
+ throw new IllegalArgumentException("Field 'database' is not set.");
89
+ }
90
+ StringBuilder urlBuilder = new StringBuilder();
91
+ if (sqlServerTask.getInstance().isPresent()) {
92
+ urlBuilder.append(String.format("jdbc:sqlserver://%s\\%s:%d",
93
+ sqlServerTask.getHost().get(), sqlServerTask.getInstance().get(), sqlServerTask.getPort()));
94
+ } else {
95
+ urlBuilder.append(String.format("jdbc:sqlserver://%s:%d",
96
+ sqlServerTask.getHost().get(), sqlServerTask.getPort()));
97
+ }
98
+ if (sqlServerTask.getDatabase().isPresent()) {
99
+ urlBuilder.append(";databaseName=" + sqlServerTask.getDatabase().get());
100
+ }
101
+ if (sqlServerTask.getIntegratedSecurity().isPresent() && sqlServerTask.getIntegratedSecurity().get()) {
102
+ urlBuilder.append(";integratedSecurity=" + sqlServerTask.getIntegratedSecurity().get());
103
+ } else {
104
+ if (!sqlServerTask.getUser().isPresent()) {
105
+ throw new IllegalArgumentException("Field 'user' is not set.");
106
+ }
107
+ if (!sqlServerTask.getPassword().isPresent()) {
108
+ throw new IllegalArgumentException("Field 'password' is not set.");
109
+ }
110
+ }
111
+ url = urlBuilder.toString();
112
+ }
113
+
114
+ Properties props = new Properties();
115
+ if (sqlServerTask.getUser().isPresent()) {
116
+ props.setProperty("user", sqlServerTask.getUser().get());
117
+ }
118
+ if (sqlServerTask.getPassword().isPresent()) {
119
+ props.setProperty("password", sqlServerTask.getPassword().get());
120
+ }
121
+ props.putAll(sqlServerTask.getOptions());
122
+
123
+ if (sqlServerTask.getDriverPath().isPresent()) {
124
+ loadDriverJar(sqlServerTask.getDriverPath().get());
125
+ }
126
+
127
+ try {
128
+ Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
129
+ } catch (Exception ex) {
130
+ throw new RuntimeException(ex);
131
+ }
132
+
133
+ Connection con = DriverManager.getConnection(url, props);
134
+ try {
135
+ SQLServerInputConnection c = new SQLServerInputConnection(con, sqlServerTask.getSchema().orNull());
136
+ con = null;
137
+ return c;
138
+ } finally {
139
+ if (con != null) {
140
+ con.close();
141
+ }
142
+ }
143
+ }
144
+
145
+ }
@@ -0,0 +1,21 @@
1
+ package org.embulk.input.sqlserver;
2
+
3
+ import java.sql.Connection;
4
+ import java.sql.SQLException;
5
+
6
+ import org.embulk.input.jdbc.JdbcInputConnection;
7
+
8
+ public class SQLServerInputConnection extends JdbcInputConnection {
9
+
10
+ public SQLServerInputConnection(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-sqlserver
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.6.0
5
+ platform: ruby
6
+ authors:
7
+ - Sadayuki Furuhashi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-07-07 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/sqlserver.rb
23
+ - src/main/java/org/embulk/input/SQLServerInputPlugin.java
24
+ - src/main/java/org/embulk/input/sqlserver/SQLServerInputConnection.java
25
+ - classpath/embulk-input-jdbc-0.6.0.jar
26
+ - classpath/embulk-input-sqlserver-0.6.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: []