embulk-output-gcs 0.4.0 → 0.4.1

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: c5f66c9aebb242064e49a624cb08443142d7440b
4
- data.tar.gz: bb3ef12c25a3bb768e2453012e351073566bf5b1
3
+ metadata.gz: b41fdc69131fe0099ff844875bafa6d160510e10
4
+ data.tar.gz: 5b084d56f12509c0c273ea295519a1534d310579
5
5
  SHA512:
6
- metadata.gz: 337c8a5c9cbf80008865a89dae91bad27de12915354b6937223ce72ef9f4295d089495ee577b2e29001486bb9cc1ff4217b23d1a7d7832bedaac9228ac3f224c
7
- data.tar.gz: e26a507cebd8e93f87b0b5cd8b7c206901cc3ff9ca01b85a92e4ec721a2c84e164a009b134c259fb88a5e35ef8f02b47aaf2ebb9eab22d45948acb30cc2dadc4
6
+ metadata.gz: a7f51eec122063edaffe94aa065f9bdd1dcc09752d46296f3f8d276d5af250ef82f1a2f56b7e0163f646c98731954d4bf5ce2b901f4e22b4e09033fd20fbf627
7
+ data.tar.gz: 7ed822140abca79f035a9bf59af3d472472b6bdfa4c1db505a22ae4ca0a80ca1fd380635487f72eb8fd74f706fd1e531fdf421f63b1614f6fcc5731b319c1489
data/build.gradle CHANGED
@@ -17,7 +17,7 @@ configurations {
17
17
  sourceCompatibility = 1.7
18
18
  targetCompatibility = 1.7
19
19
 
20
- version = "0.4.0"
20
+ version = "0.4.1"
21
21
 
22
22
  dependencies {
23
23
  compile "org.embulk:embulk-core:0.8.6"
@@ -255,7 +255,7 @@ public class GcsOutputPlugin implements FileOutputPlugin
255
255
  @Override
256
256
  public void finish()
257
257
  {
258
- String path = pathPrefix + String.format(sequenceFormat, taskIndex, fileIndex) + pathSuffix;
258
+ String path = generateRemotePath(pathPrefix, sequenceFormat, taskIndex, fileIndex, pathSuffix);
259
259
  close();
260
260
  if (tempFile != null) {
261
261
  currentUpload = startUpload(path);
@@ -419,6 +419,19 @@ public class GcsOutputPlugin implements FileOutputPlugin
419
419
  }
420
420
  }
421
421
 
422
+ /**
423
+ * GCS has character limitation in object names.
424
+ * @see https://cloud.google.com/storage/docs/naming#objectnames
425
+ * Although "." isn't listed at above pages, we can't access "./" path from GUI console.
426
+ * And in many cases, user don't intend of creating "/" directory under the bucket.
427
+ * This method normalizes path when it contains "./" and "/" and its variations at the beginning
428
+ */
429
+ private static String generateRemotePath(String pathPrefix, String sequenceFormat, int taskIndex, int fileIndex, String pathSuffix)
430
+ {
431
+ String path = pathPrefix + String.format(sequenceFormat, taskIndex, fileIndex) + pathSuffix;
432
+ return path.replaceFirst("^\\.*/*", "");
433
+ }
434
+
422
435
  public enum AuthMethod
423
436
  {
424
437
  private_key("private_key"),
@@ -70,7 +70,7 @@ public class TestGcsOutputPlugin
70
70
  assumeNotNull(GCP_EMAIL, GCP_P12_KEYFILE, GCP_JSON_KEYFILE, GCP_BUCKET);
71
71
 
72
72
  GCP_BUCKET_DIRECTORY = System.getenv("GCP_BUCKET_DIRECTORY") != null ? getDirectory(System.getenv("GCP_BUCKET_DIRECTORY")) : getDirectory("");
73
- GCP_PATH_PREFIX = GCP_BUCKET_DIRECTORY + "sample_";
73
+ GCP_PATH_PREFIX = GCP_BUCKET_DIRECTORY + "output_";
74
74
  LOCAL_PATH_PREFIX = GcsOutputPlugin.class.getClassLoader().getResource("sample_01.csv").getPath();
75
75
  GCP_APPLICATION_NAME = "embulk-output-gcs";
76
76
  }
@@ -275,10 +275,28 @@ public class TestGcsOutputPlugin
275
275
  output.finish();
276
276
  output.commit();
277
277
 
278
- String remotePath = GCP_PATH_PREFIX + String.format(task.getSequenceFormat(), 0, 0) + task.getFileNameExtension();
278
+ String remotePath = GCP_PATH_PREFIX + String.format(task.getSequenceFormat(), 0, 1) + task.getFileNameExtension();
279
279
  assertRecords(remotePath);
280
280
  }
281
281
 
282
+ @Test
283
+ public void testGenerateRemotePath() throws Exception
284
+ {
285
+ ConfigSource configSource = config();
286
+ PluginTask task = configSource.loadConfig(PluginTask.class);
287
+ Method method = GcsOutputPlugin.class.getDeclaredMethod("generateRemotePath", String.class, String.class, int.class, int.class, String.class);
288
+ method.setAccessible(true);
289
+ assertEquals("sample.000.01.csv", method.invoke(plugin, "/sample", task.getSequenceFormat(), 0, 1, ".csv"));
290
+ assertEquals("sample.000.01.csv", method.invoke(plugin, "./sample", task.getSequenceFormat(), 0, 1, ".csv"));
291
+ assertEquals("sample.000.01.csv", method.invoke(plugin, "../sample", task.getSequenceFormat(), 0, 1, ".csv"));
292
+ assertEquals("sample.000.01.csv", method.invoke(plugin, "//sample", task.getSequenceFormat(), 0, 1, ".csv"));
293
+ assertEquals("path/to/sample.000.01.csv", method.invoke(plugin, "/path/to/sample", task.getSequenceFormat(), 0, 1, ".csv"));
294
+ assertEquals("path/to/./sample.000.01.csv", method.invoke(plugin, "path/to/./sample", task.getSequenceFormat(), 0, 1, ".csv"));
295
+ assertEquals("path/to/../sample.000.01.csv", method.invoke(plugin, "path/to/../sample", task.getSequenceFormat(), 0, 1, ".csv"));
296
+ assertEquals("sample.000.01.csv", method.invoke(plugin, "....../sample", task.getSequenceFormat(), 0, 1, ".csv"));
297
+ assertEquals("sample.000.01.csv", method.invoke(plugin, "......///sample", task.getSequenceFormat(), 0, 1, ".csv"));
298
+ }
299
+
282
300
  public ConfigSource config()
283
301
  {
284
302
  return Exec.newConfigSource()
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: embulk-output-gcs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kazuyuki Honda
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-22 00:00:00.000000000 Z
11
+ date: 2017-05-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -71,7 +71,7 @@ files:
71
71
  - src/test/resources/sample_02.csv
72
72
  - classpath/commons-codec-1.3.jar
73
73
  - classpath/commons-logging-1.1.1.jar
74
- - classpath/embulk-output-gcs-0.4.0.jar
74
+ - classpath/embulk-output-gcs-0.4.1.jar
75
75
  - classpath/google-api-client-1.19.1.jar
76
76
  - classpath/google-api-services-storage-v1-rev28-1.19.1.jar
77
77
  - classpath/google-http-client-1.19.0.jar