embulk-output-jdbc 0.5.0 → 0.5.1
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 +4 -4
- data/classpath/{embulk-output-jdbc-0.5.0.jar → embulk-output-jdbc-0.5.1.jar} +0 -0
- data/src/main/java/org/embulk/output/JdbcOutputPlugin.java +2 -0
- data/src/main/java/org/embulk/output/jdbc/TimestampFormat.java +37 -0
- data/src/test/java/org/embulk/output/TimestampFormatTest.java +59 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b9fcb08c1a3c9afee4fbf4ceaff31436edaf7530
|
4
|
+
data.tar.gz: 9be57c753cfa20b5b416db21144498af5f3f6338
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 226037b92383771a74da77abde6615cbbb3015a138431ffa80a8ef14aa462dfd2c6b7b48e23d0ebf82c5b7457985a1a3f250c01996fc4131a2469b9543d41cb6
|
7
|
+
data.tar.gz: f5a4a8c4bd1aecdb15abd3d64104beb8daae4ccd90402a0f663e169f0186318c8170a727d05afb14ef077eff76c11b759a42043747baff783e490bd83ac568f9
|
Binary file
|
@@ -6,9 +6,11 @@ import java.sql.Driver;
|
|
6
6
|
import java.io.IOException;
|
7
7
|
import java.sql.Connection;
|
8
8
|
import java.sql.SQLException;
|
9
|
+
|
9
10
|
import com.google.common.base.Optional;
|
10
11
|
import com.google.common.base.Throwables;
|
11
12
|
import com.google.common.collect.ImmutableSet;
|
13
|
+
|
12
14
|
import org.embulk.config.Config;
|
13
15
|
import org.embulk.config.ConfigDefault;
|
14
16
|
import org.embulk.output.jdbc.AbstractJdbcOutputPlugin;
|
@@ -0,0 +1,37 @@
|
|
1
|
+
package org.embulk.output.jdbc;
|
2
|
+
|
3
|
+
import java.sql.Timestamp;
|
4
|
+
import java.text.FieldPosition;
|
5
|
+
import java.text.SimpleDateFormat;
|
6
|
+
import java.util.Date;
|
7
|
+
|
8
|
+
|
9
|
+
public class TimestampFormat extends SimpleDateFormat
|
10
|
+
{
|
11
|
+
|
12
|
+
private final int scale;
|
13
|
+
|
14
|
+
public TimestampFormat(String pattern, int scale)
|
15
|
+
{
|
16
|
+
super(pattern);
|
17
|
+
|
18
|
+
this.scale = scale;
|
19
|
+
}
|
20
|
+
|
21
|
+
@Override
|
22
|
+
public StringBuffer format(Date date, StringBuffer toAppendTo, FieldPosition pos)
|
23
|
+
{
|
24
|
+
StringBuffer buffer = super.format(date, toAppendTo, pos);
|
25
|
+
if (scale > 0) {
|
26
|
+
buffer.append('.');
|
27
|
+
String nanos = Integer.toString(((Timestamp)date).getNanos());
|
28
|
+
int zeros = Math.min(scale, 9 - nanos.length());
|
29
|
+
for (int i = 0; i < zeros; i++) {
|
30
|
+
buffer.append('0');
|
31
|
+
}
|
32
|
+
buffer.append(nanos.substring(0, scale - zeros));
|
33
|
+
}
|
34
|
+
return buffer;
|
35
|
+
}
|
36
|
+
|
37
|
+
}
|
@@ -0,0 +1,59 @@
|
|
1
|
+
package org.embulk.output;
|
2
|
+
|
3
|
+
import java.sql.Timestamp;
|
4
|
+
import java.text.ParseException;
|
5
|
+
import java.text.SimpleDateFormat;
|
6
|
+
import java.util.Date;
|
7
|
+
|
8
|
+
import org.embulk.output.jdbc.TimestampFormat;
|
9
|
+
import org.junit.Test;
|
10
|
+
|
11
|
+
import static org.junit.Assert.assertEquals;
|
12
|
+
|
13
|
+
public class TimestampFormatTest {
|
14
|
+
|
15
|
+
@Test
|
16
|
+
public void test() throws ParseException
|
17
|
+
{
|
18
|
+
Date date = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").parse("2015/03/04 17:08:09");
|
19
|
+
Timestamp t = new Timestamp(date.getTime());
|
20
|
+
|
21
|
+
{
|
22
|
+
TimestampFormat format = new TimestampFormat("yyyy-MM-dd HH:mm:ss", 9);
|
23
|
+
assertEquals("2015-03-04 17:08:09.000000000", format.format(t));
|
24
|
+
}
|
25
|
+
{
|
26
|
+
TimestampFormat format = new TimestampFormat("yyyy-MM-dd HH:mm:ss", 0);
|
27
|
+
assertEquals("2015-03-04 17:08:09", format.format(t));
|
28
|
+
}
|
29
|
+
{
|
30
|
+
TimestampFormat format = new TimestampFormat("yyyy-MM-dd HH:mm:ss", 1);
|
31
|
+
assertEquals("2015-03-04 17:08:09.0", format.format(t));
|
32
|
+
}
|
33
|
+
|
34
|
+
t.setNanos(1234567);
|
35
|
+
{
|
36
|
+
TimestampFormat format = new TimestampFormat("yyyy-MM-dd HH:mm:ss", 9);
|
37
|
+
assertEquals("2015-03-04 17:08:09.001234567", format.format(t));
|
38
|
+
}
|
39
|
+
{
|
40
|
+
TimestampFormat format = new TimestampFormat("yyyy-MM-dd HH:mm:ss", 2);
|
41
|
+
assertEquals("2015-03-04 17:08:09.00", format.format(t));
|
42
|
+
}
|
43
|
+
{
|
44
|
+
TimestampFormat format = new TimestampFormat("yyyy-MM-dd HH:mm:ss", 3);
|
45
|
+
assertEquals("2015-03-04 17:08:09.001", format.format(t));
|
46
|
+
}
|
47
|
+
|
48
|
+
t.setNanos(123456789);
|
49
|
+
{
|
50
|
+
TimestampFormat format = new TimestampFormat("yyyy-MM-dd HH:mm:ss", 9);
|
51
|
+
assertEquals("2015-03-04 17:08:09.123456789", format.format(t));
|
52
|
+
}
|
53
|
+
{
|
54
|
+
TimestampFormat format = new TimestampFormat("yyyy-MM-dd HH:mm:ss", 1);
|
55
|
+
assertEquals("2015-03-04 17:08:09.1", format.format(t));
|
56
|
+
}
|
57
|
+
}
|
58
|
+
|
59
|
+
}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: embulk-output-jdbc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.1
|
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-03-29 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Inserts or updates records to a table.
|
14
14
|
email:
|
@@ -29,6 +29,7 @@ files:
|
|
29
29
|
- src/main/java/org/embulk/output/jdbc/JdbcSchema.java
|
30
30
|
- src/main/java/org/embulk/output/jdbc/JdbcUtils.java
|
31
31
|
- src/main/java/org/embulk/output/jdbc/StandardBatchInsert.java
|
32
|
+
- src/main/java/org/embulk/output/jdbc/TimestampFormat.java
|
32
33
|
- src/main/java/org/embulk/output/jdbc/ToString.java
|
33
34
|
- src/main/java/org/embulk/output/jdbc/ToStringMap.java
|
34
35
|
- src/main/java/org/embulk/output/jdbc/setter/BigDecimalColumnSetter.java
|
@@ -54,8 +55,9 @@ files:
|
|
54
55
|
- src/main/java/org/embulk/output/jdbc/setter/StringColumnSetter.java
|
55
56
|
- src/test/java/org/embulk/output/AbstractJdbcOutputPluginTest.java
|
56
57
|
- src/test/java/org/embulk/output/TestJdbcOutputPlugin.java
|
58
|
+
- src/test/java/org/embulk/output/TimestampFormatTest.java
|
57
59
|
- src/test/java/org/embulk/output/tester/EmbulkPluginTester.java
|
58
|
-
- classpath/embulk-output-jdbc-0.5.
|
60
|
+
- classpath/embulk-output-jdbc-0.5.1.jar
|
59
61
|
homepage: https://github.com/embulk/embulk-output-jdbc
|
60
62
|
licenses:
|
61
63
|
- Apache 2.0
|