embulk-output-dynamodb 0.1.3 → 0.1.4

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: 65c351383c9859353bc121a5f054b63de4876773
4
- data.tar.gz: e171f2369c6582ef90c8fb7d4a6acc0a0300061b
3
+ metadata.gz: 7db44cb5c01ab73108a51ce0d10c01f8de59a275
4
+ data.tar.gz: d700b39b97d766bb766275fec915fa3070742a47
5
5
  SHA512:
6
- metadata.gz: 862214066e48cb94be626d68b9a014dcdccf1a4a74f1808e4ff87b43beef2115f55b0d5547aa8d3460404bf85856ab9ed64488190bf1dbdde71ce7f44c07dd47
7
- data.tar.gz: 8466fe13984980117b6a7bba30efbafca953ad8011758fcfd4b6a0eb6589efc45389051ed2de2e7c2eeb11342a5abf2e5be9b9c82a188d28f28652c5b7b5e5c6
6
+ metadata.gz: cb9075e5f44fcd4c2de7ddc4082f0c77c132ce8064e6b7929c85ae0b28da442e343a7ba4359f83da88eb9996c839eca6d3a66e09209d8f906abf49ba31114d3b
7
+ data.tar.gz: c40cb955974f0241a5b78774ded216fb3267e20ecb8cfdfd25bd7e80a8c0cc322ff524f4ff39908b8aa518f80d5f845a520b974b34877e0b8515a7f62be723c4
@@ -1 +1 @@
1
- ## 0.1.3 - 2016-07-11
1
+ ## 0.1.4 - 2017-06-21
@@ -14,7 +14,7 @@ configurations {
14
14
  provided
15
15
  }
16
16
 
17
- version = "0.1.3"
17
+ version = "0.1.4"
18
18
 
19
19
  sourceCompatibility = 1.7
20
20
  targetCompatibility = 1.7
