embulk-filter-expand_json 0.1.2 → 0.1.3

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: 4eb62c73f09245613f9c6950d72f840434d6cc16
4
- data.tar.gz: b46a7998eeab53f56fe524a6746d9c266ee45a53
3
+ metadata.gz: 20479395de0c44c53f19f7f0ef50cb51733d4fd8
4
+ data.tar.gz: d4c932d30cf21a260b92c20b4ea5a0dfcf8e117c
5
5
  SHA512:
6
- metadata.gz: dd2395c19f4113da5d4c98624ebc8d4c3a2b268bb68a9e0091cc4955ea5fb1696665c1541d9bcf183ba6b8e9b2f76291c340face70e17c6ffbfdd949024beb31
7
- data.tar.gz: d1005e506f9f61dcb06e08da8c396983ed04797a25d8d5add72828a14fe19ee1b77ec7c391dfd0518d6f1717a1e1c436769ddedc413ad068e1b343cee2102124
6
+ metadata.gz: 1d9de6fe928ef8c0109797af93e4372026a67a376fbe6d3b3ca3da4ad9e97af1a887e5c408740238459031c69af5d78c7fe145ef69517190c701607d8efc5f37
7
+ data.tar.gz: 6667c87842b18e870b5669cd075dad44e5d6b66b9d769554020025ee486f4883485fedbfcd3a6242e1e0f7c9d94d4da952f676f1d75823c7dc7b28c9e722e020
@@ -1,3 +1,8 @@
1
+ 0.1.3 (2016-07-27)
2
+ ==================
3
+ - [Enhancement] Improve Exception handling
4
+ - https://github.com/civitaspo/embulk-filter-expand_json/pull/23
5
+
1
6
  0.1.2 (2016-05-31)
2
7
  ==================
3
8
  - [Enhancement] Add a validation to check column duplication
data/README.md CHANGED
@@ -69,3 +69,4 @@ $ ./gradlew gem # -t to watch change of files and rebuild continuously
69
69
  ## Contributor
70
70
  - @Civitaspo
71
71
  - @muga
72
+ - @sakama
@@ -15,7 +15,7 @@ configurations {
15
15
  provided
16
16
  }
17
17
 
18
- version = "0.1.2"
18
+ version = "0.1.3"
19
19
  sourceCompatibility = 1.7
20
20
  targetCompatibility = 1.7
21
21
 
@@ -20,7 +20,9 @@ import org.embulk.spi.PageBuilder;
20
20
  import org.embulk.spi.PageOutput;
21
21
  import org.embulk.spi.PageReader;
22
22
  import org.embulk.spi.Schema;
23
+ import org.embulk.spi.json.JsonParseException;
23
24
  import org.embulk.spi.json.JsonParser;
25
+ import org.embulk.spi.time.TimestampParseException;
24
26
  import org.embulk.spi.time.TimestampParser;
25
27
  import org.embulk.spi.type.Types;
26
28
  import org.joda.time.DateTimeZone;
@@ -308,22 +310,42 @@ public class FilteredPageOutput
308
310
  pageBuilder.setBoolean(expandedJsonColumn.getColumn(), Boolean.parseBoolean(finalValue));
309
311
  }
310
312
  else if (Types.DOUBLE.equals(expandedJsonColumn.getColumn().getType())) {
311
- pageBuilder.setDouble(expandedJsonColumn.getColumn(), Double.parseDouble(finalValue));
313
+ try {
314
+ pageBuilder.setDouble(expandedJsonColumn.getColumn(), Double.parseDouble(finalValue));
315
+ }
316
+ catch (NumberFormatException e) {
317
+ throw new JsonValueInvalidException(String.format("Failed to parse '%s' as double", finalValue), e);
318
+ }
312
319
  }
313
320
  else if (Types.LONG.equals(expandedJsonColumn.getColumn().getType())) {
314
- pageBuilder.setLong(expandedJsonColumn.getColumn(), Long.parseLong(finalValue));
321
+ try {
322
+ pageBuilder.setLong(expandedJsonColumn.getColumn(), Long.parseLong(finalValue));
323
+ }
324
+ catch (NumberFormatException e) {
325
+ throw new JsonValueInvalidException(String.format("Failed to parse '%s' as long", finalValue), e);
326
+ }
315
327
  }
316
328
  else if (Types.TIMESTAMP.equals(expandedJsonColumn.getColumn().getType())) {
317
329
  if (expandedJsonColumn.getTimestampParser().isPresent()) {
318
330
  TimestampParser parser = expandedJsonColumn.getTimestampParser().get();
319
- pageBuilder.setTimestamp(expandedJsonColumn.getColumn(), parser.parse(finalValue));
331
+ try {
332
+ pageBuilder.setTimestamp(expandedJsonColumn.getColumn(), parser.parse(finalValue));
333
+ }
334
+ catch (TimestampParseException e) {
335
+ throw new JsonValueInvalidException(String.format("Failed to parse '%s' as timestamp", finalValue), e);
336
+ }
320
337
  }
321
338
  else {
322
339
  throw new RuntimeException("TimestampParser is absent for column:" + expandedJsonColumn.getKey());
323
340
  }
324
341
  }
