embulk-input-rethinkdb 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 21aa87211af2414daa21a3b274500095fa379f7a
4
- data.tar.gz: 2bca810caf3003b88f593bce79a458cbc000e045
3
+ metadata.gz: 0ca030b9fc584a0ae98be06b989981197951dace
4
+ data.tar.gz: 123d35f231b3ea02d62123f6b69a0840f4fb8e3f
5
5
  SHA512:
6
- metadata.gz: 616d24bc4184ccaa8461a5cf593f6d14f3dda00c6bcdba0c69afeb8af80d4354e67abc977cc358c7b29d11dc39977aa173ae0493310b4729eb9810a9b1a8a083
7
- data.tar.gz: 9fe40b9bed815b8b02dc095c8bf42a2f6e83db03a8933b5fc047126d80639e8c3832a3eb07fb1e74309d833685e1b980ac627c8ab4ce8d4fa35610521d146fcd
6
+ metadata.gz: 1c4845e091d29f00838c5add36ad2a31d94cc192f0b8de37a4e91a5c522954860f196f90ff04e5e8f60ea94187f48c1ff9187a82df4cb0035fcca3135874e13c
7
+ data.tar.gz: b7cdd6c44a36dcfbca1347ff2523b2914c375869e6876eb2e41245dd5c77f537c2fc2c390812ef6b5cc2b1cd33e6ee75f20648f598d4de6d137bc3563292704b
data/README.md CHANGED
@@ -19,7 +19,10 @@ RethinkDB input plugin for Embulk loads records from RethinkDB.
19
19
  - **user**: database login user name (string, required)
20
20
  - **password**: database login password (string, required)
21
21
  - **cert_file**: path to TLS CA certificate file (string)
22
- - **query**: ReQL to run (string, required)
22
+ - Select whether to write a query or specify only the table
23
+ - **query**: ReQL to run (string)
24
+ <br>or<br>
25
+ - **table**: table from which load data from (string)
23
26
  - **column_name**: column name used in outputs (string, default: `"record"`)
24
27
 
25
28
  ## ReQL for query option
@@ -13,7 +13,7 @@ configurations {
13
13
  provided
14
14
  }
15
15
 
16
- version = "0.1.1"
16
+ version = "0.1.2"
17
17
 
18
18
  sourceCompatibility = 1.8
19
19
  targetCompatibility = 1.8
@@ -80,10 +80,17 @@ public class RethinkdbInputPlugin
80
80
  @ConfigDefault("null")
81
81
  Optional<String> getQuery();
82
82
 
83
+ @Config("table")
84
+ @ConfigDefault("null")
85
+ Optional<String> getTable();
86
+
83
87
  @Config("column_name")
84
88
  @ConfigDefault("\"record\"")
85
89
  String getColumnName();
86
90
 
91
+ String getReql();
92
+ void setReql(String ast);
93
+
87
94
  @ConfigInject
88
95
  BufferAllocator getBufferAllocator();
89
96
  }
@@ -102,9 +109,21 @@ public class RethinkdbInputPlugin
102
109
  if (!(task.getUser().isPresent() && task.getPassword().isPresent())) {
103
110
  throw new ConfigException("user and password are needed");
104
111
  }
105
- if (!task.getQuery().isPresent()) {
106
- throw new ConfigException("query is needed");
112
+
113
+ String reql;
114
+ if (task.getQuery().isPresent()) {
115
+ if (task.getTable().isPresent()) {
116
+ throw new ConfigException("only one of 'table' or 'query' parameter is needed");
117
+ }
118
+ reql = String.format("var ast = %s; var res = {ast: ast}; res;", task.getQuery().get());
107
119
  }
120
+ else {
121
+ if (!task.getTable().isPresent()) {
122
+ throw new ConfigException("'table' or 'query' parameter is needed");
123
+ }
124
+ reql = String.format("var ast = r.table('%s'); var res = {ast: ast}; res;", task.getTable().get());
125
+ }
126
+ task.setReql(reql);
108
127
 
109
128
  Schema schema = Schema.builder().add(task.getColumnName(), Types.JSON).build();
110
129
  int taskCount = 1;
@@ -141,12 +160,11 @@ public class RethinkdbInputPlugin
141
160
  RethinkDB r = RethinkDB.r;
142
161
  ReqlAst ast;
143
162
  try {
144
- ast = compileReQL(r, task.getQuery().get());
163
+ ast = compileReQL(r, task.getReql());
145
164
  }
146
165
  catch (final ScriptException se) {
147
166
  throw new ConfigException("ReQL compile error");
148
167
  }
149
-
150
168
  Connection.Builder builder = r.connection()
151
169
  .hostname(task.getHost())
152
170
  .port(task.getPort())
@@ -185,14 +203,13 @@ public class RethinkdbInputPlugin
185
203
  return Exec.newConfigDiff();
186
204
  }
187
205
 
188
- private ReqlAst compileReQL(RethinkDB r, String query) throws ScriptException
206
+ private ReqlAst compileReQL(RethinkDB r, String reql) throws ScriptException
189
207
  {
190
208
  ScriptEngineManager factory = new ScriptEngineManager();
191
209
  ScriptEngine engine = factory.getEngineByName("nashorn");
192
210
 
193
211
  engine.put("r", r);
194
212
 
195
- String reql = String.format("var ast = %s; var res = {ast: ast}; res;", query);
196
213
  Bindings bindings = (Bindings) engine.eval(reql);
197
214
 
198
215
  return (ReqlAst) bindings.get("ast");
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: embulk-input-rethinkdb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Koji Matsumoto
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-18 00:00:00.000000000 Z
11
+ date: 2020-06-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -49,7 +49,7 @@ files:
49
49
  - LICENSE.txt
50
50
  - README.md
51
51
  - build.gradle
52
- - classpath/embulk-input-rethinkdb-0.1.1.jar
52
+ - classpath/embulk-input-rethinkdb-0.1.2.jar
53
53
  - classpath/hamcrest-core-1.1.jar
54
54
  - classpath/json-simple-1.1.1.jar
55
55
  - classpath/junit-4.10.jar