embulk-input-athena 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -1
- data/build.gradle +7 -3
- data/src/main/java/org/embulk/input/athena/AthenaInputConnection.java +1 -0
- metadata +4 -28
- data/src/main/java/org/embulk/input/jdbc/AbstractJdbcInputPlugin.java +0 -674
- data/src/main/java/org/embulk/input/jdbc/JdbcColumn.java +0 -58
- data/src/main/java/org/embulk/input/jdbc/JdbcColumnOption.java +0 -31
- data/src/main/java/org/embulk/input/jdbc/JdbcInputConnection.java +0 -397
- data/src/main/java/org/embulk/input/jdbc/JdbcLiteral.java +0 -38
- data/src/main/java/org/embulk/input/jdbc/JdbcSchema.java +0 -55
- data/src/main/java/org/embulk/input/jdbc/Ssl.java +0 -37
- data/src/main/java/org/embulk/input/jdbc/ToString.java +0 -54
- data/src/main/java/org/embulk/input/jdbc/ToStringMap.java +0 -35
- data/src/main/java/org/embulk/input/jdbc/getter/AbstractColumnGetter.java +0 -105
- data/src/main/java/org/embulk/input/jdbc/getter/AbstractIncrementalHandler.java +0 -45
- data/src/main/java/org/embulk/input/jdbc/getter/AbstractTimestampColumnGetter.java +0 -38
- data/src/main/java/org/embulk/input/jdbc/getter/BigDecimalColumnGetter.java +0 -59
- data/src/main/java/org/embulk/input/jdbc/getter/BooleanColumnGetter.java +0 -56
- data/src/main/java/org/embulk/input/jdbc/getter/ColumnGetter.java +0 -21
- data/src/main/java/org/embulk/input/jdbc/getter/ColumnGetterFactory.java +0 -207
- data/src/main/java/org/embulk/input/jdbc/getter/DateColumnGetter.java +0 -37
- data/src/main/java/org/embulk/input/jdbc/getter/DoubleColumnGetter.java +0 -66
- data/src/main/java/org/embulk/input/jdbc/getter/FloatColumnGetter.java +0 -66
- data/src/main/java/org/embulk/input/jdbc/getter/JsonColumnGetter.java +0 -57
- data/src/main/java/org/embulk/input/jdbc/getter/LongColumnGetter.java +0 -70
- data/src/main/java/org/embulk/input/jdbc/getter/StringColumnGetter.java +0 -96
- data/src/main/java/org/embulk/input/jdbc/getter/TimeColumnGetter.java +0 -37
- data/src/main/java/org/embulk/input/jdbc/getter/TimestampColumnGetter.java +0 -36
- data/src/main/java/org/embulk/input/jdbc/getter/TimestampWithTimeZoneIncrementalHandler.java +0 -83
- data/src/main/java/org/embulk/input/jdbc/getter/TimestampWithoutTimeZoneIncrementalHandler.java +0 -75
@@ -1,56 +0,0 @@
|
|
1
|
-
package org.embulk.input.jdbc.getter;
|
2
|
-
|
3
|
-
import java.sql.ResultSet;
|
4
|
-
import java.sql.SQLException;
|
5
|
-
import org.embulk.spi.Column;
|
6
|
-
import org.embulk.spi.PageBuilder;
|
7
|
-
import org.embulk.spi.type.Type;
|
8
|
-
import org.embulk.spi.type.Types;
|
9
|
-
|
10
|
-
public class BooleanColumnGetter
|
11
|
-
extends AbstractColumnGetter
|
12
|
-
{
|
13
|
-
protected boolean value;
|
14
|
-
|
15
|
-
public BooleanColumnGetter(PageBuilder to, Type toType)
|
16
|
-
{
|
17
|
-
super(to, toType);
|
18
|
-
}
|
19
|
-
|
20
|
-
@Override
|
21
|
-
protected void fetch(ResultSet from, int fromIndex) throws SQLException
|
22
|
-
{
|
23
|
-
value = from.getBoolean(fromIndex);
|
24
|
-
}
|
25
|
-
|
26
|
-
@Override
|
27
|
-
protected Type getDefaultToType()
|
28
|
-
{
|
29
|
-
return Types.BOOLEAN;
|
30
|
-
}
|
31
|
-
|
32
|
-
@Override
|
33
|
-
public void booleanColumn(Column column)
|
34
|
-
{
|
35
|
-
to.setBoolean(column, value);
|
36
|
-
}
|
37
|
-
|
38
|
-
@Override
|
39
|
-
public void longColumn(Column column)
|
40
|
-
{
|
41
|
-
to.setLong(column, value ? 1L : 0L);
|
42
|
-
}
|
43
|
-
|
44
|
-
@Override
|
45
|
-
public void doubleColumn(Column column)
|
46
|
-
{
|
47
|
-
to.setDouble(column, value ? 1.0 : 0.0);
|
48
|
-
}
|
49
|
-
|
50
|
-
@Override
|
51
|
-
public void stringColumn(Column column)
|
52
|
-
{
|
53
|
-
to.setString(column, Boolean.toString(value));
|
54
|
-
}
|
55
|
-
|
56
|
-
}
|
@@ -1,21 +0,0 @@
|
|
1
|
-
package org.embulk.input.jdbc.getter;
|
2
|
-
|
3
|
-
import java.sql.ResultSet;
|
4
|
-
import java.sql.SQLException;
|
5
|
-
import java.sql.PreparedStatement;
|
6
|
-
import com.fasterxml.jackson.databind.JsonNode;
|
7
|
-
import org.embulk.spi.Column;
|
8
|
-
import org.embulk.spi.type.Type;
|
9
|
-
|
10
|
-
public interface ColumnGetter
|
11
|
-
{
|
12
|
-
public void getAndSet(ResultSet from, int fromIndex,
|
13
|
-
Column toColumn) throws SQLException;
|
14
|
-
|
15
|
-
public Type getToType();
|
16
|
-
|
17
|
-
public JsonNode encodeToJson();
|
18
|
-
|
19
|
-
public void decodeFromJsonTo(PreparedStatement toStatement, int toIndex, JsonNode fromValue)
|
20
|
-
throws SQLException;
|
21
|
-
}
|
@@ -1,207 +0,0 @@
|
|
1
|
-
package org.embulk.input.jdbc.getter;
|
2
|
-
|
3
|
-
import java.lang.reflect.Field;
|
4
|
-
import java.sql.Types;
|
5
|
-
import java.util.HashMap;
|
6
|
-
import java.util.Map;
|
7
|
-
|
8
|
-
import com.google.common.base.Optional;
|
9
|
-
import org.embulk.config.ConfigException;
|
10
|
-
import org.embulk.config.ConfigSource;
|
11
|
-
import org.embulk.config.Task;
|
12
|
-
import org.embulk.input.jdbc.AbstractJdbcInputPlugin.PluginTask;
|
13
|
-
import org.embulk.input.jdbc.JdbcColumn;
|
14
|
-
import org.embulk.input.jdbc.JdbcColumnOption;
|
15
|
-
import org.embulk.input.jdbc.JdbcInputConnection;
|
16
|
-
import org.embulk.spi.Exec;
|
17
|
-
import org.embulk.spi.PageBuilder;
|
18
|
-
import org.embulk.spi.time.TimestampFormatter;
|
19
|
-
import org.embulk.spi.type.TimestampType;
|
20
|
-
import org.embulk.spi.type.Type;
|
21
|
-
import org.joda.time.DateTimeZone;
|
22
|
-
|
23
|
-
import static java.util.Locale.ENGLISH;
|
24
|
-
|
25
|
-
public class ColumnGetterFactory
|
26
|
-
{
|
27
|
-
protected final PageBuilder to;
|
28
|
-
private final DateTimeZone defaultTimeZone;
|
29
|
-
private final Map<Integer, String> jdbcTypes = getAllJDBCTypes();
|
30
|
-
|
31
|
-
public ColumnGetterFactory(PageBuilder to, DateTimeZone defaultTimeZone)
|
32
|
-
{
|
33
|
-
this.to = to;
|
34
|
-
this.defaultTimeZone = defaultTimeZone;
|
35
|
-
}
|
36
|
-
|
37
|
-
public ColumnGetter newColumnGetter(JdbcInputConnection con, PluginTask task, JdbcColumn column, JdbcColumnOption option)
|
38
|
-
{
|
39
|
-
return newColumnGetter(con, task, column, option, option.getValueType());
|
40
|
-
}
|
41
|
-
|
42
|
-
private ColumnGetter newColumnGetter(JdbcInputConnection con, PluginTask task, JdbcColumn column, JdbcColumnOption option, String valueType)
|
43
|
-
{
|
44
|
-
Type toType = getToType(option);
|
45
|
-
switch(valueType) {
|
46
|
-
case "coalesce":
|
47
|
-
// resolve actual valueType using sqlTypeToValueType() method and retry.
|
48
|
-
return newColumnGetter(con, task, column, option, sqlTypeToValueType(column, column.getSqlType()));
|
49
|
-
case "long":
|
50
|
-
return new LongColumnGetter(to, toType);
|
51
|
-
case "float":
|
52
|
-
return new FloatColumnGetter(to, toType);
|
53
|
-
case "double":
|
54
|
-
return new DoubleColumnGetter(to, toType);
|
55
|
-
case "boolean":
|
56
|
-
return new BooleanColumnGetter(to, toType);
|
57
|
-
case "string":
|
58
|
-
return new StringColumnGetter(to, toType);
|
59
|
-
case "json":
|
60
|
-
return new JsonColumnGetter(to, toType);
|
61
|
-
case "date":
|
62
|
-
return new DateColumnGetter(to, toType, newTimestampFormatter(option, DateColumnGetter.DEFAULT_FORMAT));
|
63
|
-
case "time":
|
64
|
-
return new TimeColumnGetter(to, toType, newTimestampFormatter(option, DateColumnGetter.DEFAULT_FORMAT));
|
65
|
-
case "timestamp":
|
66
|
-
return new TimestampColumnGetter(to, toType, newTimestampFormatter(option, DateColumnGetter.DEFAULT_FORMAT));
|
67
|
-
case "decimal":
|
68
|
-
return new BigDecimalColumnGetter(to, toType);
|
69
|
-
default:
|
70
|
-
throw new ConfigException(String.format(ENGLISH,
|
71
|
-
"Unknown value_type '%s' for column '%s'", option.getValueType(), column.getName()));
|
72
|
-
}
|
73
|
-
}
|
74
|
-
|
75
|
-
protected Map<Integer,String> getAllJDBCTypes() {
|
76
|
-
Map<Integer,String> map = new HashMap<Integer, String>();
|
77
|
-
for(Field f: Types.class.getFields()){
|
78
|
-
try {
|
79
|
-
map.put((Integer) f.get(null), f.getName());
|
80
|
-
} catch(IllegalAccessException iea){
|
81
|
-
}
|
82
|
-
}
|
83
|
-
return map;
|
84
|
-
}
|
85
|
-
|
86
|
-
public String getJdbcType(int sqlType)
|
87
|
-
{
|
88
|
-
return jdbcTypes.get(sqlType);
|
89
|
-
}
|
90
|
-
|
91
|
-
|
92
|
-
protected String sqlTypeToValueType(JdbcColumn column, int sqlType)
|
93
|
-
{
|
94
|
-
switch(sqlType) {
|
95
|
-
// getLong
|
96
|
-
case Types.TINYINT:
|
97
|
-
case Types.SMALLINT:
|
98
|
-
case Types.INTEGER:
|
99
|
-
case Types.BIGINT:
|
100
|
-
return "long";
|
101
|
-
|
102
|
-
// getFloat
|
103
|
-
case Types.FLOAT:
|
104
|
-
case Types.REAL:
|
105
|
-
return "float";
|
106
|
-
|
107
|
-
// getDouble
|
108
|
-
case Types.DOUBLE:
|
109
|
-
return "double";
|
110
|
-
|
111
|
-
// getBool
|
112
|
-
case Types.BOOLEAN:
|
113
|
-
case Types.BIT: // JDBC BIT is boolean, unlike SQL-92
|
114
|
-
return "boolean";
|
115
|
-
|
116
|
-
// getString, Clob
|
117
|
-
case Types.CHAR:
|
118
|
-
case Types.VARCHAR:
|
119
|
-
case Types.LONGVARCHAR:
|
120
|
-
case Types.CLOB:
|
121
|
-
case Types.NCHAR:
|
122
|
-
case Types.NVARCHAR:
|
123
|
-
case Types.LONGNVARCHAR:
|
124
|
-
return "string";
|
125
|
-
|
126
|
-
// TODO
|
127
|
-
//// getBytes Blob
|
128
|
-
//case Types.BINARY:
|
129
|
-
//case Types.VARBINARY:
|
130
|
-
//case Types.LONGVARBINARY:
|
131
|
-
//case Types.BLOB:
|
132
|
-
// return new BytesColumnGetter();
|
133
|
-
|
134
|
-
// getDate
|
135
|
-
case Types.DATE:
|
136
|
-
return "date";
|
137
|
-
|
138
|
-
// getTime
|
139
|
-
case Types.TIME:
|
140
|
-
return "time";
|
141
|
-
|
142
|
-
// getTimestamp
|
143
|
-
case Types.TIMESTAMP:
|
144
|
-
return "timestamp";
|
145
|
-
|
146
|
-
// TODO
|
147
|
-
//// Null
|
148
|
-
//case Types.NULL:
|
149
|
-
// return new NullColumnGetter();
|
150
|
-
|
151
|
-
// getBigDecimal
|
152
|
-
case Types.NUMERIC:
|
153
|
-
case Types.DECIMAL:
|
154
|
-
return "decimal";
|
155
|
-
|
156
|
-
// others
|
157
|
-
case Types.ARRAY: // array
|
158
|
-
case Types.STRUCT: // map
|
159
|
-
case Types.REF:
|
160
|
-
case Types.DATALINK:
|
161
|
-
case Types.SQLXML: // XML
|
162
|
-
case Types.ROWID:
|
163
|
-
case Types.DISTINCT:
|
164
|
-
case Types.JAVA_OBJECT:
|
165
|
-
case Types.OTHER:
|
166
|
-
default:
|
167
|
-
throw unsupportedOperationException(column);
|
168
|
-
}
|
169
|
-
}
|
170
|
-
|
171
|
-
protected Type getToType(JdbcColumnOption option)
|
172
|
-
{
|
173
|
-
if (!option.getType().isPresent()) {
|
174
|
-
return null;
|
175
|
-
}
|
176
|
-
Type toType = option.getType().get();
|
177
|
-
if (toType instanceof TimestampType && option.getTimestampFormat().isPresent()) {
|
178
|
-
toType = ((TimestampType)toType).withFormat(option.getTimestampFormat().get().getFormat());
|
179
|
-
}
|
180
|
-
return toType;
|
181
|
-
}
|
182
|
-
|
183
|
-
private static interface FormatterIntlTask extends Task, TimestampFormatter.Task {}
|
184
|
-
private static interface FormatterIntlColumnOption extends Task, TimestampFormatter.TimestampColumnOption {}
|
185
|
-
|
186
|
-
private TimestampFormatter newTimestampFormatter(JdbcColumnOption option, String defaultTimestampFormat)
|
187
|
-
{
|
188
|
-
// TODO: Switch to a newer TimestampFormatter constructor after a reasonable interval.
|
189
|
-
// Traditional constructor is used here for compatibility.
|
190
|
-
final ConfigSource configSource = Exec.newConfigSource();
|
191
|
-
configSource.set("format", option.getTimestampFormat().isPresent()
|
192
|
-
? option.getTimestampFormat().get().getFormat()
|
193
|
-
: defaultTimestampFormat);
|
194
|
-
configSource.set("timezone", option.getTimeZone().or(this.defaultTimeZone));
|
195
|
-
return new TimestampFormatter(
|
196
|
-
Exec.newConfigSource().loadConfig(FormatterIntlTask.class),
|
197
|
-
Optional.fromNullable(configSource.loadConfig(FormatterIntlColumnOption.class)));
|
198
|
-
}
|
199
|
-
|
200
|
-
private static UnsupportedOperationException unsupportedOperationException(JdbcColumn column)
|
201
|
-
{
|
202
|
-
throw new UnsupportedOperationException(
|
203
|
-
String.format(ENGLISH,
|
204
|
-
"Unsupported type %s (sqlType=%d) of '%s' column. Please add '%s: {value_type: string}' to 'column_options: {...}' option to convert the values to strings, or exclude the column from 'select:' option",
|
205
|
-
column.getTypeName(), column.getSqlType(), column.getName(), column.getName()));
|
206
|
-
}
|
207
|
-
}
|
@@ -1,37 +0,0 @@
|
|
1
|
-
package org.embulk.input.jdbc.getter;
|
2
|
-
|
3
|
-
import java.sql.Date;
|
4
|
-
import java.sql.ResultSet;
|
5
|
-
import java.sql.SQLException;
|
6
|
-
import org.embulk.spi.PageBuilder;
|
7
|
-
import org.embulk.spi.time.Timestamp;
|
8
|
-
import org.embulk.spi.time.TimestampFormatter;
|
9
|
-
import org.embulk.spi.type.Type;
|
10
|
-
import org.embulk.spi.type.Types;
|
11
|
-
|
12
|
-
public class DateColumnGetter
|
13
|
-
extends AbstractTimestampColumnGetter
|
14
|
-
{
|
15
|
-
static final String DEFAULT_FORMAT = "%Y-%m-%d";
|
16
|
-
|
17
|
-
public DateColumnGetter(PageBuilder to, Type toType, TimestampFormatter timestampFormatter)
|
18
|
-
{
|
19
|
-
super(to, toType, timestampFormatter);
|
20
|
-
}
|
21
|
-
|
22
|
-
@Override
|
23
|
-
protected void fetch(ResultSet from, int fromIndex) throws SQLException
|
24
|
-
{
|
25
|
-
Date date = from.getDate(fromIndex);
|
26
|
-
if (date != null) {
|
27
|
-
value = Timestamp.ofEpochMilli(date.getTime());
|
28
|
-
}
|
29
|
-
}
|
30
|
-
|
31
|
-
@Override
|
32
|
-
protected Type getDefaultToType()
|
33
|
-
{
|
34
|
-
return Types.TIMESTAMP.withFormat(DEFAULT_FORMAT);
|
35
|
-
}
|
36
|
-
|
37
|
-
}
|
@@ -1,66 +0,0 @@
|
|
1
|
-
package org.embulk.input.jdbc.getter;
|
2
|
-
|
3
|
-
import java.math.RoundingMode;
|
4
|
-
import java.sql.ResultSet;
|
5
|
-
import java.sql.SQLException;
|
6
|
-
import org.embulk.spi.Column;
|
7
|
-
import org.embulk.spi.PageBuilder;
|
8
|
-
import org.embulk.spi.type.Type;
|
9
|
-
import org.embulk.spi.type.Types;
|
10
|
-
import com.google.common.math.DoubleMath;
|
11
|
-
|
12
|
-
public class DoubleColumnGetter
|
13
|
-
extends AbstractColumnGetter
|
14
|
-
{
|
15
|
-
protected double value;
|
16
|
-
|
17
|
-
public DoubleColumnGetter(PageBuilder to, Type toType)
|
18
|
-
{
|
19
|
-
super(to, toType);
|
20
|
-
}
|
21
|
-
|
22
|
-
@Override
|
23
|
-
protected void fetch(ResultSet from, int fromIndex) throws SQLException
|
24
|
-
{
|
25
|
-
value = from.getDouble(fromIndex);
|
26
|
-
}
|
27
|
-
|
28
|
-
@Override
|
29
|
-
protected Type getDefaultToType()
|
30
|
-
{
|
31
|
-
return Types.DOUBLE;
|
32
|
-
}
|
33
|
-
|
34
|
-
@Override
|
35
|
-
public void booleanColumn(Column column)
|
36
|
-
{
|
37
|
-
to.setBoolean(column, value > 0.0);
|
38
|
-
}
|
39
|
-
|
40
|
-
@Override
|
41
|
-
public void longColumn(Column column)
|
42
|
-
{
|
43
|
-
long l;
|
44
|
-
try {
|
45
|
-
// TODO configurable rounding mode
|
46
|
-
l = DoubleMath.roundToLong(value, RoundingMode.HALF_UP);
|
47
|
-
} catch (ArithmeticException e) {
|
48
|
-
// NaN / Infinite / -Infinite
|
49
|
-
super.longColumn(column);
|
50
|
-
return;
|
51
|
-
}
|
52
|
-
to.setLong(column, l);
|
53
|
-
}
|
54
|
-
|
55
|
-
@Override
|
56
|
-
public void doubleColumn(Column column)
|
57
|
-
{
|
58
|
-
to.setDouble(column, value);
|
59
|
-
}
|
60
|
-
|
61
|
-
@Override
|
62
|
-
public void stringColumn(Column column)
|
63
|
-
{
|
64
|
-
to.setString(column, Double.toString(value));
|
65
|
-
}
|
66
|
-
}
|
@@ -1,66 +0,0 @@
|
|
1
|
-
package org.embulk.input.jdbc.getter;
|
2
|
-
|
3
|
-
import java.math.RoundingMode;
|
4
|
-
import java.sql.ResultSet;
|
5
|
-
import java.sql.SQLException;
|
6
|
-
import org.embulk.spi.Column;
|
7
|
-
import org.embulk.spi.PageBuilder;
|
8
|
-
import org.embulk.spi.type.Type;
|
9
|
-
import org.embulk.spi.type.Types;
|
10
|
-
import com.google.common.math.DoubleMath;
|
11
|
-
|
12
|
-
public class FloatColumnGetter
|
13
|
-
extends AbstractColumnGetter
|
14
|
-
{
|
15
|
-
protected float value;
|
16
|
-
|
17
|
-
public FloatColumnGetter(PageBuilder to, Type toType)
|
18
|
-
{
|
19
|
-
super(to, toType);
|
20
|
-
}
|
21
|
-
|
22
|
-
@Override
|
23
|
-
protected void fetch(ResultSet from, int fromIndex) throws SQLException
|
24
|
-
{
|
25
|
-
value = from.getFloat(fromIndex);
|
26
|
-
}
|
27
|
-
|
28
|
-
@Override
|
29
|
-
protected Type getDefaultToType()
|
30
|
-
{
|
31
|
-
return Types.DOUBLE;
|
32
|
-
}
|
33
|
-
|
34
|
-
@Override
|
35
|
-
public void booleanColumn(Column column)
|
36
|
-
{
|
37
|
-
to.setBoolean(column, value > 0.0);
|
38
|
-
}
|
39
|
-
|
40
|
-
@Override
|
41
|
-
public void longColumn(Column column)
|
42
|
-
{
|
43
|
-
long l;
|
44
|
-
try {
|
45
|
-
// TODO configurable rounding mode
|
46
|
-
l = DoubleMath.roundToLong(value, RoundingMode.HALF_UP);
|
47
|
-
} catch (ArithmeticException e) {
|
48
|
-
// NaN / Infinite / -Infinite
|
49
|
-
super.longColumn(column);
|
50
|
-
return;
|
51
|
-
}
|
52
|
-
to.setLong(column, l);
|
53
|
-
}
|
54
|
-
|
55
|
-
@Override
|
56
|
-
public void doubleColumn(Column column)
|
57
|
-
{
|
58
|
-
to.setDouble(column, value);
|
59
|
-
}
|
60
|
-
|
61
|
-
@Override
|
62
|
-
public void stringColumn(Column column)
|
63
|
-
{
|
64
|
-
to.setString(column, Float.toString(value));
|
65
|
-
}
|
66
|
-
}
|