embulk-filter-expand_json 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 20479395de0c44c53f19f7f0ef50cb51733d4fd8
|
4
|
+
data.tar.gz: d4c932d30cf21a260b92c20b4ea5a0dfcf8e117c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d9de6fe928ef8c0109797af93e4372026a67a376fbe6d3b3ca3da4ad9e97af1a887e5c408740238459031c69af5d78c7fe145ef69517190c701607d8efc5f37
|
7
|
+
data.tar.gz: 6667c87842b18e870b5669cd075dad44e5d6b66b9d769554020025ee486f4883485fedbfcd3a6242e1e0f7c9d94d4da952f676f1d75823c7dc7b28c9e722e020
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
data/build.gradle
CHANGED
@@ -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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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.
|
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-
|
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: '
|
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.
|
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
|