embulk-input-datastore 0.0.4 → 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 +4 -4
- data/build.gradle +25 -1
- data/gradle.properties +1 -1
- data/src/main/java/org/embulk/input/datastore/DatastoreInputPlugin.kt +8 -6
- data/src/test/java/org/embulk/input/datastore/DatastoreInputPluginSpec.kt +116 -0
- metadata +4 -4
- data/src/test/java/org/embulk/input/datastore/TestDatastoreInputPlugin.java +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7073922589f46f02c4b1e1534ccccec56bf56eb9d6316bde1f6f6d7f80b7d1b1
|
4
|
+
data.tar.gz: 6ced669ff8d160252dd8806f801b5e28b8ce7f0a51c65fc969c5a07412897a82
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 891dd771e4683e046c413308ca0c71efbe349ff29ebf9dfc8b7f65ce16442e7d8bd2f010a87c7cbe39d2de2882b63170fe6a0baabfcf8716184018db86152aa1
|
7
|
+
data.tar.gz: beacaf4852d72788a3d77494ee96badb04ff4548e97b3304475a64f62aec856fdbca669bdc0691e45194499ef7a010ddb6b3899c894b9ec79888abff5d5e5830
|
data/build.gradle
CHANGED
@@ -8,12 +8,26 @@ buildscript {
|
|
8
8
|
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
9
9
|
classpath "com.github.kamatama41:gradle-embulk-plugin:0.2.0"
|
10
10
|
classpath "net.researchgate:gradle-release:2.6.0"
|
11
|
+
classpath 'org.junit.platform:junit-platform-gradle-plugin:1.0.0'
|
11
12
|
}
|
12
13
|
}
|
13
14
|
|
14
15
|
apply plugin: "kotlin"
|
15
16
|
apply plugin: "com.github.kamatama41.embulk"
|
16
17
|
apply plugin: "net.researchgate.release"
|
18
|
+
apply plugin: 'org.junit.platform.gradle.plugin'
|
19
|
+
|
20
|
+
junitPlatform {
|
21
|
+
filters {
|
22
|
+
engines {
|
23
|
+
include 'spek'
|
24
|
+
}
|
25
|
+
}
|
26
|
+
}
|
27
|
+
|
28
|
+
repositories {
|
29
|
+
maven { url "http://dl.bintray.com/jetbrains/spek" }
|
30
|
+
}
|
17
31
|
|
18
32
|
embulk {
|
19
33
|
version = "0.8.18"
|
@@ -30,6 +44,16 @@ embulk {
|
|
30
44
|
dependencies {
|
31
45
|
// To refer KClass::class.java
|
32
46
|
compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
|
33
|
-
|
34
47
|
compile 'com.google.cloud:google-cloud-datastore:1.27.0'
|
48
|
+
|
49
|
+
testCompile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
|
50
|
+
testCompile group: 'org.jetbrains.kotlin', name: 'kotlin-test', version: '1.2.50'
|
51
|
+
testCompile group: 'org.jetbrains.kotlin', name: 'kotlin-test-annotations-common', version: '1.2.50'
|
52
|
+
testCompile ('org.jetbrains.spek:spek-api:1.1.5') {
|
53
|
+
exclude group: 'org.jetbrains.kotlin'
|
54
|
+
}
|
55
|
+
testRuntime ('org.jetbrains.spek:spek-junit-platform-engine:1.1.5') {
|
56
|
+
exclude group: 'org.junit.platform'
|
57
|
+
exclude group: 'org.jetbrains.kotlin'
|
58
|
+
}
|
35
59
|
}
|
data/gradle.properties
CHANGED
@@ -1 +1 @@
|
|
1
|
-
version=0.0
|
1
|
+
version=0.1.0
|
@@ -11,12 +11,14 @@ import org.embulk.spi.*
|
|
11
11
|
import org.embulk.spi.type.Types
|
12
12
|
import org.msgpack.value.ValueFactory
|
13
13
|
import java.io.FileInputStream
|
14
|
+
import java.util.Base64
|
14
15
|
|
15
|
-
class DatastoreInputPlugin : InputPlugin {
|
16
|
+
class DatastoreInputPlugin(doLogging: Boolean = true) : InputPlugin {
|
16
17
|
// number of run() method calls
|
17
18
|
private val TASK_COUNT = 1
|
18
19
|
|
19
|
-
private val logger = Exec.getLogger(javaClass)
|
20
|
+
private val logger = if (doLogging) { Exec.getLogger(javaClass) } else { null }
|
21
|
+
private val b64encoder = Base64.getEncoder()
|
20
22
|
|
21
23
|
override fun transaction(config: ConfigSource,
|
22
24
|
control: InputPlugin.Control): ConfigDiff {
|
@@ -59,10 +61,10 @@ class DatastoreInputPlugin : InputPlugin {
|
|
59
61
|
|
60
62
|
datastore.run(query)
|
61
63
|
.forEach { entity ->
|
62
|
-
logger
|
64
|
+
logger?.debug(entity.toString())
|
63
65
|
|
64
66
|
val json = entityToJsonObject(entity)
|
65
|
-
logger
|
67
|
+
logger?.debug(json)
|
66
68
|
|
67
69
|
pageBuilder.setJson(col, ValueFactory.newString(json))
|
68
70
|
pageBuilder.addRecord()
|
@@ -134,7 +136,7 @@ class DatastoreInputPlugin : InputPlugin {
|
|
134
136
|
*/
|
135
137
|
private fun valueToField(dsValue: Value<Any>): String? {
|
136
138
|
return when (dsValue.type) {
|
137
|
-
ValueType.BLOB -> (dsValue.get() as
|
139
|
+
ValueType.BLOB -> "\"${b64encoder.encodeToString((dsValue.get() as Blob).toByteArray())}\""
|
138
140
|
ValueType.BOOLEAN -> (dsValue.get() as Boolean).toString()
|
139
141
|
ValueType.DOUBLE -> (dsValue.get() as Double).toString()
|
140
142
|
ValueType.ENTITY -> entityToJsonObject(dsValue.get() as FullEntity<*>)
|
@@ -145,7 +147,7 @@ class DatastoreInputPlugin : InputPlugin {
|
|
145
147
|
ValueType.NULL -> "null"
|
146
148
|
ValueType.RAW_VALUE -> (dsValue.get() as RawValue).toString()
|
147
149
|
ValueType.STRING -> "\"${dsValue.get() as String}\""
|
148
|
-
ValueType.TIMESTAMP ->
|
150
|
+
ValueType.TIMESTAMP -> "\"${dsValue.get() as Timestamp}\""
|
149
151
|
else -> null // NOTE: unexpected or unsupported type
|
150
152
|
}
|
151
153
|
}
|
@@ -0,0 +1,116 @@
|
|
1
|
+
package org.embulk.input.datastore
|
2
|
+
|
3
|
+
import com.google.cloud.Timestamp
|
4
|
+
import com.google.cloud.datastore.*
|
5
|
+
import org.jetbrains.spek.api.Spek
|
6
|
+
import org.jetbrains.spek.api.dsl.describe
|
7
|
+
import org.jetbrains.spek.api.dsl.it
|
8
|
+
import org.jetbrains.spek.api.dsl.on
|
9
|
+
import kotlin.reflect.full.memberFunctions
|
10
|
+
import kotlin.reflect.jvm.isAccessible
|
11
|
+
import kotlin.test.assertEquals
|
12
|
+
import java.util.Base64
|
13
|
+
|
14
|
+
object DatastoreInputPluginSpec : Spek({
|
15
|
+
val b64Encoder = Base64.getEncoder()
|
16
|
+
|
17
|
+
describe("entityToJsonObject()") {
|
18
|
+
val plugin = DatastoreInputPlugin(false)
|
19
|
+
|
20
|
+
val method = plugin::class.memberFunctions.find { it.name == "entityToJsonObject" }
|
21
|
+
val accesibleMethod = method!!.let {
|
22
|
+
it.isAccessible = true
|
23
|
+
it
|
24
|
+
}
|
25
|
+
|
26
|
+
on("single property values") {
|
27
|
+
val testcases = listOf<Pair<FullEntity<IncompleteKey>, String>>(
|
28
|
+
Pair(
|
29
|
+
Entity.newBuilder().set("blobProp", Blob.copyFrom("test".toByteArray())).build(),
|
30
|
+
"{\"blobProp\":\"${b64Encoder.encodeToString("test".toByteArray())}\"}"
|
31
|
+
),
|
32
|
+
Pair(
|
33
|
+
Entity.newBuilder().set("boolProp", true).build(),
|
34
|
+
"{\"boolProp\":true}"
|
35
|
+
),
|
36
|
+
Pair(
|
37
|
+
Entity.newBuilder().set("doubleProp", 1.1).build(),
|
38
|
+
"{\"doubleProp\":1.1}"
|
39
|
+
),
|
40
|
+
Pair(
|
41
|
+
Entity.newBuilder().set("entityProp", FullEntity.newBuilder().set("name1", 1).build()).build(),
|
42
|
+
"{\"entityProp\":{\"name1\":1}}"
|
43
|
+
),
|
44
|
+
Pair(
|
45
|
+
Entity.newBuilder().set("listProp", 1, 2, 3).build(),
|
46
|
+
"{\"listProp\":[1, 2, 3]}"
|
47
|
+
),
|
48
|
+
Pair(
|
49
|
+
Entity.newBuilder().set("nullProp", NullValue.of()).build(),
|
50
|
+
"{\"nullProp\":null}"
|
51
|
+
),
|
52
|
+
Pair(
|
53
|
+
Entity.newBuilder().set("longProp", 1).build(),
|
54
|
+
"{\"longProp\":1}"
|
55
|
+
),
|
56
|
+
Pair(
|
57
|
+
Entity.newBuilder().set("stringProp", "test").build(),
|
58
|
+
"{\"stringProp\":\"test\"}"
|
59
|
+
),
|
60
|
+
Pair(
|
61
|
+
Entity.newBuilder().set("timestampProp", Timestamp.MIN_VALUE).build(),
|
62
|
+
"{\"timestampProp\":\"0001-01-01T00:00:00Z\"}"
|
63
|
+
)
|
64
|
+
)
|
65
|
+
|
66
|
+
it("should be converted json value") {
|
67
|
+
testcases.forEach { pair ->
|
68
|
+
val entity = pair.first
|
69
|
+
val expected = pair.second
|
70
|
+
|
71
|
+
val actual = accesibleMethod.call(plugin, entity) as String
|
72
|
+
assertEquals(expected, actual)
|
73
|
+
}
|
74
|
+
}
|
75
|
+
}
|
76
|
+
|
77
|
+
on("combinational property values") {
|
78
|
+
val testcases = listOf<Pair<FullEntity<IncompleteKey>, String>>(
|
79
|
+
Pair(
|
80
|
+
Entity.newBuilder()
|
81
|
+
.set("blobProp", Blob.copyFrom("test".toByteArray()))
|
82
|
+
.set("boolProp", true)
|
83
|
+
.set("doubleProp", 1.1)
|
84
|
+
.set("entityProp", FullEntity.newBuilder().set("name1", 1).build())
|
85
|
+
.set("listProp", 1, 2, 3)
|
86
|
+
.set("nullProp", NullValue.of())
|
87
|
+
.set("longProp", 1)
|
88
|
+
.set("stringProp", "test")
|
89
|
+
.set("timestampProp", Timestamp.MIN_VALUE)
|
90
|
+
.build(),
|
91
|
+
"{" +
|
92
|
+
"\"blobProp\":\"${b64Encoder.encodeToString("test".toByteArray())}\", " +
|
93
|
+
"\"boolProp\":true, " +
|
94
|
+
"\"doubleProp\":1.1, " +
|
95
|
+
"\"entityProp\":{\"name1\":1}, " +
|
96
|
+
"\"listProp\":[1, 2, 3], " +
|
97
|
+
"\"longProp\":1, " +
|
98
|
+
"\"nullProp\":null, " +
|
99
|
+
"\"stringProp\":\"test\", " +
|
100
|
+
"\"timestampProp\":\"0001-01-01T00:00:00Z\"" +
|
101
|
+
"}"
|
102
|
+
)
|
103
|
+
)
|
104
|
+
|
105
|
+
it("should be converted json value") {
|
106
|
+
testcases.forEach { pair ->
|
107
|
+
val entity = pair.first
|
108
|
+
val expected = pair.second
|
109
|
+
|
110
|
+
val actual = accesibleMethod.call(plugin, entity) as String
|
111
|
+
assertEquals(expected, actual)
|
112
|
+
}
|
113
|
+
}
|
114
|
+
}
|
115
|
+
}
|
116
|
+
})
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: embulk-input-datastore
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- syucream
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-06-
|
11
|
+
date: 2018-06-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -55,7 +55,7 @@ files:
|
|
55
55
|
- classpath/commons-codec-1.3.jar
|
56
56
|
- classpath/commons-logging-1.1.1.jar
|
57
57
|
- classpath/datastore-v1-proto-client-1.6.0.jar
|
58
|
-
- classpath/embulk-input-datastore-0.0.
|
58
|
+
- classpath/embulk-input-datastore-0.1.0.jar
|
59
59
|
- classpath/error_prone_annotations-2.2.0.jar
|
60
60
|
- classpath/gax-1.23.0.jar
|
61
61
|
- classpath/gax-httpjson-0.40.0.jar
|
@@ -95,7 +95,7 @@ files:
|
|
95
95
|
- lib/embulk/input/datastore.rb
|
96
96
|
- src/main/java/org/embulk/input/datastore/DatastoreInputPlugin.kt
|
97
97
|
- src/main/java/org/embulk/input/datastore/PluginTask.kt
|
98
|
-
- src/test/java/org/embulk/input/datastore/
|
98
|
+
- src/test/java/org/embulk/input/datastore/DatastoreInputPluginSpec.kt
|
99
99
|
homepage: https://github.com/syucream/embulk-input-datastore
|
100
100
|
licenses:
|
101
101
|
- MIT
|