@@ -1,90 +1,90 @@
1
- @if "%DEBUG%" == "" @echo off
2
- @rem ##########################################################################
3
- @rem
4
- @rem Gradle startup script for Windows
5
- @rem
6
- @rem ##########################################################################
7
-
8
- @rem Set local scope for the variables with windows NT shell
9
- if "%OS%"=="Windows_NT" setlocal
10
-
11
- @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12
- set DEFAULT_JVM_OPTS=
13
-
14
- set DIRNAME=%~dp0
15
- if "%DIRNAME%" == "" set DIRNAME=.
16
- set APP_BASE_NAME=%~n0
17
- set APP_HOME=%DIRNAME%
18
-
19
- @rem Find java.exe
20
- if defined JAVA_HOME goto findJavaFromJavaHome
21
-
22
- set JAVA_EXE=java.exe
23
- %JAVA_EXE% -version >NUL 2>&1
24
- if "%ERRORLEVEL%" == "0" goto init
25
-
26
- echo.
27
- echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28
- echo.
29
- echo Please set the JAVA_HOME variable in your environment to match the
30
- echo location of your Java installation.
31
-
32
- goto fail
33
-
34
- :findJavaFromJavaHome
35
- set JAVA_HOME=%JAVA_HOME:"=%
36
- set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37
-
38
- if exist "%JAVA_EXE%" goto init
39
-
40
- echo.
41
- echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42
- echo.
43
- echo Please set the JAVA_HOME variable in your environment to match the
44
- echo location of your Java installation.
45
-
46
- goto fail
47
-
48
- :init
49
- @rem Get command-line arguments, handling Windowz variants
50
-
51
- if not "%OS%" == "Windows_NT" goto win9xME_args
52
- if "%@eval[2+2]" == "4" goto 4NT_args
53
-
54
- :win9xME_args
55
- @rem Slurp the command line arguments.
56
- set CMD_LINE_ARGS=
57
- set _SKIP=2
58
-
59
- :win9xME_args_slurp
60
- if "x%~1" == "x" goto execute
61
-
62
- set CMD_LINE_ARGS=%*
63
- goto execute
64
-
65
- :4NT_args
66
- @rem Get arguments from the 4NT Shell from JP Software
67
- set CMD_LINE_ARGS=%$
68
-
69
- :execute
70
- @rem Setup the command line
71
-
72
- set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73
-
74
- @rem Execute Gradle
75
- "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76
-
77
- :end
78
- @rem End local scope for the variables with windows NT shell
79
- if "%ERRORLEVEL%"=="0" goto mainEnd
80
-
81
- :fail
82
- rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83
- rem the _cmd.exe /c_ return code!
84
- if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85
- exit /b 1
86
-
87
- :mainEnd
88
- if "%OS%"=="Windows_NT" endlocal
89
-
90
- :omega
1
+ @if "%DEBUG%" == "" @echo off
2
+ @rem ##########################################################################
3
+ @rem
4
+ @rem Gradle startup script for Windows
5
+ @rem
6
+ @rem ##########################################################################
7
+
8
+ @rem Set local scope for the variables with windows NT shell
9
+ if "%OS%"=="Windows_NT" setlocal
10
+
11
+ @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12
+ set DEFAULT_JVM_OPTS=
13
+
14
+ set DIRNAME=%~dp0
15
+ if "%DIRNAME%" == "" set DIRNAME=.
16
+ set APP_BASE_NAME=%~n0
17
+ set APP_HOME=%DIRNAME%
18
+
19
+ @rem Find java.exe
20
+ if defined JAVA_HOME goto findJavaFromJavaHome
21
+
22
+ set JAVA_EXE=java.exe
23
+ %JAVA_EXE% -version >NUL 2>&1
24
+ if "%ERRORLEVEL%" == "0" goto init
25
+
26
+ echo.
27
+ echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28
+ echo.
29
+ echo Please set the JAVA_HOME variable in your environment to match the
30
+ echo location of your Java installation.
31
+
32
+ goto fail
33
+
34
+ :findJavaFromJavaHome
35
+ set JAVA_HOME=%JAVA_HOME:"=%
36
+ set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37
+
38
+ if exist "%JAVA_EXE%" goto init
39
+
40
+ echo.
41
+ echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42
+ echo.
43
+ echo Please set the JAVA_HOME variable in your environment to match the
44
+ echo location of your Java installation.
45
+
46
+ goto fail
47
+
48
+ :init
49
+ @rem Get command-line arguments, handling Windowz variants
50
+
51
+ if not "%OS%" == "Windows_NT" goto win9xME_args
52
+ if "%@eval[2+2]" == "4" goto 4NT_args
53
+
54
+ :win9xME_args
55
+ @rem Slurp the command line arguments.
56
+ set CMD_LINE_ARGS=
57
+ set _SKIP=2
58
+
59
+ :win9xME_args_slurp
60
+ if "x%~1" == "x" goto execute
61
+
62
+ set CMD_LINE_ARGS=%*
63
+ goto execute
64
+
65
+ :4NT_args
66
+ @rem Get arguments from the 4NT Shell from JP Software
67
+ set CMD_LINE_ARGS=%$
68
+
69
+ :execute
70
+ @rem Setup the command line
71
+
72
+ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73
+
74
+ @rem Execute Gradle
75
+ "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76
+
77
+ :end
78
+ @rem End local scope for the variables with windows NT shell
79
+ if "%ERRORLEVEL%"=="0" goto mainEnd
80
+
81
+ :fail
82
+ rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83
+ rem the _cmd.exe /c_ return code!
84
+ if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85
+ exit /b 1
86
+
87
+ :mainEnd
88
+ if "%OS%"=="Windows_NT" endlocal
89
+
90
+ :omega
@@ -199,7 +199,7 @@ public class DynamodbOutputPlugin
199
199
  private final String table;
200
200
  private final Mode mode;
201
201
  private final Optional<String> updateExpression;
