embulk-input-datastore 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a08810cd4edfd6940aebe26cdb15a4471b5d77bb
4
+ data.tar.gz: 77e8fd4024f7c3e9b7bb8fe444857c9dd907f0de
5
+ SHA512:
6
+ metadata.gz: b0f57598b143161a2721343ced65cab1b54de29b3d9c30661dc3aaaa4ead810c47816f6da463af3cf43c569c046b61a5de22d6d9f152a32aa8f671325504499a
7
+ data.tar.gz: a4f63b161e32c4dbb54cd00572b0e3a034aef531bebd30c075e231f91f1c53699ac2bd090b9bd15746e186db2954671a6bbf03c2fc48220139fb92542a618297
@@ -0,0 +1,12 @@
1
+ *~
2
+ /pkg/
3
+ /tmp/
4
+ *.gemspec
5
+ .gradle/
6
+ /classpath/
7
+ build/
8
+ .idea
9
+ /.settings/
10
+ /.metadata/
11
+ .classpath
12
+ .project
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018 Ryo Okubo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,37 @@
1
+ # Datastore input plugin for Embulk
2
+
3
+ A embulk input plugin fetches Cloud Datastore entities.
4
+
5
+ ## Overview
6
+
7
+ * **Plugin type**: input
8
+ * **Resume supported**: no
9
+ * **Cleanup supported**: no
10
+ * **Guess supported**: no
11
+
12
+ ## Configuration
13
+
14
+ - **json_keyfile**: A path to JSON keyfile. (string, required)
15
+ - **gql**: A GQL fetches to Cloud Datastore (string, required)
16
+ - **json_column_name**: description (string, default: `"record"`)
17
+
18
+ ## Example
19
+
20
+ ```yaml
21
+ in:
22
+ type: datastore
23
+ json_keyfile: example1
24
+ gql: "SELECT * FROM myKind WHERE myProp >= 100 AND myProp < 200"
25
+ ```
26
+
27
+
28
+ ## Build
29
+
30
+ ```
31
+ $ ./gradlew gem # -t to watch change of files and rebuild continuously
32
+ ```
33
+
34
+ ## NOTE
35
+
36
+ Currently this plugin aggregates fetched entities to 1 'json' type column.
37
+
@@ -0,0 +1,30 @@
1
+ buildscript {
2
+ ext.kotlin_version = '1.2.31'
3
+ repositories {
4
+ jcenter()
5
+ maven { url 'http://kamatama41.github.com/maven-repository/repository' }
6
+ }
7
+ dependencies {
8
+ classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
9
+ classpath "com.github.kamatama41:gradle-embulk-plugin:0.2.0"
10
+ classpath "net.researchgate:gradle-release:2.6.0"
11
+ }
12
+ }
13
+
14
+ apply plugin: "com.github.kamatama41.embulk"
15
+
16
+ embulk {
17
+ version = "0.8.18"
18
+ category = "input"
19
+ name = "datastore"
20
+ authors = ["syucream"]
21
+ email = "syucream1031@gmail.com"
22
+ homepage = "https://github.com/syucream/embulk-input-datastore"
23
+ }
24
+
25
+ dependencies {
26
+ // To refer KClass::class.java
27
+ implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
28
+
29
+ implementation 'com.google.cloud:google-cloud-datastore:1.27.0'
30
+ }
@@ -0,0 +1,13 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module external.linked.project.id="embulk-input-datastore" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="" external.system.module.version="0.0.1" type="JAVA_MODULE" version="4">
3
+ <component name="NewModuleRootManager" inherit-compiler-output="true">
4
+ <exclude-output />
5
+ <content url="file://$MODULE_DIR$">
6
+ <excludeFolder url="file://$MODULE_DIR$/.gradle" />
7
+ <excludeFolder url="file://$MODULE_DIR$/build" />
8
+ <excludeFolder url="file://$MODULE_DIR$/out" />
9
+ </content>
10
+ <orderEntry type="inheritedJdk" />
11
+ <orderEntry type="sourceFolder" forTests="false" />
12
+ </component>
13
+ </module>
@@ -0,0 +1 @@
1
+ version=0.0.2
@@ -0,0 +1,3 @@
1
+ Embulk::JavaPlugin.register_input(
2
+ "datastore", "org.embulk.input.datastore.DatastoreInputPlugin",
3
+ File.expand_path('../../../../classpath', __FILE__))
@@ -0,0 +1,87 @@
1
+ package org.embulk.input.datastore
2
+
3
+ import com.google.auth.oauth2.GoogleCredentials
4
+ import com.google.cloud.datastore.*
5
+ import org.embulk.config.TaskReport
6
+ import org.embulk.config.ConfigDiff
7
+ import org.embulk.config.ConfigSource
8
+ import org.embulk.config.TaskSource
9
+ import org.embulk.spi.*
10
+ import org.embulk.spi.type.Types
11
+ import org.msgpack.value.ValueFactory
12
+ import java.io.FileInputStream
13
+ import java.io.IOException
14
+
15
+ class DatastoreInputPlugin : InputPlugin {
16
+ // number of run() method calls
17
+ val TASK_COUNT = 1
18
+
19
+ var datastore: Datastore? = null
20
+
21
+ override fun transaction(config: ConfigSource,
22
+ control: InputPlugin.Control): ConfigDiff {
23
+ val task: PluginTask = config.loadConfig(PluginTask::class.java)
24
+
25
+ // Support only 1 'json' type column
26
+ val schema = Schema.builder()
27
+ .add(task.jsonColumnName, Types.JSON)
28
+ .build()
29
+
30
+ // Setup datastore client
31
+ val cred = GoogleCredentials
32
+ .fromStream(FileInputStream(task.jsonKeyfile))
33
+ this.datastore = DatastoreOptions.newBuilder()
34
+ .setCredentials(cred)
35
+ .build()
36
+ .service
37
+
38
+ return resume(task.dump(), schema, TASK_COUNT, control)
39
+ }
40
+
41
+ override fun resume(taskSource: TaskSource,
42
+ schema: Schema, taskCount: Int,
43
+ control: InputPlugin.Control): ConfigDiff {
44
+ // XXX Unimplemented
45
+ control.run(taskSource, schema, taskCount)
46
+ return Exec.newConfigDiff()
47
+ }
48
+
49
+ override fun cleanup(taskSource: TaskSource,
50
+ schema: Schema, taskCount: Int,
51
+ successTaskReports: List<TaskReport>) {
52
+ }
53
+
54
+ override fun run(taskSource: TaskSource,
55
+ schema: Schema, taskIndex: Int,
56
+ output: PageOutput): TaskReport {
57
+ val task = taskSource.loadTask(PluginTask::class.java)
58
+ val allocator = task.getBufferAllocator()
59
+ val pageBuilder = PageBuilder(allocator, schema, output)
60
+
61
+ val query = Query
62
+ .newGqlQueryBuilder(Query.ResultType.ENTITY, task.gql)
63
+ .build()
64
+
65
+ datastore?.let {
66
+ val col = pageBuilder.schema.getColumn(0)
67
+
68
+ it.run(query)
69
+ .forEach { entity ->
70
+ val msgpackValue = ValueFactory.newString(entity.toString())
71
+ pageBuilder.setJson(col, msgpackValue)
72
+ pageBuilder.addRecord()
73
+ }
74
+
75
+ pageBuilder.finish()
76
+ } ?: run {
77
+ throw IOException("Datastore client is unavailable.")
78
+ }
79
+
80
+ return Exec.newTaskReport()
81
+ }
82
+
83
+ override fun guess(config: ConfigSource): ConfigDiff {
84
+ // XXX Unimplemented
85
+ return Exec.newConfigDiff()
86
+ }
87
+ }
@@ -0,0 +1,22 @@
1
+ package org.embulk.input.datastore
2
+
3
+ import org.embulk.config.Config
4
+ import org.embulk.config.ConfigDefault
5
+ import org.embulk.config.ConfigInject
6
+ import org.embulk.config.Task
7
+ import org.embulk.spi.BufferAllocator
8
+
9
+ interface PluginTask : Task {
10
+ @get:Config("json_keyfile")
11
+ val jsonKeyfile: String
12
+
13
+ @get:Config("gql")
14
+ val gql: String
15
+
16
+ @get:Config("json_column_name")
17
+ @get:ConfigDefault("\"record\"")
18
+ val jsonColumnName: String
19
+
20
+ @ConfigInject
21
+ fun getBufferAllocator(): BufferAllocator
22
+ }
@@ -0,0 +1,5 @@
1
+ package org.embulk.input.datastore;
2
+
3
+ public class TestDatastoreInputPlugin
4
+ {
5
+ }
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: embulk-input-datastore
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - syucream
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-06-19 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 datastore.
42
+ email:
43
+ - syucream1031@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - LICENSE
50
+ - README.md
51
+ - build.gradle
52
+ - embulk-input-datastore.iml
53
+ - gradle.properties
54
+ - lib/embulk/input/datastore.rb
55
+ - src/main/java/org/embulk/input/datastore/DatastoreInputPlugin.kt
56
+ - src/main/java/org/embulk/input/datastore/PluginTask.kt
57
+ - src/test/java/org/embulk/input/datastore/TestDatastoreInputPlugin.java
58
+ - classpath/embulk-input-datastore-0.0.2.jar
59
+ homepage: https://github.com/syucream/embulk-input-datastore
60
+ licenses:
61
+ - MIT
62
+ metadata: {}
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - '>='
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubyforge_project:
79
+ rubygems_version: 2.1.9
80
+ signing_key:
81
+ specification_version: 4
82
+ summary: Datastore input plugin for Embulk
83
+ test_files: []