embulk-parser-jsonpath 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -2
- data/README.md +2 -2
- data/build.gradle +5 -3
- data/lib/embulk/guess/jsonpath.rb +24 -54
- metadata +33 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3fd87aab165b58977d3110a7a915f327e453813e
|
4
|
+
data.tar.gz: b88edab1cf1df67f66cccd1281a4f4ec21dbacd4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a7ad10c37acef5698b6566e9d42a08b97a8a3c819e467945224deba9886d1fe3c2780d6e1eb5f95ad87639f59d16bbab58a031983b9bbd5ae7bef34c81e7eb82
|
7
|
+
data.tar.gz: 0bab6a0db8c79e2ba3dce758710ee310178aba2f94d8c66f15bed2ce940c40c68f63e99e654f910d027565ff735552e4809141772f00995efbaa2e25da822bc0
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -5,7 +5,7 @@ The JSON with [JSONPath](http://goessner.net/articles/JsonPath/) parser plugin f
|
|
5
5
|
## Overview
|
6
6
|
|
7
7
|
* **Plugin type**: parser
|
8
|
-
* **Guess supported**:
|
8
|
+
* **Guess supported**: yes
|
9
9
|
|
10
10
|
## Configuration
|
11
11
|
|
@@ -91,7 +91,7 @@ registered_at (timestamp) : 2014-06-30 19:25:27 UTC
|
|
91
91
|
|
92
92
|
```
|
93
93
|
$ embulk gem install embulk-parser-jsonpath
|
94
|
-
$ embulk guess -g jsonpath config.yml -o guessed.yml
|
94
|
+
$ embulk guess -g jsonpath config.yml -o guessed.yml
|
95
95
|
```
|
96
96
|
|
97
97
|
## Build
|
data/build.gradle
CHANGED
@@ -14,7 +14,7 @@ configurations {
|
|
14
14
|
provided
|
15
15
|
}
|
16
16
|
|
17
|
-
version = "0.1.
|
17
|
+
version = "0.1.1"
|
18
18
|
|
19
19
|
sourceCompatibility = 1.7
|
20
20
|
targetCompatibility = 1.7
|
@@ -91,8 +91,8 @@ Gem::Specification.new do |spec|
|
|
91
91
|
spec.name = "${project.name}"
|
92
92
|
spec.version = "${project.version}"
|
93
93
|
spec.authors = ["Hiroyuki Sato"]
|
94
|
-
spec.summary = %[
|
95
|
-
spec.description = %[Parses
|
94
|
+
spec.summary = %[JSON parser with JSONPath plugin for Embulk]
|
95
|
+
spec.description = %[Parses JSON files with JSONPath read by other file input plugins.]
|
96
96
|
spec.email = ["hiroysato@gmail.com"]
|
97
97
|
spec.licenses = ["MIT"]
|
98
98
|
spec.homepage = "https://github.com/hiroyuki-sato/embulk-parser-jsonpath"
|
@@ -104,6 +104,8 @@ Gem::Specification.new do |spec|
|
|
104
104
|
#spec.add_dependency 'YOUR_GEM_DEPENDENCY', ['~> YOUR_GEM_DEPENDENCY_VERSION']
|
105
105
|
spec.add_development_dependency 'bundler', ['~> 1.0']
|
106
106
|
spec.add_development_dependency 'rake', ['>= 10.0']
|
107
|
+
spec.add_dependency 'jsonpath', ['~> 0.5.8'] # for guess
|
108
|
+
spec.add_dependency 'json', ['~> 2.0.2'] # for guess
|
107
109
|
end
|
108
110
|
/$)
|
109
111
|
}
|
@@ -1,61 +1,31 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'jsonpath'
|
1
3
|
module Embulk
|
2
4
|
module Guess
|
3
5
|
|
4
|
-
|
5
|
-
|
6
|
-
#
|
7
|
-
# Depending on the file format the plugin uses, you can use choose
|
8
|
-
# one of binary guess (GuessPlugin), text guess (TextGuessPlugin),
|
9
|
-
# or line guess (LineGuessPlugin).
|
6
|
+
class Jsonpath < TextGuessPlugin
|
7
|
+
Plugin.register_guess("jsonpath", self)
|
10
8
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
# def guess_text(config, sample_text)
|
30
|
-
# js = JSON.parse(sample_text) rescue nil
|
31
|
-
# if js && js["mykeyword"] == "keyword"
|
32
|
-
# guessed = {}
|
33
|
-
# guessed["type"] = "jsonpath"
|
34
|
-
# guessed["property1"] = "guessed-value"
|
35
|
-
# return {"parser" => guessed}
|
36
|
-
# else
|
37
|
-
# return {}
|
38
|
-
# end
|
39
|
-
# end
|
40
|
-
#end
|
41
|
-
|
42
|
-
#class Jsonpath < LineGuessPlugin
|
43
|
-
# Plugin.register_guess("jsonpath", self)
|
44
|
-
#
|
45
|
-
# def guess_lines(config, sample_lines)
|
46
|
-
# all_line_matched = sample_lines.all? do |line|
|
47
|
-
# line =~ /mypattern/
|
48
|
-
# end
|
49
|
-
# if all_line_matched
|
50
|
-
# guessed = {}
|
51
|
-
# guessed["type"] = "jsonpath"
|
52
|
-
# guessed["property1"] = "guessed-value"
|
53
|
-
# return {"parser" => guessed}
|
54
|
-
# else
|
55
|
-
# return {}
|
56
|
-
# end
|
57
|
-
# end
|
58
|
-
#end
|
9
|
+
def guess_text(config, sample_text)
|
10
|
+
parser_config = config.param("parser",:hash)
|
11
|
+
json_path = parser_config.param("root",:string,default: "$")
|
12
|
+
json = JsonPath.new(json_path).on(sample_text).first
|
13
|
+
if( json.kind_of?(Array) )
|
14
|
+
no_hash = json.find{ |j| !j.kind_of?(Hash) }
|
15
|
+
raise RuntimeError,"Can't exec guess. The row data must be hash." if no_hash
|
16
|
+
columns = Embulk::Guess::SchemaGuess.from_hash_records(json).map do |c|
|
17
|
+
column = {name: c.name, type: c.type}
|
18
|
+
column[:format] = c.format if c.format
|
19
|
+
column
|
20
|
+
end
|
21
|
+
parser_guessed = {"type" => "jsonpath"}
|
22
|
+
parser_guessed["columns"] = columns
|
23
|
+
return {"parser" => parser_guessed}
|
24
|
+
else
|
25
|
+
raise RuntimeError,"Can't guess specified the JSONPath: #{json_path}. The results does not return an Array."
|
26
|
+
end
|
59
27
|
|
28
|
+
end
|
29
|
+
end
|
60
30
|
end
|
61
31
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: embulk-parser-jsonpath
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hiroyuki Sato
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-08-
|
11
|
+
date: 2016-08-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|
@@ -38,7 +38,35 @@ dependencies:
|
|
38
38
|
- - '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
|
-
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ~>
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 0.5.8
|
47
|
+
name: jsonpath
|
48
|
+
prerelease: false
|
49
|
+
type: :runtime
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.5.8
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ~>
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 2.0.2
|
61
|
+
name: json
|
62
|
+
prerelease: false
|
63
|
+
type: :runtime
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 2.0.2
|
69
|
+
description: Parses JSON files with JSONPath read by other file input plugins.
|
42
70
|
email:
|
43
71
|
- hiroysato@gmail.com
|
44
72
|
executables: []
|
@@ -82,7 +110,7 @@ files:
|
|
82
110
|
- src/test/java/org/embulk/parser/jsonpath/cast/TestStringCast.java
|
83
111
|
- classpath/accessors-smart-1.1.jar
|
84
112
|
- classpath/asm-5.0.3.jar
|
85
|
-
- classpath/embulk-parser-jsonpath-0.1.
|
113
|
+
- classpath/embulk-parser-jsonpath-0.1.1.jar
|
86
114
|
- classpath/json-path-2.2.0.jar
|
87
115
|
- classpath/json-smart-2.2.1.jar
|
88
116
|
- classpath/slf4j-api-1.7.16.jar
|
@@ -109,5 +137,5 @@ rubyforge_project:
|
|
109
137
|
rubygems_version: 2.1.9
|
110
138
|
signing_key:
|
111
139
|
specification_version: 4
|
112
|
-
summary:
|
140
|
+
summary: JSON parser with JSONPath plugin for Embulk
|
113
141
|
test_files: []
|