embulk-parser-json 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -3
- data/embulk-parser-json.gemspec +1 -1
- data/lib/embulk/parser/jsonpath.rb +23 -5
- metadata +14 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b6f1282a901442d18e42cc128c2d3bd655ea6c13
|
4
|
+
data.tar.gz: 6ecce69a72ef4ef3937eb5a6e4c543eeb0589895
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c26df186cf61cde5cd9b39e5f87c274a88d9760c4de9b441c390eca5fa47ee9a353744f656ee19f5de1b7921f3111b5af8360dbccb1358ea18022b71e48166a6
|
7
|
+
data.tar.gz: 2c7ecd428848dc85478af476cd5009ab4e15777b40429602c89d847c990efe3ea6b09f3b191249de7347dc19516e8f1f762241ca290514ff167aeb5e0d833fdd
|
data/README.md
CHANGED
@@ -22,6 +22,7 @@ A type name has been changed from **json** to **jsonpath** from v0.0.3.
|
|
22
22
|
parser:
|
23
23
|
type: jsonpath
|
24
24
|
root: $.response.station
|
25
|
+
stop_on_invalid_record: false
|
25
26
|
schema:
|
26
27
|
- {name: name, type: string}
|
27
28
|
- {name: next, type: string}
|
@@ -34,9 +35,10 @@ parser:
|
|
34
35
|
- {name: optionals, type: json}
|
35
36
|
```
|
36
37
|
|
37
|
-
- **type**:
|
38
|
-
- **root**:
|
39
|
-
- **schema**:
|
38
|
+
- **type**: Specify this plugin as `json`
|
39
|
+
- **root**: Root property to start fetching each entries, specify in [jsonpath](http://goessner.net/articles/JsonPath/) style, required
|
40
|
+
- **schema**: Specify the attribute of table and data type, required
|
41
|
+
- **stop_on_invalid_record**: Stop bulk load transaction if a file includes invalid record, false by default
|
40
42
|
|
41
43
|
|
42
44
|
## Example
|
data/embulk-parser-json.gemspec
CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "embulk-parser-json"
|
7
|
-
spec.version = "0.0.
|
7
|
+
spec.version = "0.0.6"
|
8
8
|
spec.authors = ["Takuma kanari"]
|
9
9
|
spec.email = ["chemtrails.t@gmail.com"]
|
10
10
|
spec.summary = %q{Embulk parser plugin for json with jsonpath}
|
@@ -9,8 +9,9 @@ module Embulk
|
|
9
9
|
|
10
10
|
def self.transaction(config, &control)
|
11
11
|
task = {
|
12
|
-
:
|
13
|
-
:
|
12
|
+
schema: config.param("schema", :array),
|
13
|
+
root: config.param("root", :string),
|
14
|
+
stop_on_invalid_record: config.param("stop_on_invalid_record", :bool, default: false)
|
14
15
|
}
|
15
16
|
columns = task[:schema].each_with_index.map do |c, i|
|
16
17
|
Column.new(i, c["name"], c["type"].to_sym)
|
@@ -21,9 +22,16 @@ module Embulk
|
|
21
22
|
def run(file_input)
|
22
23
|
root = JsonPath.new(@task["root"])
|
23
24
|
schema = @task["schema"]
|
25
|
+
stop_on_invalid_record = @task["stop_on_invalid_record"]
|
24
26
|
while file = file_input.next_file
|
25
|
-
|
26
|
-
|
27
|
+
json_text = file.read
|
28
|
+
begin
|
29
|
+
root.on(JSON.parse(json_text)).flatten.each do |e|
|
30
|
+
@page_builder.add(make_record(schema, e))
|
31
|
+
end
|
32
|
+
rescue JSON::ParserError, DataParseError => e
|
33
|
+
raise "Invalid record: '#{json_text}' (#{e})" if stop_on_invalid_record
|
34
|
+
Embulk.logger.warn "Skipped record (#{e}): '#{json_text}'"
|
27
35
|
end
|
28
36
|
end
|
29
37
|
@page_builder.finish
|
@@ -59,7 +67,15 @@ module Embulk
|
|
59
67
|
!!val
|
60
68
|
end
|
61
69
|
when "timestamp"
|
62
|
-
val.nil? || val.empty?
|
70
|
+
if val.nil? || val.empty?
|
71
|
+
nil
|
72
|
+
else
|
73
|
+
begin
|
74
|
+
Time.strptime(val, c["format"])
|
75
|
+
rescue ArgumentError => e
|
76
|
+
raise DataParseError.new e
|
77
|
+
end
|
78
|
+
end
|
63
79
|
else
|
64
80
|
raise "Unsupported type #{type}"
|
65
81
|
end
|
@@ -69,6 +85,8 @@ module Embulk
|
|
69
85
|
def kind_of_boolean?(val)
|
70
86
|
val.kind_of?(TrueClass) || val.kind_of?(FalseClass)
|
71
87
|
end
|
88
|
+
|
89
|
+
class DataParseError < StandardError ; end
|
72
90
|
end
|
73
91
|
end
|
74
92
|
end
|
metadata
CHANGED
@@ -1,59 +1,58 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: embulk-parser-json
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Takuma kanari
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-02-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name: jsonpath
|
15
14
|
requirement: !ruby/object:Gem::Requirement
|
16
15
|
requirements:
|
17
16
|
- - "~>"
|
18
17
|
- !ruby/object:Gem::Version
|
19
18
|
version: '0.5'
|
20
|
-
|
19
|
+
name: jsonpath
|
21
20
|
prerelease: false
|
21
|
+
type: :runtime
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0.5'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name: bundler
|
29
28
|
requirement: !ruby/object:Gem::Requirement
|
30
29
|
requirements:
|
31
30
|
- - "~>"
|
32
31
|
- !ruby/object:Gem::Version
|
33
32
|
version: '1.0'
|
34
|
-
|
33
|
+
name: bundler
|
35
34
|
prerelease: false
|
35
|
+
type: :development
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '1.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name: rake
|
43
42
|
requirement: !ruby/object:Gem::Requirement
|
44
43
|
requirements:
|
45
44
|
- - "~>"
|
46
45
|
- !ruby/object:Gem::Version
|
47
46
|
version: '10.0'
|
48
|
-
|
47
|
+
name: rake
|
49
48
|
prerelease: false
|
49
|
+
type: :development
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '10.0'
|
55
|
-
description: Json parser plugin is Embulk plugin to fetch entries in json format with
|
56
|
-
jsonpath.
|
55
|
+
description: Json parser plugin is Embulk plugin to fetch entries in json format with jsonpath.
|
57
56
|
email:
|
58
57
|
- chemtrails.t@gmail.com
|
59
58
|
executables: []
|
@@ -71,7 +70,7 @@ homepage: https://github.com/takumakanari/embulk-parser-json
|
|
71
70
|
licenses:
|
72
71
|
- MIT
|
73
72
|
metadata: {}
|
74
|
-
post_install_message:
|
73
|
+
post_install_message:
|
75
74
|
rdoc_options: []
|
76
75
|
require_paths:
|
77
76
|
- lib
|
@@ -86,9 +85,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
86
85
|
- !ruby/object:Gem::Version
|
87
86
|
version: '0'
|
88
87
|
requirements: []
|
89
|
-
rubyforge_project:
|
90
|
-
rubygems_version: 2.
|
91
|
-
signing_key:
|
88
|
+
rubyforge_project:
|
89
|
+
rubygems_version: 2.6.6
|
90
|
+
signing_key:
|
92
91
|
specification_version: 4
|
93
92
|
summary: Embulk parser plugin for json with jsonpath
|
94
93
|
test_files: []
|