325
342
  else if (Types.JSON.equals(expandedJsonColumn.getColumn().getType())) {
326
- pageBuilder.setJson(expandedJsonColumn.getColumn(), jsonParser.parse(finalValue));
343
+ try {
344
+ pageBuilder.setJson(expandedJsonColumn.getColumn(), jsonParser.parse(finalValue));
345
+ }
346
+ catch (JsonParseException e) {
347
+ throw new JsonValueInvalidException(String.format("Failed to parse '%s' as JSON", finalValue), e);
348
+ }
327
349
  }
328
350
  }
329
351
  }
@@ -347,4 +369,12 @@ public class FilteredPageOutput
347
369
  return String.valueOf(value);
348
370
  }
349
371
  }
372
+
373
+ private class JsonValueInvalidException extends DataException
374
+ {
375
+ JsonValueInvalidException(String message, Throwable cause)
376
+ {
377
+ super(message, cause);
378
+ }
379
+ }
350
380
  }
@@ -500,6 +500,65 @@ public class TestExpandJsonFilterPlugin
500
500
  });
501
501
  }
502
502
 
503
+ @Test(expected = DataException.class)
504
+ public void testSetExpandedJsonColumnsSetInvalidDoubleValue()
505
+ {
506
+ setExpandedJsonColumnsWithInvalidValue("double", s("abcde"));
507
+ }
508
+
509
+ @Test(expected = DataException.class)
510
+ public void testSetExpandedJsonColumnsSetInvalidLongValue()
511
+ {
512
+ setExpandedJsonColumnsWithInvalidValue("long", s("abcde"));
513
+ }
514
+
515
+ @Test(expected = DataException.class)
516
+ public void testSetExpandedJsonColumnsSetInvalidTimestampValue()
517
+ {
518
+ setExpandedJsonColumnsWithInvalidValue("timestamp", s("abcde"));
519
+ }
520
+
521
+ @Test(expected = DataException.class)
522
+ public void testSetExpandedJsonColumnsSetInvalidJsonValue()
523
+ {
524
+ setExpandedJsonColumnsWithInvalidValue("json", s("abcde"));
525
+ }
526
+
527
+ public void setExpandedJsonColumnsWithInvalidValue(String ValidType, final Value invalidValue)
528
+ {
529
+ String configYaml = "" +
530
+ "type: expand_json\n" +
531
+ "stop_on_invalid_record: 1\n" +
532
+ "json_column_name: _c0\n" +
533
+ "root: $.\n" +
534
+ "time_zone: Asia/Tokyo\n" +
535
+ "expanded_columns:\n" +
536
+ " - {name: _j0, type: " + ValidType + "}\n";
537
+
538
+ ConfigSource config = getConfigFromYaml(configYaml);
539
+ final Schema schema = schema("_c0", JSON, "_c1", STRING);
540
+
541
+ expandJsonFilterPlugin.transaction(config, schema, new Control()
542
+ {
543
+ @Override
544
+ public void run(TaskSource taskSource, Schema outputSchema)
545
+ {
546
+ MockPageOutput mockPageOutput = new MockPageOutput();
547
+ Value data = newMapBuilder()
548
+ .put(s("_j0"), invalidValue)
549
+ .build();
550
+
551
+ try (PageOutput pageOutput = expandJsonFilterPlugin.open(taskSource, schema, outputSchema, mockPageOutput)) {
552
+ for (Page page : PageTestUtils.buildPage(runtime.getBufferAllocator(), schema, data, c1Data)) {
553
+ pageOutput.add(page);
554
+ }
555
+
556
+ pageOutput.finish();
557
+ }
558
+ }
559
+ });
560
+ }
561
+
503
562
  @Test
504
563
  public void testExpandedJsonValuesWithKeepJsonColumns()
505
564
  {
metadata CHANGED
@@ -1,43 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: embulk-filter-expand_json
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Civitaspo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-31 00:00:00.000000000 Z
11
+ date: 2016-07-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: bundler
15
- version_requirements: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ~>
18
- - !ruby/object:Gem::Version
19
- version: '1.0'
20
14
  requirement: !ruby/object:Gem::Requirement
21
15
  requirements:
22
16
  - - ~>
23
17
  - !ruby/object:Gem::Version
24
18
  version: '1.0'
19
+ name: bundler
25
20
  prerelease: false
26
21
  type: :development
27
- - !ruby/object:Gem::Dependency
28
- name: rake
29
22
  version_requirements: !ruby/object:Gem::Requirement
30
23
  requirements:
31
- - - '>='
24
+ - - ~>
32
25
  - !ruby/object:Gem::Version
33
- version: '10.0'
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
34
28
  requirement: !ruby/object:Gem::Requirement
35
29
  requirements:
36
30
  - - '>='
37
31
  - !ruby/object:Gem::Version
38
32
  version: '10.0'
33
+ name: rake
39
34
  prerelease: false
40
35
  type: :development
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
41
  description: Expand Json
42
42
  email:
43
43
  - civitaspo@gmail.com
@@ -65,7 +65,7 @@ files:
65
65
  - src/test/java/org/embulk/filter/expand_json/TestExpandJsonFilterPlugin.java
66
66
  - classpath/accessors-smart-1.1.jar
67
67
  - classpath/asm-5.0.3.jar
68
- - classpath/embulk-filter-expand_json-0.1.2.jar
68
+ - classpath/embulk-filter-expand_json-0.1.3.jar
69
69
  - classpath/json-path-2.2.0.jar
70
70
  - classpath/json-smart-2.2.1.jar
71
71
  - classpath/slf4j-api-1.7.16.jar