202
- private final String primaryKey;
202
+ private final List primaryKeyElements;
203
203
  private final int maxPutItems;
204
204
 
205
205
  public DynamodbPageOutput(PluginTask task, DynamoDB dynamoDB)
@@ -210,7 +210,7 @@ public class DynamodbOutputPlugin
210
210
  this.table = task.getTable();
211
211
  this.mode = task.getMode();
212
212
  this.updateExpression = task.getUpdateExpression();
213
- this.primaryKey = (mode.equals(Mode.UPSERT_WITH_EXPRESSION)) ? dynamodbUtils.getPrimaryKeyName(dynamoDB, table) : null;
213
+ this.primaryKeyElements = (mode.equals(Mode.UPSERT_WITH_EXPRESSION)) ? dynamodbUtils.getPrimaryKey(dynamoDB, table) : null;
214
214
  this.maxPutItems = task.getMaxPutItems();
215
215
  }
216
216
 
@@ -400,7 +400,7 @@ public class DynamodbOutputPlugin
400
400
  public void updateItem(Item item)
401
401
  {
402
402
  try {
403
- dynamodbUtils.updateItem(dynamoDB, table, item, primaryKey, updateExpression);
403
+ dynamodbUtils.updateItem(dynamoDB, table, item, primaryKeyElements, updateExpression);
404
404
  totalWroteItemSize++;
405
405
  if (totalWroteItemSize % 1000 == 0) {
406
406
  log.info(String.format("Updated %s items", totalWroteItemSize));
@@ -143,17 +143,34 @@ public class DynamodbUtils
143
143
  }
144
144
  }
145
145
 
146
- protected void updateItem(DynamoDB dynamoDB, String tableName, Item item, String primaryKey, Optional<String> expression)
146
+ protected void updateItem(DynamoDB dynamoDB, String tableName, Item item, List primaryKeyelements, Optional<String> expression)
147
147
  {
148
- Object primaryKeyValue = null;
148
+ String hashKeyname = null;
149
+ String rangeKeyname = null;
150
+ Object hashKeyValue = null;
151
+ Object rangeKeyValue = null;
149
152
  Map<String, String> attributeNames = new HashMap<>();
150
153
  Map<String, Object> attributeValues = new HashMap<>();
151
154
 
155
+ Iterator it = primaryKeyelements.iterator();
156
+ while (it.hasNext()) {
157
+ KeySchemaElement element = (KeySchemaElement) it.next();
158
+ if (element.getKeyType().equals(KeyType.HASH.toString())) {
159
+ hashKeyname = element.getAttributeName();
160
+ }
161
+ else if (element.getKeyType().equals(KeyType.RANGE.toString())) {
162
+ rangeKeyname = element.getAttributeName();
163
+ }
164
+ }
165
+
152
166
  Map<String, Object> itemMap = item.asMap();
153
167
  for (Map.Entry<String, Object> e : itemMap.entrySet()) {
154
168
  String keyName = e.getKey();
155
- if (keyName.equals(primaryKey)) {
156
- primaryKeyValue = e.getValue();
169
+ if (keyName.equals(hashKeyname)) {
170
+ hashKeyValue = e.getValue();
171
+ }
172
+ else if (keyName.equals(rangeKeyname)) {
173
+ rangeKeyValue = e.getValue();
157
174
  }
158
175
  else {
159
176
  if (expression.get().indexOf(keyName) > 0) {
@@ -164,9 +181,17 @@ public class DynamodbUtils
164
181
  }
165
182
  log.debug("attribute names: " + attributeNames.toString());
166
183
  log.debug("attribute values: " + attributeValues.toString());
167
- log.debug(String.format("primary key %s:%s", primaryKey, primaryKeyValue));
184
+
168
185
  Table table = dynamoDB.getTable(tableName);
169
- table.updateItem(primaryKey, primaryKeyValue, expression.get(), attributeNames, attributeValues);
186
+
187
+ log.debug(String.format("hash key %s:%s", hashKeyname, hashKeyValue));
188
+ if (rangeKeyValue == null) {
189
+ table.updateItem(hashKeyname, hashKeyValue, expression.get(), attributeNames, attributeValues);
190
+ }
191
+ else {
192
+ log.debug(String.format("range key %s:%s", rangeKeyname, rangeKeyValue));
193
+ table.updateItem(hashKeyname, hashKeyValue, rangeKeyname, rangeKeyValue, expression.get(), attributeNames, attributeValues);
194
+ }
170
195
  }
171
196
 
172
197
  protected String getPrimaryKeyName(DynamoDB dynamoDB, String tableName)
@@ -178,11 +203,21 @@ public class DynamodbUtils
178
203
  String primaryKey = null;
179
204
  while (schema.hasNext()) {
180
205
  KeySchemaElement element = schema.next();
181
- primaryKey = element.getAttributeName();
206
+ if (element.getKeyType().equals(KeyType.HASH.toString())) {
207
+ primaryKey = element.getAttributeName();
208
+ }
182
209
  }
183
210
  return primaryKey;
184
211
  }
185
212
 
213
+ protected List getPrimaryKey(DynamoDB dynamoDB, String tableName)
214
+ {
215
+ Table table = dynamoDB.getTable(tableName);
216
+ TableDescription description = table.describe();
217
+ List<KeySchemaElement> keyelements = description.getKeySchema();
218
+ return keyelements;
219
+ }
220
+
186
221
  protected void createTable(DynamoDB dynamoDB, DynamodbOutputPlugin.PluginTask task)
187
222
  throws InterruptedException
188
223
  {
metadata CHANGED
@@ -1,43 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: embulk-output-dynamodb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Satoshi Akama
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-11 00:00:00.000000000 Z
11
+ date: 2017-06-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- requirement: !ruby/object:Gem::Requirement
14
+ name: bundler
15
+ version_requirements: !ruby/object:Gem::Requirement
15
16
  requirements:
16
17
  - - ~>
17
18
  - !ruby/object:Gem::Version
18
19
  version: '1.0'
19
- name: bundler
20
- prerelease: false
21
- type: :development
22
- version_requirements: !ruby/object:Gem::Requirement
20
+ requirement: !ruby/object:Gem::Requirement
23
21
  requirements:
24
22
  - - ~>
25
23
  - !ruby/object:Gem::Version
26
24
  version: '1.0'
25
+ prerelease: false
26
+ type: :development
27
27
  - !ruby/object:Gem::Dependency
28
- requirement: !ruby/object:Gem::Requirement
28
+ name: rake
29
+ version_requirements: !ruby/object:Gem::Requirement
29
30
  requirements:
30
31
  - - '>='
31
32
  - !ruby/object:Gem::Version
32
33
  version: '10.0'
33
- name: rake
34
- prerelease: false
35
- type: :development
36
- version_requirements: !ruby/object:Gem::Requirement
34
+ requirement: !ruby/object:Gem::Requirement
37
35
  requirements:
38
36
  - - '>='
39
37
  - !ruby/object:Gem::Version
40
38
  version: '10.0'
39
+ prerelease: false
40
+ type: :development
41
41
  description: Dumps records to AWS DynamoDB.
42
42
  email:
43
43
  - satoshiakama@gmail.com
@@ -71,7 +71,7 @@ files:
71
71
  - classpath/aws-java-sdk-s3-1.10.50.jar
72
72
  - classpath/commons-codec-1.6.jar
73
73
  - classpath/commons-logging-1.1.3.jar
74
- - classpath/embulk-output-dynamodb-0.1.3.jar
74
+ - classpath/embulk-output-dynamodb-0.1.4.jar
75
75
  - classpath/httpclient-4.3.6.jar
76
76
  - classpath/httpcore-4.3.3.jar
77
77
  homepage: https://github.com/sakama/embulk-output-dynamodb