embulk-output-cassandra 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +13 -0
  3. data/LICENSE.txt +21 -0
  4. data/README.md +45 -0
  5. data/build.gradle +97 -0
  6. data/config/checkstyle/checkstyle.xml +128 -0
  7. data/config/checkstyle/default.xml +108 -0
  8. data/embulk-output-cassandra.iml +13 -0
  9. data/gradle/wrapper/gradle-wrapper.jar +0 -0
  10. data/gradle/wrapper/gradle-wrapper.properties +5 -0
  11. data/gradlew +172 -0
  12. data/gradlew.bat +84 -0
  13. data/lib/embulk/output/cassandra.rb +3 -0
  14. data/src/main/java/org/embulk/output/cassandra/CassandraOutputPlugin.java +283 -0
  15. data/src/main/java/org/embulk/output/cassandra/setter/BigintColumnSetter.java +41 -0
  16. data/src/main/java/org/embulk/output/cassandra/setter/BooleanColumnSetter.java +30 -0
  17. data/src/main/java/org/embulk/output/cassandra/setter/CassandraColumnSetter.java +51 -0
  18. data/src/main/java/org/embulk/output/cassandra/setter/CassandraColumnSetterFactory.java +60 -0
  19. data/src/main/java/org/embulk/output/cassandra/setter/ColumnSetterVisitor.java +96 -0
  20. data/src/main/java/org/embulk/output/cassandra/setter/DateColumnSetter.java +29 -0
  21. data/src/main/java/org/embulk/output/cassandra/setter/DecimalColumnSetter.java +43 -0
  22. data/src/main/java/org/embulk/output/cassandra/setter/DoubleColumnSetter.java +41 -0
  23. data/src/main/java/org/embulk/output/cassandra/setter/FloatColumnSetter.java +41 -0
  24. data/src/main/java/org/embulk/output/cassandra/setter/InetColumnSetter.java +26 -0
  25. data/src/main/java/org/embulk/output/cassandra/setter/IntColumnSetter.java +41 -0
  26. data/src/main/java/org/embulk/output/cassandra/setter/ListColumnSetter.java +22 -0
  27. data/src/main/java/org/embulk/output/cassandra/setter/MapColumnSetter.java +22 -0
  28. data/src/main/java/org/embulk/output/cassandra/setter/SetColumnSetter.java +24 -0
  29. data/src/main/java/org/embulk/output/cassandra/setter/SmallintColumnSetter.java +41 -0
  30. data/src/main/java/org/embulk/output/cassandra/setter/TextColumnSetter.java +50 -0
  31. data/src/main/java/org/embulk/output/cassandra/setter/TimeColumnSetter.java +46 -0
  32. data/src/main/java/org/embulk/output/cassandra/setter/TimestampColumnSetter.java +42 -0
  33. data/src/main/java/org/embulk/output/cassandra/setter/TimeuuidColumnSetter.java +18 -0
  34. data/src/main/java/org/embulk/output/cassandra/setter/TinyintColumnSetter.java +41 -0
  35. data/src/main/java/org/embulk/output/cassandra/setter/TupleColumnSetter.java +34 -0
  36. data/src/main/java/org/embulk/output/cassandra/setter/UuidColumnSetter.java +18 -0
  37. data/src/main/java/org/embulk/output/cassandra/setter/ValueConverter.java +63 -0
  38. data/src/main/java/org/embulk/output/cassandra/setter/VarintColumnSetter.java +43 -0
  39. data/src/test/java/org/embulk/output/cassandra/TestCassandraOutputPlugin.java +250 -0
  40. data/src/test/resources/org/embulk/output/cassandra/create_keyspace.cql +5 -0
  41. data/src/test/resources/org/embulk/output/cassandra/create_table_test_basic.cql +11 -0
  42. data/src/test/resources/org/embulk/output/cassandra/create_table_test_complex.cql +12 -0
  43. data/src/test/resources/org/embulk/output/cassandra/create_table_test_uuid.cql +8 -0
  44. data/src/test/resources/org/embulk/output/cassandra/test1.csv +4 -0
  45. data/src/test/resources/org/embulk/output/cassandra/test2.csv +2 -0
  46. data/src/test/resources/org/embulk/output/cassandra/test3.csv +2 -0
  47. data/src/test/resources/org/embulk/output/cassandra/test_basic.yaml +3 -0
  48. data/src/test/resources/org/embulk/output/cassandra/test_complex.yaml +3 -0
  49. data/src/test/resources/org/embulk/output/cassandra/test_uuid.yaml +3 -0
  50. metadata +141 -0
