fluent-plugin-filter_where 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.travis.yml +9 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +3 -0
- data/Gemfile.fluentd.0.12 +4 -0
- data/LICENSE +22 -0
- data/README.md +141 -0
- data/Rakefile +24 -0
- data/example.conf +14 -0
- data/fluent-plugin-filter_where.gemspec +30 -0
- data/lib/fluent/plugin/filter_where.rb +7 -0
- data/lib/fluent/plugin/filter_where/core.rb +32 -0
- data/lib/fluent/plugin/filter_where/parser.racc +86 -0
- data/lib/fluent/plugin/filter_where/parser.rex +92 -0
- data/lib/fluent/plugin/filter_where/parser.rex.rb +206 -0
- data/lib/fluent/plugin/filter_where/parser.tab.rb +419 -0
- data/lib/fluent/plugin/filter_where/parser/exp.rb +178 -0
- data/lib/fluent/plugin/filter_where/parser/literal.rb +56 -0
- data/lib/fluent/plugin/filter_where/v12.rb +26 -0
- data/lib/fluent/plugin/filter_where/v14.rb +21 -0
- data/test/bench_filter_where.rb +23 -0
- data/test/helper.rb +98 -0
- data/test/test_filter_where.rb +37 -0
- data/test/test_where_parser.rb +109 -0
- metadata +197 -0
@@ -0,0 +1,109 @@
|
|
1
|
+
require_relative 'helper'
|
2
|
+
|
3
|
+
class WhereParserTest < Test::Unit::TestCase
|
4
|
+
class << self
|
5
|
+
def systemputs(cmd)
|
6
|
+
puts cmd
|
7
|
+
raise unless system cmd
|
8
|
+
end
|
9
|
+
|
10
|
+
def startup
|
11
|
+
systemputs "racc #{ROOT}/lib/fluent/plugin/filter_where/parser.racc -o #{ROOT}/lib/fluent/plugin/filter_where/parser.tab.rb"
|
12
|
+
systemputs "rex #{ROOT}/lib/fluent/plugin/filter_where/parser.rex -o #{ROOT}/lib/fluent/plugin/filter_where/parser.rex.rb"
|
13
|
+
require 'fluent/plugin/filter_where/parser.tab'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def parser
|
18
|
+
@parser ||= Fluent::FilterWhere::Parser.new
|
19
|
+
end
|
20
|
+
|
21
|
+
def record
|
22
|
+
{'boolean' => true, 'integer' => 1, 'float' => 1.5, 'string' => 'string', 'time' => 0}
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_parse
|
26
|
+
result = parser.scan(%q[boolean = true])
|
27
|
+
assert_true(result.eval(record))
|
28
|
+
result = parser.scan(%q[boolean = false])
|
29
|
+
assert_false(result.eval(record))
|
30
|
+
|
31
|
+
result = parser.scan(%q[integer = 1])
|
32
|
+
assert_true(result.eval(record))
|
33
|
+
result = parser.scan(%q[integer = 0])
|
34
|
+
assert_false(result.eval(record))
|
35
|
+
|
36
|
+
result = parser.scan(%q[float = 1.5])
|
37
|
+
assert_true(result.eval(record))
|
38
|
+
result = parser.scan(%q[float = 1])
|
39
|
+
assert_false(result.eval(record))
|
40
|
+
|
41
|
+
result = parser.scan(%q[string = 'string'])
|
42
|
+
assert_true(result.eval(record))
|
43
|
+
result = parser.scan(%q[string = 'foobar'])
|
44
|
+
assert_false(result.eval(record))
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_identifier_literal
|
48
|
+
result = parser.scan(%q["boolean" = true])
|
49
|
+
assert_true(result.eval(record))
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_string_literal
|
53
|
+
result = parser.scan(%q["string" = 'string'])
|
54
|
+
assert_true(result.eval(record))
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_boolean_op
|
58
|
+
result = parser.scan(%q[boolean = true])
|
59
|
+
assert_true(result.eval(record))
|
60
|
+
result = parser.scan(%q[boolean != false])
|
61
|
+
assert_true(result.eval(record))
|
62
|
+
assert_raise(Racc::ParseError) { parser.scan(%q[boolean > false]) }
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_number_op
|
66
|
+
result = parser.scan(%q[integer = 1])
|
67
|
+
assert_true(result.eval(record))
|
68
|
+
result = parser.scan(%q[integer != 0])
|
69
|
+
assert_true(result.eval(record))
|
70
|
+
result = parser.scan(%q[integer > 0])
|
71
|
+
assert_true(result.eval(record))
|
72
|
+
result = parser.scan(%q[integer >= 0])
|
73
|
+
assert_true(result.eval(record))
|
74
|
+
result = parser.scan(%q[integer < 2])
|
75
|
+
assert_true(result.eval(record))
|
76
|
+
result = parser.scan(%q[integer <= 2])
|
77
|
+
assert_true(result.eval(record))
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_string_op
|
81
|
+
result = parser.scan(%q[string = 'string'])
|
82
|
+
assert_true(result.eval(record))
|
83
|
+
result = parser.scan(%q[string != 'foobar'])
|
84
|
+
assert_true(result.eval(record))
|
85
|
+
result = parser.scan(%q[string start_with'str'])
|
86
|
+
assert_true(result.eval(record))
|
87
|
+
result = parser.scan(%q[string end_with 'ing'])
|
88
|
+
assert_true(result.eval(record))
|
89
|
+
result = parser.scan(%q[string include 'str'])
|
90
|
+
assert_true(result.eval(record))
|
91
|
+
result = parser.scan(%q[string regexp '.*str.*'])
|
92
|
+
assert_true(result.eval(record))
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_null_op
|
96
|
+
result = parser.scan(%q[nothing IS NULL])
|
97
|
+
result.eval(record)
|
98
|
+
assert_true(result.eval(record))
|
99
|
+
result = parser.scan(%q[string IS NOT NULL])
|
100
|
+
assert_true(result.eval(record))
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_logical_op
|
104
|
+
result = parser.scan(%q[boolean = true AND string = 'string'])
|
105
|
+
assert_true(result.eval(record))
|
106
|
+
result = parser.scan(%q[boolean = true OR string = 'foobar'])
|
107
|
+
assert_true(result.eval(record))
|
108
|
+
end
|
109
|
+
end
|
metadata
ADDED
@@ -0,0 +1,197 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fluent-plugin-filter_where
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Naotoshi Seo
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-05-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: fluentd
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: racc
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rexical
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry-nav
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: test-unit
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: test-unit-rr
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: timecop
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
description: Fluentd plugin to filter records with SQL-like WHERE statements
|
140
|
+
email: sonots@gmail.com
|
141
|
+
executables: []
|
142
|
+
extensions: []
|
143
|
+
extra_rdoc_files: []
|
144
|
+
files:
|
145
|
+
- ".gitignore"
|
146
|
+
- ".travis.yml"
|
147
|
+
- CHANGELOG.md
|
148
|
+
- Gemfile
|
149
|
+
- Gemfile.fluentd.0.12
|
150
|
+
- LICENSE
|
151
|
+
- README.md
|
152
|
+
- Rakefile
|
153
|
+
- example.conf
|
154
|
+
- fluent-plugin-filter_where.gemspec
|
155
|
+
- lib/fluent/plugin/filter_where.rb
|
156
|
+
- lib/fluent/plugin/filter_where/core.rb
|
157
|
+
- lib/fluent/plugin/filter_where/parser.racc
|
158
|
+
- lib/fluent/plugin/filter_where/parser.rex
|
159
|
+
- lib/fluent/plugin/filter_where/parser.rex.rb
|
160
|
+
- lib/fluent/plugin/filter_where/parser.tab.rb
|
161
|
+
- lib/fluent/plugin/filter_where/parser/exp.rb
|
162
|
+
- lib/fluent/plugin/filter_where/parser/literal.rb
|
163
|
+
- lib/fluent/plugin/filter_where/v12.rb
|
164
|
+
- lib/fluent/plugin/filter_where/v14.rb
|
165
|
+
- test/bench_filter_where.rb
|
166
|
+
- test/helper.rb
|
167
|
+
- test/test_filter_where.rb
|
168
|
+
- test/test_where_parser.rb
|
169
|
+
homepage: https://github.com/sonots/fluent-plugin-filter_where
|
170
|
+
licenses:
|
171
|
+
- MIT
|
172
|
+
metadata: {}
|
173
|
+
post_install_message:
|
174
|
+
rdoc_options: []
|
175
|
+
require_paths:
|
176
|
+
- lib
|
177
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
178
|
+
requirements:
|
179
|
+
- - ">="
|
180
|
+
- !ruby/object:Gem::Version
|
181
|
+
version: '0'
|
182
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
183
|
+
requirements:
|
184
|
+
- - ">="
|
185
|
+
- !ruby/object:Gem::Version
|
186
|
+
version: '0'
|
187
|
+
requirements: []
|
188
|
+
rubyforge_project:
|
189
|
+
rubygems_version: 2.6.11
|
190
|
+
signing_key:
|
191
|
+
specification_version: 4
|
192
|
+
summary: Fluentd plugin to filter records with SQL-like WHERE statements
|
193
|
+
test_files:
|
194
|
+
- test/bench_filter_where.rb
|
195
|
+
- test/helper.rb
|
196
|
+
- test/test_filter_where.rb
|
197
|
+
- test/test_where_parser.rb
|