embulk-input-postgresql 0.7.4 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/classpath/{embulk-input-jdbc-0.7.4.jar → embulk-input-jdbc-0.8.0.jar} +0 -0
- data/classpath/{embulk-input-postgresql-0.7.4.jar → embulk-input-postgresql-0.8.0.jar} +0 -0
- data/src/test/java/org/embulk/input/postgresql/PostgreSQLInputPluginTest.java +39 -63
- data/src/test/resources/yml/input_hstore.yml +4 -4
- data/src/test/resources/yml/input_hstore2.yml +4 -4
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2c06aab77369550b3a8fe22a06ed19f08813b552
|
4
|
+
data.tar.gz: fe540f426d5a51eab8768330faf2964fa0323410
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 563d09b98cd013a35089223a1f88dbf413be9dd5d894c3cd567420e0f67bd5d390eab565cdc1ad2b4dcf7c70cde6f8c1461b19a35cfa6562ddadff88a1458fb4
|
7
|
+
data.tar.gz: 5166f3f915d6159c7a576fbf0db217ad5ee153b72eaa051feb6f9c2b2c7452f38ef0cce6c1cbb83ec2313716abe0e30eef66f38ac10c91937d9150f7896a0cd8
|
data/README.md
CHANGED
Binary file
|
Binary file
|
@@ -1,83 +1,62 @@
|
|
1
1
|
package org.embulk.input.postgresql;
|
2
2
|
|
3
|
+
import static java.util.Locale.ENGLISH;
|
3
4
|
import static org.junit.Assert.assertEquals;
|
4
5
|
|
5
6
|
import java.io.BufferedReader;
|
6
|
-
import java.io.File;
|
7
7
|
import java.io.IOException;
|
8
8
|
import java.io.InputStreamReader;
|
9
|
-
import java.net.URISyntaxException;
|
10
|
-
import java.nio.charset.Charset;
|
11
|
-
import java.nio.file.FileSystem;
|
12
|
-
import java.nio.file.FileSystems;
|
13
|
-
import java.nio.file.Files;
|
14
9
|
import java.sql.Connection;
|
15
10
|
import java.sql.DriverManager;
|
16
|
-
import java.sql.
|
11
|
+
import java.sql.SQLException;
|
17
12
|
import java.util.Arrays;
|
18
|
-
import java.util.List;
|
19
13
|
|
20
|
-
import org.
|
14
|
+
import org.apache.commons.lang3.StringUtils;
|
15
|
+
import org.embulk.input.AbstractJdbcInputPluginTest;
|
21
16
|
import org.embulk.input.PostgreSQLInputPlugin;
|
22
17
|
import org.embulk.spi.InputPlugin;
|
23
|
-
import org.junit.AfterClass;
|
24
|
-
import org.junit.BeforeClass;
|
25
18
|
import org.junit.Test;
|
26
19
|
|
27
|
-
public class PostgreSQLInputPluginTest
|
20
|
+
public class PostgreSQLInputPluginTest extends AbstractJdbcInputPluginTest
|
28
21
|
{
|
29
|
-
|
30
|
-
|
31
|
-
private static final String PASSWORD = "test_pw";
|
32
|
-
private static final String URL = "jdbc:postgresql://localhost:5432/" + DATABASE;
|
33
|
-
|
34
|
-
private static boolean prepared = false;
|
35
|
-
private static EmbulkPluginTester tester = new EmbulkPluginTester(InputPlugin.class, "postgresql", PostgreSQLInputPlugin.class);
|
36
|
-
|
37
|
-
@BeforeClass
|
38
|
-
public static void prepare() throws Exception
|
22
|
+
@Override
|
23
|
+
protected void prepare() throws SQLException
|
39
24
|
{
|
25
|
+
tester.addPlugin(InputPlugin.class, "postgresql", PostgreSQLInputPlugin.class);
|
26
|
+
|
40
27
|
try {
|
41
28
|
// Create User and Database
|
42
|
-
psql(String.format("DROP DATABASE IF EXISTS %s;",
|
43
|
-
psql(String.format("DROP USER IF EXISTS %s;",
|
44
|
-
psql(String.format("CREATE USER %s WITH SUPERUSER PASSWORD '%s';",
|
45
|
-
psql(String.format("CREATE DATABASE %s WITH OWNER %s;",
|
29
|
+
psql(String.format(ENGLISH, "DROP DATABASE IF EXISTS %s;", getDatabase()));
|
30
|
+
psql(String.format(ENGLISH, "DROP USER IF EXISTS %s;", getUser()));
|
31
|
+
psql(String.format(ENGLISH, "CREATE USER %s WITH SUPERUSER PASSWORD '%s';", getUser(), getPassword()));
|
32
|
+
psql(String.format(ENGLISH, "CREATE DATABASE %s WITH OWNER %s;", getDatabase(), getUser()));
|
46
33
|
} catch (IOException e) {
|
47
34
|
System.err.println(e);
|
48
35
|
System.err.println("Warning: cannot prepare a database for testing embulk-input-postgresql.");
|
49
36
|
// 1. install postgresql.
|
50
37
|
// 2. add bin directory to path.
|
51
|
-
// 3. set environment variable PGPASSWORD
|
38
|
+
// 3. set environment variable PGPASSWORD or write pgpassword in tests.yml
|
52
39
|
return;
|
40
|
+
} catch (InterruptedException e) {
|
41
|
+
throw new RuntimeException(e);
|
53
42
|
}
|
54
43
|
|
55
|
-
|
44
|
+
enabled = true;
|
56
45
|
|
57
46
|
// Insert Data
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
sql += "INSERT INTO input_hstore (c1) VALUES('\"a\" => \"b\"');";
|
65
|
-
statement.execute(sql);
|
66
|
-
}
|
67
|
-
}
|
68
|
-
}
|
69
|
-
|
70
|
-
@AfterClass
|
71
|
-
public static void dispose()
|
72
|
-
{
|
73
|
-
tester.destroy();
|
47
|
+
String sql = "";
|
48
|
+
sql += "DROP TABLE IF EXISTS input_hstore;";
|
49
|
+
sql += "CREATE EXTENSION IF NOT EXISTS hstore WITH SCHEMA public;";
|
50
|
+
sql += "CREATE TABLE input_hstore (c1 hstore);";
|
51
|
+
sql += "INSERT INTO input_hstore (c1) VALUES('\"a\" => \"b\"');";
|
52
|
+
executeSQL(sql);
|
74
53
|
}
|
75
54
|
|
76
55
|
@Test
|
77
56
|
public void testHstoreAsString() throws Exception
|
78
57
|
{
|
79
|
-
if (
|
80
|
-
|
58
|
+
if (enabled) {
|
59
|
+
test("/yml/input_hstore.yml");
|
81
60
|
assertEquals(Arrays.asList("c1", "\"\"\"a\"\"=>\"\"b\"\"\""),
|
82
61
|
read("postgresql-input000.00.csv"));
|
83
62
|
}
|
@@ -86,29 +65,19 @@ public class PostgreSQLInputPluginTest
|
|
86
65
|
@Test
|
87
66
|
public void testHstoreAsJson() throws Exception
|
88
67
|
{
|
89
|
-
if (
|
90
|
-
|
68
|
+
if (enabled) {
|
69
|
+
test("/yml/input_hstore2.yml");
|
91
70
|
assertEquals(Arrays.asList("c1", "\"{\"\"a\"\":\"\"b\"\"}\""),
|
92
71
|
read("postgresql-input000.00.csv"));
|
93
72
|
}
|
94
73
|
}
|
95
74
|
|
96
|
-
private
|
97
|
-
{
|
98
|
-
FileSystem fs = FileSystems.getDefault();
|
99
|
-
return Files.readAllLines(fs.getPath(path), Charset.defaultCharset());
|
100
|
-
}
|
101
|
-
|
102
|
-
private String convertPath(String name) throws URISyntaxException
|
103
|
-
{
|
104
|
-
if (getClass().getResource(name) == null) {
|
105
|
-
return name;
|
106
|
-
}
|
107
|
-
return new File(getClass().getResource(name).toURI()).getAbsolutePath();
|
108
|
-
}
|
109
|
-
|
110
|
-
private static void psql(String sql) throws IOException, InterruptedException {
|
75
|
+
private void psql(String sql) throws IOException, InterruptedException {
|
111
76
|
ProcessBuilder pb = new ProcessBuilder("psql", "-w", "-c", sql);
|
77
|
+
String pgPassword = (String)getTestConfig("pgpassword", false);
|
78
|
+
if (!StringUtils.isEmpty(pgPassword)) {
|
79
|
+
pb.environment().put("PGPASSWORD", pgPassword);
|
80
|
+
}
|
112
81
|
System.out.println("PSQL: " + pb.command().toString());
|
113
82
|
final Process process = pb.start();
|
114
83
|
final int code = process.waitFor();
|
@@ -123,4 +92,11 @@ public class PostgreSQLInputPluginTest
|
|
123
92
|
"Command finished with non-zero exit code. Exit code is %d.", code));
|
124
93
|
}
|
125
94
|
}
|
95
|
+
|
96
|
+
@Override
|
97
|
+
protected Connection connect() throws SQLException
|
98
|
+
{
|
99
|
+
return DriverManager.getConnection(String.format(ENGLISH, "jdbc:postgresql://%s:%d/%s", getHost(), getPort(), getDatabase()),
|
100
|
+
getUser(), getPassword());
|
101
|
+
}
|
126
102
|
}
|
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
|
+
version: 0.8.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: 2016-
|
11
|
+
date: 2016-10-13 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Selects records from a table.
|
14
14
|
email:
|
@@ -19,8 +19,8 @@ extra_rdoc_files: []
|
|
19
19
|
files:
|
20
20
|
- README.md
|
21
21
|
- build.gradle
|
22
|
-
- classpath/embulk-input-jdbc-0.
|
23
|
-
- classpath/embulk-input-postgresql-0.
|
22
|
+
- classpath/embulk-input-jdbc-0.8.0.jar
|
23
|
+
- classpath/embulk-input-postgresql-0.8.0.jar
|
24
24
|
- classpath/postgresql-9.4-1205-jdbc41.jar
|
25
25
|
- lib/embulk/input/postgresql.rb
|
26
26
|
- src/main/java/org/embulk/input/PostgreSQLInputPlugin.java
|