embulk-output-td 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +7 -0
- data/README.md +63 -0
- data/build.gradle +79 -0
- data/embulk-output-td.gemspec +18 -0
- data/gradle/wrapper/gradle-wrapper.jar +0 -0
- data/gradle/wrapper/gradle-wrapper.properties +6 -0
- data/gradlew +164 -0
- data/gradlew.bat +90 -0
- data/lib/embulk/output/td.rb +3 -0
- data/settings.gradle +1 -0
- data/src/main/java/com/treasuredata/api/TdApiClient.java +436 -0
- data/src/main/java/com/treasuredata/api/TdApiClientConfig.java +79 -0
- data/src/main/java/com/treasuredata/api/TdApiConflictException.java +10 -0
- data/src/main/java/com/treasuredata/api/TdApiConstants.java +6 -0
- data/src/main/java/com/treasuredata/api/TdApiException.java +20 -0
- data/src/main/java/com/treasuredata/api/TdApiExecutionException.java +10 -0
- data/src/main/java/com/treasuredata/api/TdApiExecutionInterruptedException.java +15 -0
- data/src/main/java/com/treasuredata/api/TdApiExecutionTimeoutException.java +17 -0
- data/src/main/java/com/treasuredata/api/TdApiNotFoundException.java +10 -0
- data/src/main/java/com/treasuredata/api/TdApiResponseException.java +32 -0
- data/src/main/java/com/treasuredata/api/model/TDArrayColumnType.java +80 -0
- data/src/main/java/com/treasuredata/api/model/TDBulkImportSession.java +155 -0
- data/src/main/java/com/treasuredata/api/model/TDColumn.java +83 -0
- data/src/main/java/com/treasuredata/api/model/TDColumnType.java +23 -0
- data/src/main/java/com/treasuredata/api/model/TDColumnTypeDeserializer.java +115 -0
- data/src/main/java/com/treasuredata/api/model/TDDatabase.java +48 -0
- data/src/main/java/com/treasuredata/api/model/TDDatabaseList.java +24 -0
- data/src/main/java/com/treasuredata/api/model/TDMapColumnType.java +88 -0
- data/src/main/java/com/treasuredata/api/model/TDPrimitiveColumnType.java +61 -0
- data/src/main/java/com/treasuredata/api/model/TDTable.java +64 -0
- data/src/main/java/com/treasuredata/api/model/TDTableList.java +33 -0
- data/src/main/java/com/treasuredata/api/model/TDTablePermission.java +48 -0
- data/src/main/java/com/treasuredata/api/model/TDTableSchema.java +44 -0
- data/src/main/java/com/treasuredata/api/model/TDTableType.java +36 -0
- data/src/main/java/org/embulk/output/FinalizableExecutorService.java +84 -0
- data/src/main/java/org/embulk/output/MsgpackGZFileBuilder.java +148 -0
- data/src/main/java/org/embulk/output/RecordWriter.java +567 -0
- data/src/main/java/org/embulk/output/TdOutputPlugin.java +390 -0
- data/src/test/java/org/embulk/output/TestTdOutputPlugin.java +5 -0
- metadata +119 -0
@@ -0,0 +1,23 @@
|
|
1
|
+
package com.treasuredata.api.model;
|
2
|
+
|
3
|
+
import com.fasterxml.jackson.annotation.JsonValue;
|
4
|
+
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
5
|
+
|
6
|
+
@JsonDeserialize(using = TDColumnTypeDeserializer.class)
|
7
|
+
public interface TDColumnType
|
8
|
+
{
|
9
|
+
public boolean isPrimitive();
|
10
|
+
|
11
|
+
public boolean isArrayType();
|
12
|
+
|
13
|
+
public boolean isMapType();
|
14
|
+
|
15
|
+
public TDPrimitiveColumnType asPrimitiveType();
|
16
|
+
|
17
|
+
public TDArrayColumnType asArrayType();
|
18
|
+
|
19
|
+
public TDMapColumnType asMapType();
|
20
|
+
|
21
|
+
@JsonValue
|
22
|
+
public String toString();
|
23
|
+
}
|
@@ -0,0 +1,115 @@
|
|
1
|
+
package com.treasuredata.api.model;
|
2
|
+
|
3
|
+
import com.fasterxml.jackson.core.JsonParser;
|
4
|
+
import com.fasterxml.jackson.core.JsonProcessingException;
|
5
|
+
import com.fasterxml.jackson.core.JsonToken;
|
6
|
+
import com.fasterxml.jackson.databind.DeserializationContext;
|
7
|
+
import com.fasterxml.jackson.databind.JsonDeserializer;
|
8
|
+
import com.fasterxml.jackson.databind.RuntimeJsonMappingException;
|
9
|
+
|
10
|
+
import java.io.IOException;
|
11
|
+
|
12
|
+
public class TDColumnTypeDeserializer
|
13
|
+
extends JsonDeserializer<TDColumnType>
|
14
|
+
{
|
15
|
+
@Override
|
16
|
+
public TDColumnType deserialize(JsonParser jp, DeserializationContext ctxt)
|
17
|
+
throws IOException, JsonProcessingException
|
18
|
+
{
|
19
|
+
if (jp.nextToken() != JsonToken.VALUE_STRING) {
|
20
|
+
//throw new JsonMappingException("Unexpected JSON element to deserialize TDColumnType");
|
21
|
+
throw new RuntimeJsonMappingException("Unexpected JSON element to deserialize TDColumnType");
|
22
|
+
}
|
23
|
+
String str = jp.getText();
|
24
|
+
return parseColumnType(str);
|
25
|
+
}
|
26
|
+
|
27
|
+
public static TDColumnType parseColumnType(String str)
|
28
|
+
{
|
29
|
+
Parser p = new Parser(str);
|
30
|
+
TDColumnType type = parseColumnTypeRecursive(p);
|
31
|
+
if (!p.eof()) {
|
32
|
+
throw new IllegalArgumentException("Cannot parse type: EOF expected: " + str);
|
33
|
+
}
|
34
|
+
return type;
|
35
|
+
}
|
36
|
+
|
37
|
+
private static TDColumnType parseColumnTypeRecursive(Parser p)
|
38
|
+
{
|
39
|
+
if (p.scan("string")) {
|
40
|
+
return TDPrimitiveColumnType.STRING;
|
41
|
+
|
42
|
+
} else if (p.scan("int")) {
|
43
|
+
return TDPrimitiveColumnType.INT;
|
44
|
+
|
45
|
+
} else if (p.scan("long")) {
|
46
|
+
return TDPrimitiveColumnType.LONG;
|
47
|
+
|
48
|
+
} else if (p.scan("double")) {
|
49
|
+
return TDPrimitiveColumnType.DOUBLE;
|
50
|
+
|
51
|
+
} else if (p.scan("float")) {
|
52
|
+
return TDPrimitiveColumnType.FLOAT;
|
53
|
+
|
54
|
+
} else if (p.scan("array")) {
|
55
|
+
if (!p.scan("<")) {
|
56
|
+
throw new IllegalArgumentException("Cannot parse type: expected '<' for array type: " + p.getString());
|
57
|
+
}
|
58
|
+
TDColumnType elementType = parseColumnTypeRecursive(p);
|
59
|
+
if (!p.scan(">")) {
|
60
|
+
throw new IllegalArgumentException("Cannot parse type: expected '>' for array type: " + p.getString());
|
61
|
+
}
|
62
|
+
return new TDArrayColumnType(elementType);
|
63
|
+
|
64
|
+
} else if (p.scan("map")) {
|
65
|
+
if (!p.scan("<")) {
|
66
|
+
throw new IllegalArgumentException("Cannot parse type: expected '<' for map type: " + p.getString());
|
67
|
+
}
|
68
|
+
TDColumnType keyType = parseColumnTypeRecursive(p);
|
69
|
+
if (!p.scan(",")) {
|
70
|
+
throw new IllegalArgumentException("Cannot parse type: expected ',' for map type: " + p.getString());
|
71
|
+
}
|
72
|
+
TDColumnType valueType = parseColumnTypeRecursive(p);
|
73
|
+
if (!p.scan(">")) {
|
74
|
+
throw new IllegalArgumentException("Cannot parse type: expected '>' for map type: " + p.getString());
|
75
|
+
}
|
76
|
+
return new TDMapColumnType(keyType, valueType);
|
77
|
+
|
78
|
+
} else {
|
79
|
+
throw new IllegalArgumentException("Cannot parse type: " + p.getString());
|
80
|
+
}
|
81
|
+
}
|
82
|
+
|
83
|
+
private static class Parser {
|
84
|
+
private final String string;
|
85
|
+
private int offset;
|
86
|
+
|
87
|
+
public Parser(String string) {
|
88
|
+
this.string = string;
|
89
|
+
}
|
90
|
+
|
91
|
+
public String getString() {
|
92
|
+
return string;
|
93
|
+
}
|
94
|
+
|
95
|
+
public boolean scan(String s) {
|
96
|
+
skipSpaces();
|
97
|
+
if (string.startsWith(s, offset)) {
|
98
|
+
offset += s.length();
|
99
|
+
return true;
|
100
|
+
}
|
101
|
+
return false;
|
102
|
+
}
|
103
|
+
|
104
|
+
public boolean eof() {
|
105
|
+
skipSpaces();
|
106
|
+
return string.length() <= offset;
|
107
|
+
}
|
108
|
+
|
109
|
+
private void skipSpaces() {
|
110
|
+
while (string.startsWith(" ", offset)) {
|
111
|
+
offset++;
|
112
|
+
}
|
113
|
+
}
|
114
|
+
}
|
115
|
+
}
|
@@ -0,0 +1,48 @@
|
|
1
|
+
package com.treasuredata.api.model;
|
2
|
+
|
3
|
+
import com.fasterxml.jackson.annotation.JsonCreator;
|
4
|
+
import com.fasterxml.jackson.annotation.JsonProperty;
|
5
|
+
import com.google.common.base.Objects;
|
6
|
+
|
7
|
+
public class TDDatabase
|
8
|
+
{
|
9
|
+
private String name;
|
10
|
+
// "permission" field is also available but not necessary yet
|
11
|
+
|
12
|
+
@JsonCreator
|
13
|
+
public TDDatabase(
|
14
|
+
@JsonProperty("name") String name)
|
15
|
+
{
|
16
|
+
this.name = name;
|
17
|
+
}
|
18
|
+
|
19
|
+
@JsonProperty
|
20
|
+
public String getName()
|
21
|
+
{
|
22
|
+
return name;
|
23
|
+
}
|
24
|
+
|
25
|
+
public boolean isWritable() {
|
26
|
+
// TODO not implemented yet
|
27
|
+
return true;
|
28
|
+
}
|
29
|
+
|
30
|
+
@Override
|
31
|
+
public boolean equals(Object obj)
|
32
|
+
{
|
33
|
+
if (this == obj) {
|
34
|
+
return true;
|
35
|
+
}
|
36
|
+
if (obj == null || getClass() != obj.getClass()) {
|
37
|
+
return false;
|
38
|
+
}
|
39
|
+
TDDatabase other = (TDDatabase) obj;
|
40
|
+
return Objects.equal(this.name, other.name);
|
41
|
+
}
|
42
|
+
|
43
|
+
@Override
|
44
|
+
public int hashCode()
|
45
|
+
{
|
46
|
+
return Objects.hashCode(name);
|
47
|
+
}
|
48
|
+
}
|
@@ -0,0 +1,24 @@
|
|
1
|
+
package com.treasuredata.api.model;
|
2
|
+
|
3
|
+
import com.fasterxml.jackson.annotation.JsonCreator;
|
4
|
+
import com.fasterxml.jackson.annotation.JsonProperty;
|
5
|
+
|
6
|
+
import java.util.List;
|
7
|
+
|
8
|
+
public class TDDatabaseList
|
9
|
+
{
|
10
|
+
private List<TDDatabase> databases;
|
11
|
+
|
12
|
+
@JsonCreator
|
13
|
+
public TDDatabaseList(
|
14
|
+
@JsonProperty("databases") List<TDDatabase> databases)
|
15
|
+
{
|
16
|
+
this.databases = databases;
|
17
|
+
}
|
18
|
+
|
19
|
+
@JsonProperty
|
20
|
+
public List<TDDatabase> getDatabases()
|
21
|
+
{
|
22
|
+
return databases;
|
23
|
+
}
|
24
|
+
}
|
@@ -0,0 +1,88 @@
|
|
1
|
+
package com.treasuredata.api.model;
|
2
|
+
|
3
|
+
import com.google.common.base.Objects;
|
4
|
+
|
5
|
+
public class TDMapColumnType
|
6
|
+
implements TDColumnType
|
7
|
+
{
|
8
|
+
private TDColumnType keyType;
|
9
|
+
private TDColumnType valueType;
|
10
|
+
|
11
|
+
public TDMapColumnType(TDColumnType keyType, TDColumnType valueType)
|
12
|
+
{
|
13
|
+
this.keyType = keyType;
|
14
|
+
this.valueType = valueType;
|
15
|
+
}
|
16
|
+
|
17
|
+
public TDColumnType getKeyType()
|
18
|
+
{
|
19
|
+
return keyType;
|
20
|
+
}
|
21
|
+
|
22
|
+
public TDColumnType getValueType()
|
23
|
+
{
|
24
|
+
return valueType;
|
25
|
+
}
|
26
|
+
|
27
|
+
@Override
|
28
|
+
public String toString()
|
29
|
+
{
|
30
|
+
return "map<"+keyType+","+valueType+">";
|
31
|
+
}
|
32
|
+
|
33
|
+
@Override
|
34
|
+
public boolean isPrimitive()
|
35
|
+
{
|
36
|
+
return false;
|
37
|
+
}
|
38
|
+
|
39
|
+
@Override
|
40
|
+
public boolean isArrayType()
|
41
|
+
{
|
42
|
+
return false;
|
43
|
+
}
|
44
|
+
|
45
|
+
@Override
|
46
|
+
public boolean isMapType()
|
47
|
+
{
|
48
|
+
return true;
|
49
|
+
}
|
50
|
+
|
51
|
+
@Override
|
52
|
+
public TDPrimitiveColumnType asPrimitiveType()
|
53
|
+
{
|
54
|
+
return null;
|
55
|
+
}
|
56
|
+
|
57
|
+
@Override
|
58
|
+
public TDArrayColumnType asArrayType()
|
59
|
+
{
|
60
|
+
return null;
|
61
|
+
}
|
62
|
+
|
63
|
+
@Override
|
64
|
+
public TDMapColumnType asMapType()
|
65
|
+
{
|
66
|
+
return this;
|
67
|
+
}
|
68
|
+
|
69
|
+
@Override
|
70
|
+
public boolean equals(Object obj)
|
71
|
+
{
|
72
|
+
if (this == obj) {
|
73
|
+
return true;
|
74
|
+
}
|
75
|
+
if (obj == null || getClass() != obj.getClass()) {
|
76
|
+
return false;
|
77
|
+
}
|
78
|
+
TDMapColumnType other = (TDMapColumnType) obj;
|
79
|
+
return Objects.equal(this.keyType, other.keyType) &&
|
80
|
+
Objects.equal(this.valueType, other.valueType);
|
81
|
+
}
|
82
|
+
|
83
|
+
@Override
|
84
|
+
public int hashCode()
|
85
|
+
{
|
86
|
+
return Objects.hashCode(keyType, valueType);
|
87
|
+
}
|
88
|
+
}
|
@@ -0,0 +1,61 @@
|
|
1
|
+
package com.treasuredata.api.model;
|
2
|
+
|
3
|
+
public enum TDPrimitiveColumnType
|
4
|
+
implements TDColumnType
|
5
|
+
{
|
6
|
+
INT("int"),
|
7
|
+
LONG("long"),
|
8
|
+
FLOAT("float"),
|
9
|
+
DOUBLE("double"),
|
10
|
+
BOOLEAN("boolean"),
|
11
|
+
STRING("string");
|
12
|
+
|
13
|
+
private String name;
|
14
|
+
|
15
|
+
private TDPrimitiveColumnType(String name)
|
16
|
+
{
|
17
|
+
this.name = name;
|
18
|
+
}
|
19
|
+
|
20
|
+
@Override
|
21
|
+
public String toString()
|
22
|
+
{
|
23
|
+
return name;
|
24
|
+
}
|
25
|
+
|
26
|
+
@Override
|
27
|
+
public boolean isPrimitive()
|
28
|
+
{
|
29
|
+
return true;
|
30
|
+
}
|
31
|
+
|
32
|
+
@Override
|
33
|
+
public boolean isArrayType()
|
34
|
+
{
|
35
|
+
return false;
|
36
|
+
}
|
37
|
+
|
38
|
+
@Override
|
39
|
+
public boolean isMapType()
|
40
|
+
{
|
41
|
+
return false;
|
42
|
+
}
|
43
|
+
|
44
|
+
@Override
|
45
|
+
public TDPrimitiveColumnType asPrimitiveType()
|
46
|
+
{
|
47
|
+
return this;
|
48
|
+
}
|
49
|
+
|
50
|
+
@Override
|
51
|
+
public TDArrayColumnType asArrayType()
|
52
|
+
{
|
53
|
+
return null;
|
54
|
+
}
|
55
|
+
|
56
|
+
@Override
|
57
|
+
public TDMapColumnType asMapType()
|
58
|
+
{
|
59
|
+
return null;
|
60
|
+
}
|
61
|
+
}
|
@@ -0,0 +1,64 @@
|
|
1
|
+
package com.treasuredata.api.model;
|
2
|
+
|
3
|
+
import com.fasterxml.jackson.annotation.JsonCreator;
|
4
|
+
import com.fasterxml.jackson.annotation.JsonProperty;
|
5
|
+
import com.google.common.base.Objects;
|
6
|
+
|
7
|
+
import java.util.List;
|
8
|
+
|
9
|
+
public class TDTable
|
10
|
+
{
|
11
|
+
private String name;
|
12
|
+
private TDTableType type;
|
13
|
+
private List<TDColumn> columns;
|
14
|
+
|
15
|
+
@JsonCreator
|
16
|
+
public TDTable(
|
17
|
+
@JsonProperty("name") String name,
|
18
|
+
@JsonProperty("type") TDTableType type,
|
19
|
+
@JsonProperty("columns") List<TDColumn> columns)
|
20
|
+
{
|
21
|
+
this.name = name;
|
22
|
+
this.type = type;
|
23
|
+
this.columns = columns;
|
24
|
+
}
|
25
|
+
|
26
|
+
@JsonProperty
|
27
|
+
public String getName()
|
28
|
+
{
|
29
|
+
return name;
|
30
|
+
}
|
31
|
+
|
32
|
+
@JsonProperty
|
33
|
+
public TDTableType getType()
|
34
|
+
{
|
35
|
+
return type;
|
36
|
+
}
|
37
|
+
|
38
|
+
@JsonProperty
|
39
|
+
public List<TDColumn> getColumns()
|
40
|
+
{
|
41
|
+
return columns;
|
42
|
+
}
|
43
|
+
|
44
|
+
@Override
|
45
|
+
public boolean equals(Object obj)
|
46
|
+
{
|
47
|
+
if (this == obj) {
|
48
|
+
return true;
|
49
|
+
}
|
50
|
+
if (obj == null || getClass() != obj.getClass()) {
|
51
|
+
return false;
|
52
|
+
}
|
53
|
+
TDTable other = (TDTable) obj;
|
54
|
+
return Objects.equal(this.name, other.name) &&
|
55
|
+
Objects.equal(this.type, other.type) &&
|
56
|
+
Objects.equal(this.columns, other.columns);
|
57
|
+
}
|
58
|
+
|
59
|
+
@Override
|
60
|
+
public int hashCode()
|
61
|
+
{
|
62
|
+
return Objects.hashCode(name, type, columns);
|
63
|
+
}
|
64
|
+
}
|
@@ -0,0 +1,33 @@
|
|
1
|
+
package com.treasuredata.api.model;
|
2
|
+
|
3
|
+
import com.fasterxml.jackson.annotation.JsonCreator;
|
4
|
+
import com.fasterxml.jackson.annotation.JsonProperty;
|
5
|
+
|
6
|
+
import java.util.List;
|
7
|
+
|
8
|
+
public class TDTableList
|
9
|
+
{
|
10
|
+
private String name;
|
11
|
+
private List<TDTable> tables;
|
12
|
+
|
13
|
+
@JsonCreator
|
14
|
+
public TDTableList(
|
15
|
+
@JsonProperty("name") String name,
|
16
|
+
@JsonProperty("tables") List<TDTable> tables)
|
17
|
+
{
|
18
|
+
this.name = name;
|
19
|
+
this.tables = tables;
|
20
|
+
}
|
21
|
+
|
22
|
+
@JsonProperty
|
23
|
+
public String getName()
|
24
|
+
{
|
25
|
+
return name;
|
26
|
+
}
|
27
|
+
|
28
|
+
@JsonProperty
|
29
|
+
public List<TDTable> getTables()
|
30
|
+
{
|
31
|
+
return tables;
|
32
|
+
}
|
33
|
+
}
|