embulk-input-clickhouse 0.1.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/.gitignore +12 -0
- data/LICENSE.txt +21 -0
- data/README.md +88 -0
- data/build.gradle +104 -0
- data/config/checkstyle/checkstyle.xml +128 -0
- data/config/checkstyle/default.xml +108 -0
- data/gradle/wrapper/gradle-wrapper.jar +0 -0
- data/gradle/wrapper/gradle-wrapper.properties +6 -0
- data/gradlew +172 -0
- data/gradlew.bat +84 -0
- data/lib/embulk/input/clickhouse.rb +3 -0
- data/src/main/java/org/embulk/input/clickhouse/ClickHouseColumnGetterFactory.java +40 -0
- data/src/main/java/org/embulk/input/clickhouse/ClickHouseInputConnection.java +15 -0
- data/src/main/java/org/embulk/input/clickhouse/ClickhouseInputPlugin.java +184 -0
- data/src/main/java/org/embulk/input/clickhouse/getter/ArrayColumnGetter.java +59 -0
- data/src/main/java/org/embulk/input/clickhouse/getter/BigIntegerColumnGetter.java +96 -0
- data/src/main/java/org/embulk/input/clickhouse/getter/Column2JsonUtil.java +30 -0
- data/src/main/java/org/embulk/input/clickhouse/getter/TupleColumnGetter.java +55 -0
- data/src/test/java/org/embulk/input/clickhouse/TestClickhouseInputPlugin.java +5 -0
- metadata +107 -0
@@ -0,0 +1,59 @@
|
|
1
|
+
package org.embulk.input.clickhouse.getter;
|
2
|
+
|
3
|
+
import org.embulk.input.jdbc.getter.AbstractColumnGetter;
|
4
|
+
import org.embulk.spi.Column;
|
5
|
+
import org.embulk.spi.PageBuilder;
|
6
|
+
import org.embulk.spi.json.JsonParseException;
|
7
|
+
import org.embulk.spi.type.Type;
|
8
|
+
|
9
|
+
import java.sql.Array;
|
10
|
+
import java.sql.ResultSet;
|
11
|
+
import java.sql.SQLException;
|
12
|
+
|
13
|
+
/**
|
14
|
+
* Supported JSON or String
|
15
|
+
*/
|
16
|
+
public class ArrayColumnGetter extends AbstractColumnGetter
|
17
|
+
{
|
18
|
+
protected Array value;
|
19
|
+
Column2JsonUtil c2j = new Column2JsonUtil();
|
20
|
+
|
21
|
+
public ArrayColumnGetter(PageBuilder to, Type toType)
|
22
|
+
{
|
23
|
+
super(to, toType);
|
24
|
+
}
|
25
|
+
|
26
|
+
@Override
|
27
|
+
protected void fetch(ResultSet from, int fromIndex) throws SQLException
|
28
|
+
{
|
29
|
+
value = from.getArray(fromIndex);
|
30
|
+
}
|
31
|
+
|
32
|
+
@Override
|
33
|
+
protected Type getDefaultToType()
|
34
|
+
{
|
35
|
+
return org.embulk.spi.type.Types.JSON;
|
36
|
+
}
|
37
|
+
|
38
|
+
@Override
|
39
|
+
public void jsonColumn(Column column)
|
40
|
+
{
|
41
|
+
try {
|
42
|
+
c2j.jsonColumn(column, to, value.getArray());
|
43
|
+
}
|
44
|
+
catch (JsonParseException | SQLException | ClassCastException e) {
|
45
|
+
super.jsonColumn(column);
|
46
|
+
}
|
47
|
+
}
|
48
|
+
|
49
|
+
@Override
|
50
|
+
public void stringColumn(Column column)
|
51
|
+
{
|
52
|
+
try {
|
53
|
+
c2j.stringColumn(column, to, value.getArray());
|
54
|
+
}
|
55
|
+
catch (SQLException e) {
|
56
|
+
to.setString(column, value.toString());
|
57
|
+
}
|
58
|
+
}
|
59
|
+
}
|
@@ -0,0 +1,96 @@
|
|
1
|
+
package org.embulk.input.clickhouse.getter;
|
2
|
+
|
3
|
+
import com.google.gson.Gson;
|
4
|
+
|
5
|
+
import org.embulk.input.jdbc.getter.AbstractColumnGetter;
|
6
|
+
import org.embulk.spi.Column;
|
7
|
+
import org.embulk.spi.PageBuilder;
|
8
|
+
import org.embulk.spi.json.JsonParseException;
|
9
|
+
import org.embulk.spi.json.JsonParser;
|
10
|
+
import org.embulk.spi.type.Type;
|
11
|
+
import org.embulk.spi.type.Types;
|
12
|
+
import org.msgpack.value.Value;
|
13
|
+
|
14
|
+
import java.math.BigInteger;
|
15
|
+
import java.sql.ResultSet;
|
16
|
+
import java.sql.SQLException;
|
17
|
+
|
18
|
+
import ru.yandex.clickhouse.response.ClickHouseResultSet;
|
19
|
+
|
20
|
+
public class BigIntegerColumnGetter extends AbstractColumnGetter
|
21
|
+
{
|
22
|
+
|
23
|
+
protected BigInteger value;
|
24
|
+
|
25
|
+
private final Gson gson = new Gson();
|
26
|
+
private final JsonParser jsonParser = new JsonParser();
|
27
|
+
|
28
|
+
private String originalColumnTypeName;
|
29
|
+
|
30
|
+
public BigIntegerColumnGetter(PageBuilder to, Type toType, String originalColumnTypeName)
|
31
|
+
{
|
32
|
+
super(to, toType);
|
33
|
+
this.originalColumnTypeName = originalColumnTypeName;
|
34
|
+
}
|
35
|
+
|
36
|
+
@Override
|
37
|
+
protected void fetch(ResultSet from, int fromIndex) throws SQLException
|
38
|
+
{
|
39
|
+
ClickHouseResultSet chFrom = (ClickHouseResultSet) from;
|
40
|
+
value = (BigInteger) chFrom.getObject(fromIndex);
|
41
|
+
}
|
42
|
+
|
43
|
+
@Override
|
44
|
+
protected Type getDefaultToType()
|
45
|
+
{
|
46
|
+
// In default, this ColumnGetter try to convert BigInteger value to Long value.
|
47
|
+
// If value is too big for Long type, please choose Type.String or Type.JSON
|
48
|
+
return Types.LONG;
|
49
|
+
}
|
50
|
+
|
51
|
+
@Override
|
52
|
+
public void longColumn(Column column)
|
53
|
+
{
|
54
|
+
try {
|
55
|
+
|
56
|
+
to.setLong(column, Long.parseLong(value.toString()));
|
57
|
+
|
58
|
+
}
|
59
|
+
catch (NumberFormatException e) {
|
60
|
+
throw new NumberFormatException(
|
61
|
+
String.format(
|
62
|
+
"%s In '%s %s' is too large for Long type. \n" +
|
63
|
+
"Please set other type (string or json) in your config file : \n" +
|
64
|
+
"\n" +
|
65
|
+
"in:\n" +
|
66
|
+
" type: clickhouse\n" +
|
67
|
+
" ...\n" +
|
68
|
+
" column_option:\n" +
|
69
|
+
" %s: {type: string}\n",
|
70
|
+
value.toString(),
|
71
|
+
column.getName(),
|
72
|
+
originalColumnTypeName,
|
73
|
+
column.getName()
|
74
|
+
));
|
75
|
+
}
|
76
|
+
}
|
77
|
+
|
78
|
+
@Override
|
79
|
+
public void stringColumn(Column column)
|
80
|
+
{
|
81
|
+
to.setString(column, value.toString());
|
82
|
+
}
|
83
|
+
|
84
|
+
@Override
|
85
|
+
public void jsonColumn(Column column)
|
86
|
+
{
|
87
|
+
try {
|
88
|
+
String jsonString = gson.toJson(value.toString());
|
89
|
+
Value v = jsonParser.parse(jsonString);
|
90
|
+
to.setJson(column, v);
|
91
|
+
}
|
92
|
+
catch (JsonParseException e) {
|
93
|
+
super.jsonColumn(column);
|
94
|
+
}
|
95
|
+
}
|
96
|
+
}
|
@@ -0,0 +1,30 @@
|
|
1
|
+
package org.embulk.input.clickhouse.getter;
|
2
|
+
|
3
|
+
import com.google.gson.Gson;
|
4
|
+
import com.google.gson.JsonParseException;
|
5
|
+
|
6
|
+
import org.embulk.spi.Column;
|
7
|
+
import org.embulk.spi.PageBuilder;
|
8
|
+
import org.embulk.spi.json.JsonParser;
|
9
|
+
import org.msgpack.value.Value;
|
10
|
+
|
11
|
+
import java.sql.SQLException;
|
12
|
+
|
13
|
+
public class Column2JsonUtil
|
14
|
+
{
|
15
|
+
private final Gson gson = new Gson();
|
16
|
+
private final JsonParser jsonParser = new JsonParser();
|
17
|
+
|
18
|
+
public void jsonColumn(Column column, PageBuilder to, Object value) throws JsonParseException, SQLException, ClassCastException
|
19
|
+
{
|
20
|
+
String jsonString = gson.toJson(value);
|
21
|
+
Value v = jsonParser.parse(jsonString);
|
22
|
+
to.setJson(column, v);
|
23
|
+
}
|
24
|
+
|
25
|
+
public void stringColumn(Column column, PageBuilder to, Object value)
|
26
|
+
{
|
27
|
+
String jsonString = gson.toJson(value);
|
28
|
+
to.setString(column, jsonString);
|
29
|
+
}
|
30
|
+
}
|
@@ -0,0 +1,55 @@
|
|
1
|
+
package org.embulk.input.clickhouse.getter;
|
2
|
+
|
3
|
+
import org.embulk.input.jdbc.getter.AbstractColumnGetter;
|
4
|
+
import org.embulk.spi.Column;
|
5
|
+
import org.embulk.spi.PageBuilder;
|
6
|
+
import org.embulk.spi.json.JsonParseException;
|
7
|
+
import org.embulk.spi.type.Type;
|
8
|
+
import org.embulk.spi.type.Types;
|
9
|
+
|
10
|
+
import java.sql.ResultSet;
|
11
|
+
import java.sql.SQLException;
|
12
|
+
|
13
|
+
/**
|
14
|
+
* Tuple is provided as String value.
|
15
|
+
*/
|
16
|
+
public class TupleColumnGetter extends AbstractColumnGetter
|
17
|
+
{
|
18
|
+
protected String value;
|
19
|
+
Column2JsonUtil c2j = new Column2JsonUtil();
|
20
|
+
|
21
|
+
public TupleColumnGetter(PageBuilder to, Type toType)
|
22
|
+
{
|
23
|
+
super(to, toType);
|
24
|
+
}
|
25
|
+
|
26
|
+
@Override
|
27
|
+
protected void fetch(ResultSet from, int fromIndex) throws SQLException
|
28
|
+
{
|
29
|
+
value = from.getString(fromIndex);
|
30
|
+
}
|
31
|
+
|
32
|
+
@Override
|
33
|
+
protected Type getDefaultToType()
|
34
|
+
{
|
35
|
+
return Types.STRING;
|
36
|
+
}
|
37
|
+
|
38
|
+
@Override
|
39
|
+
public void jsonColumn(Column column)
|
40
|
+
{
|
41
|
+
//FIXME: convert to flat array as JSON
|
42
|
+
try {
|
43
|
+
c2j.jsonColumn(column, to, value);
|
44
|
+
}
|
45
|
+
catch (JsonParseException | SQLException | ClassCastException e) {
|
46
|
+
super.jsonColumn(column);
|
47
|
+
}
|
48
|
+
}
|
49
|
+
|
50
|
+
@Override
|
51
|
+
public void stringColumn(Column column)
|
52
|
+
{
|
53
|
+
to.setString(column, value);
|
54
|
+
}
|
55
|
+
}
|
metadata
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: embulk-input-clickhouse
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- TAC
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-10-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
15
|
+
requirements:
|
16
|
+
- - "~>"
|
17
|
+
- !ruby/object:Gem::Version
|
18
|
+
version: '1.0'
|
19
|
+
name: bundler
|
20
|
+
prerelease: false
|
21
|
+
type: :development
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '10.0'
|
33
|
+
name: rake
|
34
|
+
prerelease: false
|
35
|
+
type: :development
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description: Loads records from Clickhouse.
|
42
|
+
email:
|
43
|
+
- tac@tac42.net
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- LICENSE.txt
|
50
|
+
- README.md
|
51
|
+
- build.gradle
|
52
|
+
- classpath/clickhouse-jdbc-0.1.41.jar
|
53
|
+
- classpath/commons-codec-1.9.jar
|
54
|
+
- classpath/commons-logging-1.2.jar
|
55
|
+
- classpath/embulk-input-clickhouse-0.1.0.jar
|
56
|
+
- classpath/embulk-input-jdbc-0.9.3.jar
|
57
|
+
- classpath/gson-2.8.5.jar
|
58
|
+
- classpath/guava-19.0.jar
|
59
|
+
- classpath/httpclient-4.5.2.jar
|
60
|
+
- classpath/httpcore-4.4.4.jar
|
61
|
+
- classpath/httpmime-4.5.2.jar
|
62
|
+
- classpath/jackson-annotations-2.7.0.jar
|
63
|
+
- classpath/jackson-core-2.7.3.jar
|
64
|
+
- classpath/jackson-databind-2.7.3.jar
|
65
|
+
- classpath/joda-time-2.9.9.jar
|
66
|
+
- classpath/lz4-1.3.0.jar
|
67
|
+
- classpath/slf4j-api-1.7.21.jar
|
68
|
+
- config/checkstyle/checkstyle.xml
|
69
|
+
- config/checkstyle/default.xml
|
70
|
+
- gradle/wrapper/gradle-wrapper.jar
|
71
|
+
- gradle/wrapper/gradle-wrapper.properties
|
72
|
+
- gradlew
|
73
|
+
- gradlew.bat
|
74
|
+
- lib/embulk/input/clickhouse.rb
|
75
|
+
- src/main/java/org/embulk/input/clickhouse/ClickHouseColumnGetterFactory.java
|
76
|
+
- src/main/java/org/embulk/input/clickhouse/ClickHouseInputConnection.java
|
77
|
+
- src/main/java/org/embulk/input/clickhouse/ClickhouseInputPlugin.java
|
78
|
+
- src/main/java/org/embulk/input/clickhouse/getter/ArrayColumnGetter.java
|
79
|
+
- src/main/java/org/embulk/input/clickhouse/getter/BigIntegerColumnGetter.java
|
80
|
+
- src/main/java/org/embulk/input/clickhouse/getter/Column2JsonUtil.java
|
81
|
+
- src/main/java/org/embulk/input/clickhouse/getter/TupleColumnGetter.java
|
82
|
+
- src/test/java/org/embulk/input/clickhouse/TestClickhouseInputPlugin.java
|
83
|
+
homepage: https://github.com/tac0x2a/embulk-input-clickhouse
|
84
|
+
licenses:
|
85
|
+
- MIT
|
86
|
+
metadata: {}
|
87
|
+
post_install_message:
|
88
|
+
rdoc_options: []
|
89
|
+
require_paths:
|
90
|
+
- lib
|
91
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
requirements: []
|
102
|
+
rubyforge_project:
|
103
|
+
rubygems_version: 2.6.8
|
104
|
+
signing_key:
|
105
|
+
specification_version: 4
|
106
|
+
summary: ClickHouse input plugin for Embulk
|
107
|
+
test_files: []
|