@@ -0,0 +1,41 @@
1
+ package org.embulk.output.cassandra.setter;
2
+
3
+ import com.datastax.driver.core.BoundStatement;
4
+ import com.datastax.driver.core.ColumnMetadata;
5
+
6
+ public class BigintColumnSetter extends CassandraColumnSetter
7
+ {
8
+ public BigintColumnSetter(ColumnMetadata cassandraColumn)
9
+ {
10
+ super(cassandraColumn);
11
+ }
12
+
13
+ @Override
14
+ public void setBooleanValue(Boolean value, BoundStatement statement)
15
+ {
16
+ if (value) {
17
+ statement.setLong(cassandraColumn.getName(), 1);
18
+ }
19
+ else {
20
+ statement.setLong(cassandraColumn.getName(), 0);
21
+ }
22
+ }
23
+
24
+ @Override
25
+ public void setLongValue(Long value, BoundStatement statement)
26
+ {
27
+ statement.setLong(cassandraColumn.getName(), value);
28
+ }
29
+
30
+ @Override
31
+ public void setDoubleValue(Double value, BoundStatement statement)
32
+ {
33
+ statement.setLong(cassandraColumn.getName(), value.longValue());
34
+ }
35
+
36
+ @Override
37
+ public void setStringValue(String value, BoundStatement statement)
38
+ {
39
+ statement.setLong(cassandraColumn.getName(), Long.parseLong(value));
40
+ }
41
+ }
@@ -0,0 +1,30 @@
1
+ package org.embulk.output.cassandra.setter;
2
+
3
+ import com.datastax.driver.core.BoundStatement;
4
+ import com.datastax.driver.core.ColumnMetadata;
5
+
6
+ public class BooleanColumnSetter extends CassandraColumnSetter
7
+ {
8
+ public BooleanColumnSetter(ColumnMetadata cassandraColumn)
9
+ {
10
+ super(cassandraColumn);
11
+ }
12
+
13
+ @Override
14
+ public void setBooleanValue(Boolean value, BoundStatement statement)
15
+ {
16
+ statement.setBool(cassandraColumn.getName(), value);
17
+ }
18
+
19
+ @Override
20
+ public void setLongValue(Long value, BoundStatement statement)
21
+ {
22
+ statement.setBool(cassandraColumn.getName(), value != 0);
23
+ }
24
+
25
+ @Override
26
+ public void setDoubleValue(Double value, BoundStatement statement)
27
+ {
28
+ statement.setBool(cassandraColumn.getName(), value != 0);
29
+ }
30
+ }
@@ -0,0 +1,51 @@
1
+ package org.embulk.output.cassandra.setter;
2
+
3
+ import com.datastax.driver.core.BoundStatement;
4
+ import com.datastax.driver.core.ColumnMetadata;
5
+ import org.embulk.spi.time.Timestamp;
6
+ import org.msgpack.value.Value;
7
+
8
+ public abstract class CassandraColumnSetter
9
+ {
10
+ protected ColumnMetadata cassandraColumn;
11
+
12
+ public CassandraColumnSetter(ColumnMetadata cassandraColumn)
13
+ {
14
+ this.cassandraColumn = cassandraColumn;
15
+ }
16
+
17
+ public void setBooleanValue(Boolean value, BoundStatement statement)
18
+ {
19
+ throw new RuntimeException("Unsupported type conversion: " + value.getClass().getName() + " -> " + cassandraColumn.getType().getName());
20
+ };
21
+
22
+ public void setLongValue(Long value, BoundStatement statement)
23
+ {
24
+ throw new RuntimeException("Unsupported type conversion: " + value.getClass().getName() + " -> " + cassandraColumn.getType().getName());
25
+ };
26
+
27
+ public void setDoubleValue(Double value, BoundStatement statement)
28
+ {
29
+ throw new RuntimeException("Unsupported type conversion: " + value.getClass().getName() + " -> " + cassandraColumn.getType().getName());
30
+ };
31
+
32
+ public void setStringValue(String value, BoundStatement statement)
33
+ {
34
+ throw new RuntimeException("Unsupported type conversion: " + value.getClass().getName() + " -> " + cassandraColumn.getType().getName());
35
+ };
36
+
37
+ public void setTimestampValue(Timestamp value, BoundStatement statement)
38
+ {
39
+ throw new RuntimeException("Unsupported type conversion: " + value.getClass().getName() + " -> " + cassandraColumn.getType().getName());
40
+ };
41
+
42
+ public void setJsonValue(Value value, BoundStatement statement)
43
+ {
44
+ throw new RuntimeException("Unsupported type conversion: " + value.getClass().getName() + " -> " + cassandraColumn.getType().getName());
45
+ };
46
+
47
+ public void setNullValue(BoundStatement statement)
48
+ {
49
+ statement.setToNull(cassandraColumn.getName());
50
+ }
51
+ }
@@ -0,0 +1,60 @@
1
+ package org.embulk.output.cassandra.setter;
2
+
3
+ import com.datastax.driver.core.Cluster;
4
+ import com.datastax.driver.core.ColumnMetadata;
5
+
6
+ public class CassandraColumnSetterFactory
7
+ {
8
+ private CassandraColumnSetterFactory()
9
+ {
10
+ }
11
+
12
+ public static CassandraColumnSetter createColumnSetter(ColumnMetadata cassandraColumn, Cluster cluster)
13
+ {
14
+ switch (cassandraColumn.getType().getName()) {
15
+ case TEXT:
16
+ case VARCHAR:
17
+ case ASCII:
18
+ return new TextColumnSetter(cassandraColumn);
19
+ case BOOLEAN:
20
+ return new BooleanColumnSetter(cassandraColumn);
21
+ case BIGINT:
22
+ return new BigintColumnSetter(cassandraColumn);
23
+ case INT:
24
+ return new IntColumnSetter(cassandraColumn);
25
+ case SMALLINT:
26
+ return new SmallintColumnSetter(cassandraColumn);
27
+ case TINYINT:
28
+ return new TinyintColumnSetter(cassandraColumn);
29
+ case VARINT:
30
+ return new VarintColumnSetter(cassandraColumn);
31
+ case DECIMAL:
32
+ return new DecimalColumnSetter(cassandraColumn);
33
+ case DOUBLE:
34
+ return new DoubleColumnSetter(cassandraColumn);
35
+ case FLOAT:
36
+ return new FloatColumnSetter(cassandraColumn);
37
+ case TIMESTAMP:
38
+ return new TimestampColumnSetter(cassandraColumn);
39
+ case DATE:
40
+ return new DateColumnSetter(cassandraColumn);
41
+ case TIME:
42
+ return new TimeColumnSetter(cassandraColumn);
43
+ case UUID:
44
+ return new UuidColumnSetter(cassandraColumn);
45
+ case TIMEUUID:
46
+ return new TimeuuidColumnSetter(cassandraColumn);
47
+ case LIST:
48
+ return new ListColumnSetter(cassandraColumn);
49
+ case MAP:
50
+ return new MapColumnSetter(cassandraColumn);
51
+ case SET:
52
+ return new SetColumnSetter(cassandraColumn);
53
+ case INET:
54
+ return new InetColumnSetter(cassandraColumn);
55
+ case TUPLE:
56
+ return new TupleColumnSetter(cassandraColumn, cluster);
57
+ }
58
+ throw new RuntimeException(cassandraColumn.getName() + ":" + cassandraColumn.getType().getName() + " is unsupported Type");
59
+ }
60
+ }
@@ -0,0 +1,96 @@
1
+ package org.embulk.output.cassandra.setter;
2
+
3
+ import com.datastax.driver.core.BoundStatement;
4
+ import org.embulk.spi.Column;
5
+ import org.embulk.spi.ColumnVisitor;
6
+ import org.embulk.spi.PageReader;
7
+
8
+ public class ColumnSetterVisitor implements ColumnVisitor
9
+ {
10
+ private final PageReader pageReader;
11
+ private final CassandraColumnSetter setter;
12
+
13
+ private BoundStatement statement;
14
+
15
+ public ColumnSetterVisitor(PageReader pageReader, CassandraColumnSetter setter)
16
+ {
17
+ this.pageReader = pageReader;
18
+ this.setter = setter;
19
+ }
20
+
21
+ public boolean hasSetter()
22
+ {
23
+ return this.setter != null;
24
+ }
25
+
26
+ public void setStatement(BoundStatement statement)
27
+ {
28
+ this.statement = statement;
29
+ }
30
+
31
+ @Override
32
+ public void booleanColumn(Column column)
33
+ {
34
+ if (pageReader.isNull(column)) {
35
+ setter.setNullValue(statement);
36
+ }
37
+ else {
38
+ setter.setBooleanValue(pageReader.getBoolean(column), statement);
39
+ }
40
+ }
41
+
42
+ @Override
43
+ public void longColumn(Column column)
44
+ {
45
+ if (pageReader.isNull(column)) {
46
+ setter.setNullValue(statement);
47
+ }
48
+ else {
49
+ setter.setLongValue(pageReader.getLong(column), statement);
50
+ }
51
+ }
52
+
53
+ @Override
54
+ public void doubleColumn(Column column)
55
+ {
56
+ if (pageReader.isNull(column)) {
57
+ setter.setNullValue(statement);
58
+ }
59
+ else {
60
+ setter.setDoubleValue(pageReader.getDouble(column), statement);
61
+ }
62
+ }
63
+
64
+ @Override
65
+ public void stringColumn(Column column)
66
+ {
67
+ if (pageReader.isNull(column)) {
68
+ setter.setNullValue(statement);
69
+ }
70
+ else {
71
+ setter.setStringValue(pageReader.getString(column), statement);
72
+ }
73
+ }
74
+
75
+ @Override
76
+ public void timestampColumn(Column column)
77
+ {
78
+ if (pageReader.isNull(column)) {
79
+ setter.setNullValue(statement);
80
+ }
81
+ else {
82
+ setter.setTimestampValue(pageReader.getTimestamp(column), statement);
83
+ }
84
+ }
85
+
86
+ @Override
87
+ public void jsonColumn(Column column)
88
+ {
89
+ if (pageReader.isNull(column)) {
90
+ setter.setNullValue(statement);
91
+ }
92
+ else {
93
+ setter.setJsonValue(pageReader.getJson(column), statement);
94
+ }
95
+ }
96
+ }
@@ -0,0 +1,29 @@
1
+ package org.embulk.output.cassandra.setter;
2
+
3
+ import com.datastax.driver.core.BoundStatement;
4
+ import com.datastax.driver.core.ColumnMetadata;
5
+ import org.embulk.spi.time.Timestamp;
6
+
7
+ import java.time.LocalDate;
8
+
9
+ public class DateColumnSetter extends CassandraColumnSetter
10
+ {
11
+ public DateColumnSetter(ColumnMetadata cassandraColumn)
12
+ {
13
+ super(cassandraColumn);
14
+ }
15
+
16
+ @Override
17
+ public void setStringValue(String value, BoundStatement statement)
18
+ {
19
+ LocalDate date = LocalDate.parse(value);
20
+ statement.setDate(cassandraColumn.getName(), com.datastax.driver.core.LocalDate.fromYearMonthDay(date.getYear(), date.getMonthValue(), date.getDayOfMonth()));
21
+ }
22
+
23
+ @Override
24
+ public void setTimestampValue(Timestamp value, BoundStatement statement)
25
+ {
26
+ com.datastax.driver.core.LocalDate date = com.datastax.driver.core.LocalDate.fromMillisSinceEpoch(value.toEpochMilli());
27
+ statement.setDate(cassandraColumn.getName(), date);
28
+ }
29
+ }
@@ -0,0 +1,43 @@
1
+ package org.embulk.output.cassandra.setter;
2
+
3
+ import com.datastax.driver.core.BoundStatement;
4
+ import com.datastax.driver.core.ColumnMetadata;
5
+
6
+ import java.math.BigDecimal;
7
+
8
+ public class DecimalColumnSetter extends CassandraColumnSetter
9
+ {
10
+ public DecimalColumnSetter(ColumnMetadata cassandraColumn)
11
+ {
12
+ super(cassandraColumn);
13
+ }
14
+
15
+ @Override
16
+ public void setBooleanValue(Boolean value, BoundStatement statement)
17
+ {
18
+ if (value) {
19
+ statement.setDecimal(cassandraColumn.getName(), BigDecimal.valueOf(1));
20
+ }
21
+ else {
22
+ statement.setDecimal(cassandraColumn.getName(), BigDecimal.valueOf(0));
23
+ }
24
+ }
25
+
26
+ @Override
27
+ public void setLongValue(Long value, BoundStatement statement)
28
+ {
29
+ statement.setDecimal(cassandraColumn.getName(), BigDecimal.valueOf(value));
30
+ }
31
+
32
+ @Override
33
+ public void setDoubleValue(Double value, BoundStatement statement)
34
+ {
35
+ statement.setDecimal(cassandraColumn.getName(), BigDecimal.valueOf(value));
36
+ }
37
+
38
+ @Override
39
+ public void setStringValue(String value, BoundStatement statement)
40
+ {
41
+ statement.setDecimal(cassandraColumn.getName(), new BigDecimal(value));
42
+ }
43
+ }
@@ -0,0 +1,41 @@
1
+ package org.embulk.output.cassandra.setter;
2
+
3
+ import com.datastax.driver.core.BoundStatement;
4
+ import com.datastax.driver.core.ColumnMetadata;
5
+
6
+ public class DoubleColumnSetter extends CassandraColumnSetter
7
+ {
8
+ public DoubleColumnSetter(ColumnMetadata cassandraColumn)
9
+ {
10
+ super(cassandraColumn);
11
+ }
12
+
13
+ @Override
14
+ public void setBooleanValue(Boolean value, BoundStatement statement)
15
+ {
16
+ if (value) {
17
+ statement.setDouble(cassandraColumn.getName(), 1);
18
+ }
19
+ else {
20
+ statement.setDouble(cassandraColumn.getName(), 0);
21
+ }
22
+ }
23
+
24
+ @Override
25
+ public void setLongValue(Long value, BoundStatement statement)
26
+ {
27
+ statement.setDouble(cassandraColumn.getName(), value.doubleValue());
28
+ }
29
+
30
+ @Override
31
+ public void setDoubleValue(Double value, BoundStatement statement)
32
+ {
33
+ statement.setDouble(cassandraColumn.getName(), value);
34
+ }
35
+
36
+ @Override
37
+ public void setStringValue(String value, BoundStatement statement)
38
+ {
39
+ statement.setDouble(cassandraColumn.getName(), Double.parseDouble(value));
40
+ }
41
+ }
@@ -0,0 +1,41 @@
1
+ package org.embulk.output.cassandra.setter;
2
+
3
+ import com.datastax.driver.core.BoundStatement;
4
+ import com.datastax.driver.core.ColumnMetadata;
5
+
6
+ public class FloatColumnSetter extends CassandraColumnSetter
7
+ {
8
+ public FloatColumnSetter(ColumnMetadata cassandraColumn)
9
+ {
10
+ super(cassandraColumn);
11
+ }
12
+
13
+ @Override
14
+ public void setBooleanValue(Boolean value, BoundStatement statement)
15
+ {
16
+ if (value) {
17
+ statement.setFloat(cassandraColumn.getName(), 1);
18
+ }
19
+ else {
20
+ statement.setFloat(cassandraColumn.getName(), 0);
21
+ }
22
+ }
23
+
24
+ @Override
25
+ public void setLongValue(Long value, BoundStatement statement)
26
+ {
27
+ statement.setFloat(cassandraColumn.getName(), value.floatValue());
28
+ }
29
+
30
+ @Override
31
+ public void setDoubleValue(Double value, BoundStatement statement)
32
+ {
33
+ statement.setFloat(cassandraColumn.getName(), value.floatValue());
34
+ }
35
+
36
+ @Override
37
+ public void setStringValue(String value, BoundStatement statement)
38
+ {
39
+ statement.setFloat(cassandraColumn.getName(), Float.parseFloat(value));
40
+ }
41
+ }
@@ -0,0 +1,26 @@
1
+ package org.embulk.output.cassandra.setter;
2
+
3
+ import com.datastax.driver.core.BoundStatement;
4
+ import com.datastax.driver.core.ColumnMetadata;
5
+
6
+ import java.net.InetAddress;
7
+ import java.net.UnknownHostException;
8
+
9
+ public class InetColumnSetter extends CassandraColumnSetter
10
+ {
11
+ public InetColumnSetter(ColumnMetadata cassandraColumn)
12
+ {
13
+ super(cassandraColumn);
14
+ }
15
+
16
+ @Override
17
+ public void setStringValue(String value, BoundStatement statement)
18
+ {
19
+ try {
20
+ statement.setInet(cassandraColumn.getName(), InetAddress.getByName(value));
21
+ }
22
+ catch (UnknownHostException e) {
23
+ throw new RuntimeException(e);
24
+ }
25
+ }
26
+ }