msfl_visitors 0.3.0.dev5 → 0.3.0.dev6
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 +4 -4
- data/lib/msfl_visitors/visitor.rb +25 -7
- data/msfl_visitors.gemspec +2 -2
- data/spec/msfl_visitors_spec.rb +10 -10
- data/spec/visitors/chewy_term_filter_spec.rb +49 -41
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bf62249c0dac5ff2ae2537406f87989007141dbd
|
4
|
+
data.tar.gz: c98ec078a520735c4b64cefec4e04f6939f981fc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a2607260acd278637f603c69a7f1c520126da9dd6ad0e777b5670a3ee54c2d9de77109bf55f650be7cf987516fc1cd0bb75af1a0338225da240cb1cd1222a0f
|
7
|
+
data.tar.gz: 6cf9d405e4bf47acf71cac765d04590734b9c266bc679c25a62b6f4ca73dbe57101c5379aca338a607cf4e119cf932b6b047037aa1b734ea8ba20668450d04e7
|
@@ -15,7 +15,7 @@ module MSFLVisitors
|
|
15
15
|
case node
|
16
16
|
when Nodes::Partial
|
17
17
|
in_aggregation_mode do
|
18
|
-
clauses
|
18
|
+
clauses.concat get_visitor.visit(node)
|
19
19
|
""
|
20
20
|
end
|
21
21
|
else
|
@@ -120,10 +120,25 @@ module MSFLVisitors
|
|
120
120
|
def visit(node)
|
121
121
|
case node
|
122
122
|
when Nodes::Partial
|
123
|
-
{ given: Hash[[node.left.accept(visitor), node.right.accept(visitor)]] }
|
123
|
+
# { given: Hash[[node.left.accept(visitor), node.right.accept(visitor)]] }
|
124
|
+
|
125
|
+
# build the aggregate criteria clause first
|
126
|
+
# agg_criteria_clause = { clause: { agg_field_name: :portfolio_size, operator: :gt, test_value: 2 }, method_to_execute: :aggregations }
|
127
|
+
agg_criteria_clause = { clause: node.right.accept(visitor), method_to_execute: :aggregations }
|
128
|
+
# switch to the term filter mode
|
129
|
+
visitor.mode = :term
|
130
|
+
given_clause = { clause: node.left.accept(visitor) }
|
131
|
+
|
132
|
+
# switch back to the aggregations mode
|
133
|
+
visitor.mode = :aggregations
|
134
|
+
# return the result of the visitation
|
135
|
+
[agg_criteria_clause, given_clause]
|
136
|
+
|
137
|
+
|
124
138
|
|
125
139
|
when Nodes::Equal
|
126
|
-
{ term: { node.left.accept(visitor) => node.right.accept(visitor) } }
|
140
|
+
# { term: { node.left.accept(visitor) => node.right.accept(visitor) } }
|
141
|
+
{ agg_field_name: node.left.accept(visitor), operator: :eq, test_value: node.right.accept(visitor) }
|
127
142
|
# [{ clause: }]
|
128
143
|
when Nodes::Field
|
129
144
|
node.value.to_sym
|
@@ -138,13 +153,16 @@ module MSFLVisitors
|
|
138
153
|
Nodes::GreaterThanEqual,
|
139
154
|
Nodes::LessThan,
|
140
155
|
Nodes::LessThanEqual
|
141
|
-
{
|
156
|
+
{ agg_field_name: node.left.accept(visitor), operator: RANGE_OPERATORS[node.class], test_value: node.right.accept(visitor) }
|
157
|
+
# { range: { node.left.accept(visitor) => { RANGE_OPERATORS[node.class] => node.right.accept(visitor) } } }
|
142
158
|
when Nodes::Given
|
143
159
|
[:filter, node.contents.first.accept(visitor)]
|
144
160
|
when Nodes::ExplicitFilter
|
145
|
-
[:filter, node.contents.map { |n| n.accept(visitor) }.reduce({}) { |hsh, x| hsh.merge!(x); hsh } ]
|
161
|
+
# [:filter, node.contents.map { |n| n.accept(visitor) }.reduce({}) { |hsh, x| hsh.merge!(x); hsh } ]
|
162
|
+
node.contents.map { |n| n.accept(visitor) }
|
146
163
|
when Nodes::NamedValue
|
147
|
-
[:aggs, {node.name.accept(visitor).to_sym => Hash[[node.value.accept(visitor)]]}]
|
164
|
+
# [:aggs, {node.name.accept(visitor).to_sym => Hash[[node.value.accept(visitor)]]}]
|
165
|
+
node.value.accept(visitor)
|
148
166
|
when Nodes::Containment
|
149
167
|
{ terms: {node.left.accept(visitor).to_sym => node.right.accept(visitor)} }
|
150
168
|
when Nodes::Set
|
@@ -159,7 +177,7 @@ module MSFLVisitors
|
|
159
177
|
{ and: node.set.accept(visitor) }
|
160
178
|
|
161
179
|
when Nodes::Foreign
|
162
|
-
{
|
180
|
+
{ foreign: Hash[[[:type, node.left.accept(visitor)], [:filter, *node.right.accept(visitor)]]] }
|
163
181
|
|
164
182
|
else
|
165
183
|
fail ArgumentError, "AGGREGATIONS cannot visit: #{node.class.name}"
|
data/msfl_visitors.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'msfl_visitors'
|
3
|
-
s.version = '0.3.0.
|
4
|
-
s.date = '2015-05-
|
3
|
+
s.version = '0.3.0.dev6'
|
4
|
+
s.date = '2015-05-20'
|
5
5
|
s.summary = "Convert MSFL to other forms"
|
6
6
|
s.description = "Visitor pattern approach to converting MSFL to other forms."
|
7
7
|
s.authors = ["Courtland Caldwell"]
|
data/spec/msfl_visitors_spec.rb
CHANGED
@@ -39,19 +39,19 @@ describe MSFLVisitors do
|
|
39
39
|
|
40
40
|
let(:msfl) { { partial: { given: { make: "Toyota" }, filter: { avg_age: 10 } } } }
|
41
41
|
|
42
|
-
it "returns: [{:clause=>{
|
42
|
+
it "returns: [{:clause=>[{:agg_field_name=>:avg_age, :operator=>:eq, :test_value=>10}], :method_to_execute=>:aggregations}, {:clause=>\"make == \"Toyota\"\"}]" do
|
43
|
+
|
43
44
|
expect(subject).to eq [
|
44
45
|
{
|
45
|
-
clause:
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
}}}}},
|
46
|
+
clause: [
|
47
|
+
{
|
48
|
+
agg_field_name: :avg_age,
|
49
|
+
operator: :eq,
|
50
|
+
test_value: 10
|
51
|
+
}
|
52
|
+
],
|
53
53
|
method_to_execute: :aggregations
|
54
|
-
}
|
54
|
+
}, {clause: "make == \"Toyota\""}
|
55
55
|
]
|
56
56
|
end
|
57
57
|
end
|
@@ -72,21 +72,8 @@ describe MSFLVisitors::Visitor do
|
|
72
72
|
subject { visitor.visit_tree node }
|
73
73
|
|
74
74
|
let(:expected) do
|
75
|
-
[{
|
76
|
-
|
77
|
-
given: {
|
78
|
-
filter: {
|
79
|
-
term: { make: "Toyota" }
|
80
|
-
},
|
81
|
-
aggs: {
|
82
|
-
partial: {
|
83
|
-
filter: { range: { age: { gt: 10 }}}
|
84
|
-
}
|
85
|
-
}
|
86
|
-
}
|
87
|
-
},
|
88
|
-
method_to_execute: :aggregations
|
89
|
-
}]
|
75
|
+
[{ clause: [{ agg_field_name: :age, operator: :gt, test_value: 10 }], method_to_execute: :aggregations },
|
76
|
+
{ clause: "make == \"Toyota\"" }]
|
90
77
|
end
|
91
78
|
|
92
79
|
it "results in the appropriate aggregation clause" do
|
@@ -115,9 +102,9 @@ describe MSFLVisitors::Visitor do
|
|
115
102
|
let(:given_value_node) { MSFLVisitors::Nodes::Word.new "Toyota" }
|
116
103
|
|
117
104
|
|
118
|
-
it "results in: [:filter, {
|
105
|
+
it "results in: [:filter, { agg_field_name: :make, operator: :eq, test_value: \"Toyota\" }]" do
|
119
106
|
visitor.mode = :aggregations
|
120
|
-
expect(subject).to eq([:filter, {
|
107
|
+
expect(subject).to eq([:filter, { agg_field_name: :make, operator: :eq, test_value: "Toyota" }])
|
121
108
|
end
|
122
109
|
end
|
123
110
|
|
@@ -146,8 +133,8 @@ describe MSFLVisitors::Visitor do
|
|
146
133
|
|
147
134
|
before { visitor.mode = :aggregations }
|
148
135
|
|
149
|
-
it "results in: {
|
150
|
-
expect(subject).to eq({
|
136
|
+
it "results in: { foreign: { type: \"person\", filter: { agg_field_name: :age, operator: :eq, test_value: 25 } } }" do
|
137
|
+
expect(subject).to eq({ foreign: { type: "person", filter: { agg_field_name: :age, operator: :eq, test_value: 25 } } })
|
151
138
|
end
|
152
139
|
end
|
153
140
|
end
|
@@ -225,8 +212,8 @@ describe MSFLVisitors::Visitor do
|
|
225
212
|
|
226
213
|
before { visitor.mode = :aggregations }
|
227
214
|
|
228
|
-
it "results in: {
|
229
|
-
expect(result).to eq({
|
215
|
+
it "results in: { agg_field_name: :lhs, operator: :eq, test_value: \"rhs\" }" do
|
216
|
+
expect(result).to eq({ agg_field_name: :lhs, operator: :eq, test_value: "rhs" })
|
230
217
|
end
|
231
218
|
end
|
232
219
|
end
|
@@ -248,8 +235,8 @@ describe MSFLVisitors::Visitor do
|
|
248
235
|
|
249
236
|
before { visitor.mode = :aggregations }
|
250
237
|
|
251
|
-
it "results in: {
|
252
|
-
expect(result).to eq({
|
238
|
+
it "results in: { agg_field_name: :lhs, operator: :gt, test_value: 1000 }" do
|
239
|
+
expect(result).to eq({ agg_field_name: :lhs, operator: :gt, test_value: 1000 })
|
253
240
|
end
|
254
241
|
end
|
255
242
|
end
|
@@ -271,8 +258,8 @@ describe MSFLVisitors::Visitor do
|
|
271
258
|
|
272
259
|
before { visitor.mode = :aggregations }
|
273
260
|
|
274
|
-
it "results in: {
|
275
|
-
expect(result).to eq({
|
261
|
+
it "results in: { agg_field_name: :lhs, operator: :gte, test_value: 10.52 }" do
|
262
|
+
expect(result).to eq({ agg_field_name: :lhs, operator: :gte, test_value: 10.52 })
|
276
263
|
end
|
277
264
|
end
|
278
265
|
end
|
@@ -294,8 +281,8 @@ describe MSFLVisitors::Visitor do
|
|
294
281
|
|
295
282
|
before { visitor.mode = :aggregations }
|
296
283
|
|
297
|
-
it "returns: {
|
298
|
-
expect(result).to eq({
|
284
|
+
it "returns: { agg_field_name: :lhs, operator: :lt, test_value: 133.7 }" do
|
285
|
+
expect(result).to eq({ agg_field_name: :lhs, operator: :lt, test_value: 133.7 })
|
299
286
|
end
|
300
287
|
end
|
301
288
|
end
|
@@ -317,8 +304,8 @@ describe MSFLVisitors::Visitor do
|
|
317
304
|
|
318
305
|
before { visitor.mode = :aggregations }
|
319
306
|
|
320
|
-
it "returns: {
|
321
|
-
expect(result).to eq({
|
307
|
+
it "returns: { agg_field_name: :lhs, operator: :lte, test_value: \"#{Date.today}\"}" do
|
308
|
+
expect(result).to eq({ agg_field_name: :lhs, operator: :lte, test_value: "#{Date.today}"})
|
322
309
|
end
|
323
310
|
end
|
324
311
|
end
|
@@ -346,8 +333,8 @@ describe MSFLVisitors::Visitor do
|
|
346
333
|
|
347
334
|
before { visitor.mode = :aggregations }
|
348
335
|
|
349
|
-
it "returns: {
|
350
|
-
expect(result).to eq({
|
336
|
+
it "returns: { agg_field_name: :value, operator: :gte, test_value: 1000 }" do
|
337
|
+
expect(result).to eq({ agg_field_name: :value, operator: :gte, test_value: 1000 })
|
351
338
|
end
|
352
339
|
end
|
353
340
|
|
@@ -376,8 +363,12 @@ describe MSFLVisitors::Visitor do
|
|
376
363
|
|
377
364
|
before { visitor.mode = :aggregations }
|
378
365
|
|
379
|
-
it "returns: {
|
380
|
-
|
366
|
+
it "returns: {
|
367
|
+
and: [{ agg_field_name: :make, operator: :eq, test_value: \"Chevy\" },
|
368
|
+
{ agg_field_name: :value, operator: :gte, test_value: 1000 }]}" do
|
369
|
+
expect(result).to eq({
|
370
|
+
and: [{ agg_field_name: :make, operator: :eq, test_value: "Chevy" },
|
371
|
+
{ agg_field_name: :value, operator: :gte, test_value: 1000 }]})
|
381
372
|
end
|
382
373
|
end
|
383
374
|
end
|
@@ -441,8 +432,8 @@ describe MSFLVisitors::Visitor do
|
|
441
432
|
|
442
433
|
before { visitor.mode = :aggregations }
|
443
434
|
|
444
|
-
it "returns: { and: [{
|
445
|
-
expect(result).to eq({ and: [{
|
435
|
+
it "returns: { and: [{ agg_field_name: :first_field, operator: :eq, test_value: \"first_word\" }]}" do
|
436
|
+
expect(result).to eq({ and: [{ agg_field_name: :first_field, operator: :eq, test_value: "first_word" }]})
|
446
437
|
end
|
447
438
|
end
|
448
439
|
end
|
@@ -462,8 +453,14 @@ describe MSFLVisitors::Visitor do
|
|
462
453
|
|
463
454
|
before { visitor.mode = :aggregations }
|
464
455
|
|
465
|
-
it "returns: {
|
466
|
-
|
456
|
+
it "returns: {
|
457
|
+
and: [{ agg_field_name: :first_field, operator: :eq, test_value: \"first_word\" },
|
458
|
+
{ agg_field_name: :second_field, operator: :eq, test_value: \"second_word\" }
|
459
|
+
]}" do
|
460
|
+
expect(result).to eq({
|
461
|
+
and: [{ agg_field_name: :first_field, operator: :eq, test_value: "first_word" },
|
462
|
+
{ agg_field_name: :second_field, operator: :eq, test_value: "second_word" }
|
463
|
+
]})
|
467
464
|
end
|
468
465
|
end
|
469
466
|
end
|
@@ -483,8 +480,16 @@ describe MSFLVisitors::Visitor do
|
|
483
480
|
|
484
481
|
before { visitor.mode = :aggregations }
|
485
482
|
|
486
|
-
it "returns: {
|
487
|
-
|
483
|
+
it "returns: {
|
484
|
+
and: [{ agg_field_name: :first_field, operator: :eq, test_value: \"first_word\" },
|
485
|
+
{ agg_field_name: :second_field, operator: :eq, test_value: \"second_word\"},
|
486
|
+
{agg_field_name: :third_field, operator: :eq, test_value: \"third_word\"}
|
487
|
+
]}" do
|
488
|
+
expect(result).to eq({
|
489
|
+
and: [{ agg_field_name: :first_field, operator: :eq, test_value: "first_word" },
|
490
|
+
{ agg_field_name: :second_field, operator: :eq, test_value: "second_word"},
|
491
|
+
{agg_field_name: :third_field, operator: :eq, test_value: "third_word"}
|
492
|
+
]})
|
488
493
|
end
|
489
494
|
end
|
490
495
|
end
|
@@ -533,8 +538,11 @@ describe MSFLVisitors::Visitor do
|
|
533
538
|
|
534
539
|
before { visitor.mode = :aggregations }
|
535
540
|
|
536
|
-
it "returns: { and: [{ terms: { make: [\"Honda\",\"Chevy\",\"Volvo\"]} }, {
|
537
|
-
expected = { and: [
|
541
|
+
it "returns: { and: [{ terms: { make: [\"Honda\",\"Chevy\",\"Volvo\"]} }, { agg_field_name: :value, operator: :gte, test_value: 1000 } }] }" do
|
542
|
+
expected = { and: [
|
543
|
+
{ terms: { make: ["Honda", "Chevy", "Volvo"] } },
|
544
|
+
{ agg_field_name: :value, operator: :gte, test_value: 1000}
|
545
|
+
]}
|
538
546
|
expect(result).to eq expected
|
539
547
|
end
|
540
548
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: msfl_visitors
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.0.
|
4
|
+
version: 0.3.0.dev6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Courtland Caldwell
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-05-
|
11
|
+
date: 2015-05-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: msfl
|