embulk-parser-jsonpath 0.1.0 → 0.1.1

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: e04c063be3c7b2fcb088030d094dcbfb05c90ad7
4
- data.tar.gz: c997fe5b4eba204de4cf4edce9f1aa6f854dd5a1
3
+ metadata.gz: 3fd87aab165b58977d3110a7a915f327e453813e
4
+ data.tar.gz: b88edab1cf1df67f66cccd1281a4f4ec21dbacd4
5
5
  SHA512:
6
- metadata.gz: 996c9b529982c2f40ffe0267f15bd164d3c400527c472d17fe5a76e14a4b1fcc40d5fcc8426221c84b2821bb3d3f3e6bff7db938ffc40cf18ed339680d20ae10
7
- data.tar.gz: 1db38cd4ba4cb1b6a09514dd7094187e741983f92c846274080021844bf418234738e0fa83fd18c520ae1bdc17e81cf8edaf7dc30720394358f363ae4d17d9a4
6
+ metadata.gz: a7ad10c37acef5698b6566e9d42a08b97a8a3c819e467945224deba9886d1fe3c2780d6e1eb5f95ad87639f59d16bbab58a031983b9bbd5ae7bef34c81e7eb82
7
+ data.tar.gz: 0bab6a0db8c79e2ba3dce758710ee310178aba2f94d8c66f15bed2ce940c40c68f63e99e654f910d027565ff735552e4809141772f00995efbaa2e25da822bc0
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # ChangeLog
2
2
 
3
- # 0.1.0 (2016-08-29)
3
+ ## 0.1.0 (2016-08-31)
4
4
 
5
- first version
5
+ * Implement guess. (Use JRuby now.)
6
+
7
+ ## 0.1.0 (2016-08-29)
8
+
9
+ * first version
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**: no (TODO)
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 (not yet implemented)
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.0"
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 = %[Jsonpath parser plugin for Embulk]
95
- spec.description = %[Parses Jsonpath files read by other file input plugins.]
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
- # TODO implement guess plugin to make this command work:
5
- # $ embulk guess -g "jsonpath" partial-config.yml
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
- #class Jsonpath < GuessPlugin
12
- # Plugin.register_guess("jsonpath", self)
13
- #
14
- # def guess(config, sample_buffer)
15
- # if sample_buffer[0,2] == GZIP_HEADER
16
- # guessed = {}
17
- # guessed["type"] = "jsonpath"
18
- # guessed["property1"] = "guessed-value"
19
- # return {"parser" => guessed}
20
- # else
21
- # return {}
22
- # end
23
- # end
24
- #end
25
-
26
- #class Jsonpath < TextGuessPlugin
27
- # Plugin.register_guess("jsonpath", self)
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.0
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-29 00:00:00.000000000 Z
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
- description: Parses Jsonpath files read by other file input plugins.
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.0.jar
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: Jsonpath parser plugin for Embulk
140
+ summary: JSON parser with JSONPath plugin for Embulk
113
141
  test_files: []