fluent-plugin-mysql 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 408a12decbefd767bb9f236f852e35d7596ffc7c
4
- data.tar.gz: 12d2f9728137b662469dd1c4a2d36b21e2b51ee3
3
+ metadata.gz: 01f59910a106e764bf3301deccc502886aca1297
4
+ data.tar.gz: a073cae83947ca7f314bbab63d68655aac08f939
5
5
  SHA512:
6
- metadata.gz: 3d6c9bb6d2a154b881cfaef8600e2bfea88f7ffaeaea7ecd96834507e7979c64acdc1f51e248a62f08a69b2a38efa6209474af69286d46a59c29c13f9901915a
7
- data.tar.gz: ad4827600dd00abd928f57e30e8f97578c4756391fbe48cc51a096f3e4623dc235182bcc964c8cc675fad9e34ae67e6764269756cb1b2d56b6a98cd770b68f22
6
+ metadata.gz: ee8e3ac4aba73b8c53744bcef56d4ebad1df87d935d11a8179b4107bc048beb7d02dcbfffcd40ea137137e3c7ad539a0066e71cafad56a6de09f119013fcbb43
7
+ data.tar.gz: 14ab65885630ebf03e699ffca944a46ab47b8fa84fb302714fed6c25892da842987ec8c3998b4d901707dc8a9e32a7fdae51115ba17308d309cc81a83e68bc7d
data/README.md CHANGED
@@ -95,6 +95,35 @@ Or, for json:
95
95
  </match>
96
96
  #=> inserted json data into column 'jsondata' with addtional attribute 'timeattr' and 'tagattr'
97
97
 
98
+ ### JsonPath format
99
+
100
+ You can use [JsonPath](http://goessner.net/articles/JsonPath/) selectors as key_names, such as:
101
+
102
+ <match output.with.jsonpath.format.*>
103
+ type mysql
104
+ host database.local
105
+ database foo
106
+ username bar
107
+
108
+ include_time_key yes
109
+ utc
110
+ include_tag_key yes
111
+ table baz
112
+
113
+ format jsonpath
114
+ key_names time, tag, id, data.name, tags[0]
115
+ sql INSERT INTO baz (coltime,coltag,id,name,tag1) VALUES (?,?,?,?,?)
116
+ </match>
117
+
118
+ Which for a record like:
119
+
120
+ `{ 'id' => 15, 'data'=> {'name' => 'jsonpath' }, 'tags' => ['unit', 'simple'] }`
121
+
122
+ will generate the following insert values:
123
+
124
+ `('2012-12-17T01:23:45Z','test',15,'jsonpath','unit')`
125
+
126
+
98
127
  ## TODO
99
128
 
100
129
  * implement 'tag_mapped'
@@ -1,7 +1,7 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  Gem::Specification.new do |gem|
3
3
  gem.name = "fluent-plugin-mysql"
4
- gem.version = "0.0.5"
4
+ gem.version = "0.0.6"
5
5
  gem.authors = ["TAGOMORI Satoshi"]
6
6
  gem.email = ["tagomoris@gmail.com"]
7
7
  gem.description = %q{fluent plugin to insert mysql as json(single column) or insert statement}
@@ -16,5 +16,6 @@ Gem::Specification.new do |gem|
16
16
 
17
17
  gem.add_runtime_dependency "fluentd"
18
18
  gem.add_runtime_dependency "mysql2-cs-bind"
19
+ gem.add_runtime_dependency "jsonpath"
19
20
  gem.add_development_dependency "rake"
20
21
  end
@@ -22,6 +22,7 @@ class Fluent::MysqlOutput < Fluent::BufferedOutput
22
22
  def initialize
23
23
  super
24
24
  require 'mysql2-cs-bind'
25
+ require 'jsonpath'
25
26
  end
26
27
 
27
28
  def configure(conf)
@@ -29,8 +30,17 @@ class Fluent::MysqlOutput < Fluent::BufferedOutput
29
30
 
30
31
  # TODO tag_mapped
31
32
 
32
- if @format == 'json'
33
+ case @format
34
+ when 'json'
33
35
  @format_proc = Proc.new{|tag, time, record| record.to_json}
36
+ when 'jsonpath'
37
+ @key_names = @key_names.split(',')
38
+ @format_proc = Proc.new do |tag, time, record|
39
+ json = record.to_json
40
+ @key_names.map do |k|
41
+ JsonPath.new(k.strip).on(json).first
42
+ end
43
+ end
34
44
  else
35
45
  @key_names = @key_names.split(',')
36
46
  @format_proc = Proc.new{|tag, time, record| @key_names.map{|k| record[k]}}
@@ -156,6 +156,29 @@ format json
156
156
  d.run
157
157
  end
158
158
 
159
+ def test_jsonpath_format
160
+ d = create_driver %[
161
+ host database.local
162
+ database foo
163
+ username bar
164
+ password mogera
165
+ include_time_key yes
166
+ utc
167
+ include_tag_key yes
168
+ table baz
169
+ format jsonpath
170
+ key_names time, tag, id, data.name, tags[0]
171
+ sql INSERT INTO baz (coltime,coltag,id,name,tag1) VALUES (?,?,?,?,?)
172
+ ]
173
+ assert_equal 'INSERT INTO baz (coltime,coltag,id,name,tag1) VALUES (?,?,?,?,?)', d.instance.sql
174
+
175
+ time = Time.parse('2012-12-17 01:23:45 UTC').to_i
176
+ record = { 'id' => 15, 'data'=> {'name' => 'jsonpath' }, 'tags' => ['unit', 'simple'] }
177
+ d.emit(record, time)
178
+ d.expect_format ['test', time, ['2012-12-17T01:23:45Z','test',15,'jsonpath','unit']].to_msgpack
179
+ d.run
180
+ end
181
+
159
182
  def test_write
160
183
  # hmm....
161
184
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-mysql
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - TAGOMORI Satoshi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-03 00:00:00.000000000 Z
11
+ date: 2014-01-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fluentd
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: jsonpath
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rake
43
57
  requirement: !ruby/object:Gem::Requirement