hotdog 0.24.0 → 0.25.0
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/hotdog/commands.rb +19 -19
- data/lib/hotdog/commands/search.rb +4 -4
- data/lib/hotdog/commands/tags.rb +4 -4
- data/lib/hotdog/expression.rb +50 -50
- data/lib/hotdog/expression/semantics.rb +97 -93
- data/lib/hotdog/expression/syntax.rb +31 -31
- data/lib/hotdog/version.rb +1 -1
- data/spec/{parser → evaluator}/glob_expression_spec.rb +19 -14
- data/spec/{parser → evaluator}/regexp_expression_spec.rb +19 -14
- data/spec/{parser → evaluator}/string_expression_spec.rb +19 -14
- data/spec/optimizer/binary_expression_spec.rb +47 -0
- data/spec/optimizer/glob_expression_spec.rb +105 -0
- data/spec/optimizer/regexp_expression_spec.rb +55 -0
- data/spec/optimizer/string_expression_spec.rb +105 -0
- data/spec/optimizer/unary_expression_spec.rb +23 -0
- data/spec/parser/parser_spec.rb +82 -82
- metadata +18 -8
@@ -106,52 +106,52 @@ module Hotdog
|
|
106
106
|
)
|
107
107
|
}
|
108
108
|
rule(:tag) {
|
109
|
-
( regexp.as(:
|
110
|
-
| regexp.as(:
|
111
|
-
| regexp.as(:
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
| separator.as(:separator) >> regexp.as(:
|
121
|
-
| separator.as(:separator) >>
|
122
|
-
| separator.as(:separator) >>
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
)
|
127
|
-
}
|
128
|
-
rule(:
|
109
|
+
( regexp.as(:tagname_regexp) >> separator.as(:separator) >> regexp.as(:tagvalue_regexp) \
|
110
|
+
| regexp.as(:tagname_regexp) >> separator.as(:separator) \
|
111
|
+
| regexp.as(:tagname_regexp) \
|
112
|
+
| tagname_glob.as(:tagname_glob) >> separator.as(:separator) >> tagvalue_glob.as(:tagvalue_glob) \
|
113
|
+
| tagname_glob.as(:tagname_glob) >> separator.as(:separator) >> tagvalue.as(:tagvalue) \
|
114
|
+
| tagname_glob.as(:tagname_glob) >> separator.as(:separator) \
|
115
|
+
| tagname_glob.as(:tagname_glob) \
|
116
|
+
| tagname.as(:tagname) >> separator.as(:separator) >> tagvalue_glob.as(:tagvalue_glob) \
|
117
|
+
| tagname.as(:tagname) >> separator.as(:separator) >> tagvalue.as(:tagvalue) \
|
118
|
+
| tagname.as(:tagname) >> separator.as(:separator) \
|
119
|
+
| tagname.as(:tagname) \
|
120
|
+
| separator.as(:separator) >> regexp.as(:tagvalue_regexp) \
|
121
|
+
| separator.as(:separator) >> tagvalue_glob.as(:tagvalue_glob) \
|
122
|
+
| separator.as(:separator) >> tagvalue.as(:tagvalue) \
|
123
|
+
| tagvalue_regexp.as(:tagvalue_regexp) \
|
124
|
+
| tagvalue_glob.as(:tagvalue_glob) \
|
125
|
+
| tagvalue.as(:tagvalue) \
|
126
|
+
)
|
127
|
+
}
|
128
|
+
rule(:tagname_regexp) {
|
129
129
|
( regexp \
|
130
130
|
)
|
131
131
|
}
|
132
|
-
rule(:
|
132
|
+
rule(:tagvalue_regexp) {
|
133
133
|
( regexp \
|
134
134
|
)
|
135
135
|
}
|
136
|
-
rule(:
|
137
|
-
( binary_op.absent? >> unary_op.absent? >>
|
138
|
-
| binary_op >> (glob_char >>
|
139
|
-
| unary_op >> (glob_char >>
|
136
|
+
rule(:tagname_glob) {
|
137
|
+
( binary_op.absent? >> unary_op.absent? >> tagname.repeat(0) >> (glob_char >> tagname.maybe).repeat(1) \
|
138
|
+
| binary_op >> (glob_char >> tagname.maybe).repeat(1) \
|
139
|
+
| unary_op >> (glob_char >> tagname.maybe).repeat(1) \
|
140
140
|
)
|
141
141
|
}
|
142
|
-
rule(:
|
143
|
-
( binary_op.absent? >> unary_op.absent? >>
|
144
|
-
| binary_op >> (glob_char >>
|
145
|
-
| unary_op >> (glob_char >>
|
142
|
+
rule(:tagvalue_glob) {
|
143
|
+
( binary_op.absent? >> unary_op.absent? >> tagvalue.repeat(0) >> (glob_char >> tagvalue.maybe).repeat(1) \
|
144
|
+
| binary_op >> (glob_char >> tagvalue.maybe).repeat(1) \
|
145
|
+
| unary_op >> (glob_char >> tagvalue.maybe).repeat(1) \
|
146
146
|
)
|
147
147
|
}
|
148
|
-
rule(:
|
148
|
+
rule(:tagname) {
|
149
149
|
( binary_op.absent? >> unary_op.absent? >> match('[A-Z_a-z]') >> match('[-./0-9A-Z_a-z]').repeat(0) \
|
150
150
|
| binary_op >> match('[-./0-9A-Z_a-z]').repeat(1) \
|
151
151
|
| unary_op >> match('[-./0-9A-Z_a-z]').repeat(1) \
|
152
152
|
)
|
153
153
|
}
|
154
|
-
rule(:
|
154
|
+
rule(:tagvalue) {
|
155
155
|
( binary_op.absent? >> unary_op.absent? >> match('[-./0-9:A-Z_a-z]').repeat(1) \
|
156
156
|
| binary_op >> match('[-./0-9:A-Z_a-z]').repeat(1) \
|
157
157
|
| unary_op >> match('[-./0-9:A-Z_a-z]').repeat(1) \
|
data/lib/hotdog/version.rb
CHANGED
@@ -9,6 +9,11 @@ describe "tag glob expression" do
|
|
9
9
|
Hotdog::Commands::Search.new(Hotdog::Application.new)
|
10
10
|
}
|
11
11
|
|
12
|
+
before(:each) do
|
13
|
+
ENV["DATADOG_API_KEY"] = "DATADOG_API_KEY"
|
14
|
+
ENV["DATADOG_APPLICATION_KEY"] = "DATADOG_APPLICATION_KEY"
|
15
|
+
end
|
16
|
+
|
12
17
|
it "interprets tag glob with host" do
|
13
18
|
expr = Hotdog::Expression::GlobHostNode.new("foo*", ":")
|
14
19
|
q = [
|
@@ -19,10 +24,10 @@ describe "tag glob expression" do
|
|
19
24
|
[[1], [2], [3]]
|
20
25
|
}
|
21
26
|
expect(expr.evaluate(cmd)).to eq([1, 2, 3])
|
22
|
-
expect(expr.dump).to eq({
|
27
|
+
expect(expr.dump).to eq({tagname_glob: "host", separator: ":", tagvalue_glob: "foo*"})
|
23
28
|
end
|
24
29
|
|
25
|
-
it "interprets tag glob with
|
30
|
+
it "interprets tag glob with tagname and tagvalue" do
|
26
31
|
expr = Hotdog::Expression::GlobTagNode.new("foo*", "bar*", ":")
|
27
32
|
q = [
|
28
33
|
"SELECT DISTINCT hosts_tags.host_id FROM hosts_tags",
|
@@ -33,11 +38,11 @@ describe "tag glob expression" do
|
|
33
38
|
[[1], [2], [3]]
|
34
39
|
}
|
35
40
|
expect(expr.evaluate(cmd)).to eq([1, 2, 3])
|
36
|
-
expect(expr.dump).to eq({
|
41
|
+
expect(expr.dump).to eq({tagname_glob: "foo*", separator: ":", tagvalue_glob: "bar*"})
|
37
42
|
end
|
38
43
|
|
39
|
-
it "interprets tag glob with
|
40
|
-
expr = Hotdog::Expression::
|
44
|
+
it "interprets tag glob with tagname with separator" do
|
45
|
+
expr = Hotdog::Expression::GlobTagnameNode.new("foo*", ":")
|
41
46
|
q = [
|
42
47
|
"SELECT DISTINCT hosts_tags.host_id FROM hosts_tags",
|
43
48
|
"INNER JOIN tags ON hosts_tags.tag_id = tags.id",
|
@@ -47,10 +52,10 @@ describe "tag glob expression" do
|
|
47
52
|
[[1], [2], [3]]
|
48
53
|
}
|
49
54
|
expect(expr.evaluate(cmd)).to eq([1, 2, 3])
|
50
|
-
expect(expr.dump).to eq({
|
55
|
+
expect(expr.dump).to eq({tagname_glob: "foo*", separator: ":"})
|
51
56
|
end
|
52
57
|
|
53
|
-
it "interprets tag glob with
|
58
|
+
it "interprets tag glob with tagname without separator" do
|
54
59
|
expr = Hotdog::Expression::GlobHostOrTagNode.new("foo*", nil)
|
55
60
|
q = [
|
56
61
|
"SELECT DISTINCT hosts_tags.host_id FROM hosts_tags",
|
@@ -62,11 +67,11 @@ describe "tag glob expression" do
|
|
62
67
|
[[1], [2], [3]]
|
63
68
|
}
|
64
69
|
expect(expr.evaluate(cmd)).to eq([1, 2, 3])
|
65
|
-
expect(expr.dump).to eq({
|
70
|
+
expect(expr.dump).to eq({tagname_glob: "foo*"})
|
66
71
|
end
|
67
72
|
|
68
|
-
it "interprets tag glob with
|
69
|
-
expr = Hotdog::Expression::
|
73
|
+
it "interprets tag glob with tagvalue with separator" do
|
74
|
+
expr = Hotdog::Expression::GlobTagvalueNode.new("foo*", ":")
|
70
75
|
q = [
|
71
76
|
"SELECT DISTINCT hosts_tags.host_id FROM hosts_tags",
|
72
77
|
"INNER JOIN hosts ON hosts_tags.host_id = hosts.id",
|
@@ -77,11 +82,11 @@ describe "tag glob expression" do
|
|
77
82
|
[[1], [2], [3]]
|
78
83
|
}
|
79
84
|
expect(expr.evaluate(cmd)).to eq([1, 2, 3])
|
80
|
-
expect(expr.dump).to eq({separator: ":",
|
85
|
+
expect(expr.dump).to eq({separator: ":", tagvalue_glob: "foo*"})
|
81
86
|
end
|
82
87
|
|
83
|
-
it "interprets tag glob with
|
84
|
-
expr = Hotdog::Expression::
|
88
|
+
it "interprets tag glob with tagvalue without separator" do
|
89
|
+
expr = Hotdog::Expression::GlobTagvalueNode.new("foo*", nil)
|
85
90
|
q = [
|
86
91
|
"SELECT DISTINCT hosts_tags.host_id FROM hosts_tags",
|
87
92
|
"INNER JOIN hosts ON hosts_tags.host_id = hosts.id",
|
@@ -92,7 +97,7 @@ describe "tag glob expression" do
|
|
92
97
|
[[1], [2], [3]]
|
93
98
|
}
|
94
99
|
expect(expr.evaluate(cmd)).to eq([1, 2, 3])
|
95
|
-
expect(expr.dump).to eq({
|
100
|
+
expect(expr.dump).to eq({tagvalue_glob: "foo*"})
|
96
101
|
end
|
97
102
|
|
98
103
|
it "empty tag glob" do
|
@@ -9,6 +9,11 @@ describe "tag regexp expression" do
|
|
9
9
|
Hotdog::Commands::Search.new(Hotdog::Application.new)
|
10
10
|
}
|
11
11
|
|
12
|
+
before(:each) do
|
13
|
+
ENV["DATADOG_API_KEY"] = "DATADOG_API_KEY"
|
14
|
+
ENV["DATADOG_APPLICATION_KEY"] = "DATADOG_APPLICATION_KEY"
|
15
|
+
end
|
16
|
+
|
12
17
|
it "interprets tag regexp with host" do
|
13
18
|
expr = Hotdog::Expression::RegexpHostNode.new("foo", ":")
|
14
19
|
q = [
|
@@ -19,10 +24,10 @@ describe "tag regexp expression" do
|
|
19
24
|
[[1], [2], [3]]
|
20
25
|
}
|
21
26
|
expect(expr.evaluate(cmd)).to eq([1, 2, 3])
|
22
|
-
expect(expr.dump).to eq({
|
27
|
+
expect(expr.dump).to eq({tagname_regexp: "host", separator: ":", tagvalue_regexp: "foo"})
|
23
28
|
end
|
24
29
|
|
25
|
-
it "interprets tag regexp with
|
30
|
+
it "interprets tag regexp with tagname and tagvalue" do
|
26
31
|
expr = Hotdog::Expression::RegexpTagNode.new("foo", "bar", ":")
|
27
32
|
q = [
|
28
33
|
"SELECT DISTINCT hosts_tags.host_id FROM hosts_tags",
|
@@ -33,11 +38,11 @@ describe "tag regexp expression" do
|
|
33
38
|
[[1], [2], [3]]
|
34
39
|
}
|
35
40
|
expect(expr.evaluate(cmd)).to eq([1, 2, 3])
|
36
|
-
expect(expr.dump).to eq({
|
41
|
+
expect(expr.dump).to eq({tagname_regexp: "foo", separator: ":", tagvalue_regexp: "bar"})
|
37
42
|
end
|
38
43
|
|
39
|
-
it "interprets tag regexp with
|
40
|
-
expr = Hotdog::Expression::
|
44
|
+
it "interprets tag regexp with tagname with separator" do
|
45
|
+
expr = Hotdog::Expression::RegexpTagnameNode.new("foo", ":")
|
41
46
|
q = [
|
42
47
|
"SELECT DISTINCT hosts_tags.host_id FROM hosts_tags",
|
43
48
|
"INNER JOIN tags ON hosts_tags.tag_id = tags.id",
|
@@ -47,10 +52,10 @@ describe "tag regexp expression" do
|
|
47
52
|
[[1], [2], [3]]
|
48
53
|
}
|
49
54
|
expect(expr.evaluate(cmd)).to eq([1, 2, 3])
|
50
|
-
expect(expr.dump).to eq({
|
55
|
+
expect(expr.dump).to eq({tagname_regexp: "foo", separator: ":"})
|
51
56
|
end
|
52
57
|
|
53
|
-
it "interprets tag regexp with
|
58
|
+
it "interprets tag regexp with tagname without separator" do
|
54
59
|
expr = Hotdog::Expression::RegexpHostOrTagNode.new("foo", nil)
|
55
60
|
q = [
|
56
61
|
"SELECT DISTINCT hosts_tags.host_id FROM hosts_tags",
|
@@ -62,11 +67,11 @@ describe "tag regexp expression" do
|
|
62
67
|
[[1], [2], [3]]
|
63
68
|
}
|
64
69
|
expect(expr.evaluate(cmd)).to eq([1, 2, 3])
|
65
|
-
expect(expr.dump).to eq({
|
70
|
+
expect(expr.dump).to eq({tagname_regexp: "foo"})
|
66
71
|
end
|
67
72
|
|
68
|
-
it "interprets tag regexp with
|
69
|
-
expr = Hotdog::Expression::
|
73
|
+
it "interprets tag regexp with tagvalue with separator" do
|
74
|
+
expr = Hotdog::Expression::RegexpTagvalueNode.new("foo", ":")
|
70
75
|
q = [
|
71
76
|
"SELECT DISTINCT hosts_tags.host_id FROM hosts_tags",
|
72
77
|
"INNER JOIN hosts ON hosts_tags.host_id = hosts.id",
|
@@ -77,11 +82,11 @@ describe "tag regexp expression" do
|
|
77
82
|
[[1], [2], [3]]
|
78
83
|
}
|
79
84
|
expect(expr.evaluate(cmd)).to eq([1, 2, 3])
|
80
|
-
expect(expr.dump).to eq({separator: ":",
|
85
|
+
expect(expr.dump).to eq({separator: ":", tagvalue_regexp: "foo"})
|
81
86
|
end
|
82
87
|
|
83
|
-
it "interprets tag regexp with
|
84
|
-
expr = Hotdog::Expression::
|
88
|
+
it "interprets tag regexp with tagvalue without separator" do
|
89
|
+
expr = Hotdog::Expression::RegexpTagvalueNode.new("foo", nil)
|
85
90
|
q = [
|
86
91
|
"SELECT DISTINCT hosts_tags.host_id FROM hosts_tags",
|
87
92
|
"INNER JOIN hosts ON hosts_tags.host_id = hosts.id",
|
@@ -92,7 +97,7 @@ describe "tag regexp expression" do
|
|
92
97
|
[[1], [2], [3]]
|
93
98
|
}
|
94
99
|
expect(expr.evaluate(cmd)).to eq([1, 2, 3])
|
95
|
-
expect(expr.dump).to eq({
|
100
|
+
expect(expr.dump).to eq({tagvalue_regexp: "foo"})
|
96
101
|
end
|
97
102
|
|
98
103
|
it "empty tag regexp" do
|
@@ -9,6 +9,11 @@ describe "tag expression" do
|
|
9
9
|
Hotdog::Commands::Search.new(Hotdog::Application.new)
|
10
10
|
}
|
11
11
|
|
12
|
+
before(:each) do
|
13
|
+
ENV["DATADOG_API_KEY"] = "DATADOG_API_KEY"
|
14
|
+
ENV["DATADOG_APPLICATION_KEY"] = "DATADOG_APPLICATION_KEY"
|
15
|
+
end
|
16
|
+
|
12
17
|
it "interprets tag with host" do
|
13
18
|
expr = Hotdog::Expression::StringHostNode.new("foo", ":")
|
14
19
|
q = [
|
@@ -19,10 +24,10 @@ describe "tag expression" do
|
|
19
24
|
[[1], [2], [3]]
|
20
25
|
}
|
21
26
|
expect(expr.evaluate(cmd)).to eq([1, 2, 3])
|
22
|
-
expect(expr.dump).to eq({
|
27
|
+
expect(expr.dump).to eq({tagname: "host", separator: ":", tagvalue: "foo"})
|
23
28
|
end
|
24
29
|
|
25
|
-
it "interprets tag with
|
30
|
+
it "interprets tag with tagname and tagvalue" do
|
26
31
|
expr = Hotdog::Expression::StringTagNode.new("foo", "bar", ":")
|
27
32
|
q = [
|
28
33
|
"SELECT DISTINCT hosts_tags.host_id FROM hosts_tags",
|
@@ -33,11 +38,11 @@ describe "tag expression" do
|
|
33
38
|
[[1], [2], [3]]
|
34
39
|
}
|
35
40
|
expect(expr.evaluate(cmd)).to eq([1, 2, 3])
|
36
|
-
expect(expr.dump).to eq({
|
41
|
+
expect(expr.dump).to eq({tagname: "foo", separator: ":", tagvalue: "bar"})
|
37
42
|
end
|
38
43
|
|
39
|
-
it "interprets tag with
|
40
|
-
expr = Hotdog::Expression::
|
44
|
+
it "interprets tag with tagname with separator" do
|
45
|
+
expr = Hotdog::Expression::StringTagnameNode.new("foo", ":")
|
41
46
|
q = [
|
42
47
|
"SELECT DISTINCT hosts_tags.host_id FROM hosts_tags",
|
43
48
|
"INNER JOIN tags ON hosts_tags.tag_id = tags.id",
|
@@ -47,10 +52,10 @@ describe "tag expression" do
|
|
47
52
|
[[1], [2], [3]]
|
48
53
|
}
|
49
54
|
expect(expr.evaluate(cmd)).to eq([1, 2, 3])
|
50
|
-
expect(expr.dump).to eq({
|
55
|
+
expect(expr.dump).to eq({tagname: "foo", separator: ":"})
|
51
56
|
end
|
52
57
|
|
53
|
-
it "interprets tag with
|
58
|
+
it "interprets tag with tagname without separator" do
|
54
59
|
expr = Hotdog::Expression::StringHostOrTagNode.new("foo", nil)
|
55
60
|
q = [
|
56
61
|
"SELECT DISTINCT hosts_tags.host_id FROM hosts_tags",
|
@@ -62,11 +67,11 @@ describe "tag expression" do
|
|
62
67
|
[[1], [2], [3]]
|
63
68
|
}
|
64
69
|
expect(expr.evaluate(cmd)).to eq([1, 2, 3])
|
65
|
-
expect(expr.dump).to eq({
|
70
|
+
expect(expr.dump).to eq({tagname: "foo"})
|
66
71
|
end
|
67
72
|
|
68
|
-
it "interprets tag with
|
69
|
-
expr = Hotdog::Expression::
|
73
|
+
it "interprets tag with tagvalue with separator" do
|
74
|
+
expr = Hotdog::Expression::StringTagvalueNode.new("foo", ":")
|
70
75
|
q = [
|
71
76
|
"SELECT DISTINCT hosts_tags.host_id FROM hosts_tags",
|
72
77
|
"INNER JOIN hosts ON hosts_tags.host_id = hosts.id",
|
@@ -77,11 +82,11 @@ describe "tag expression" do
|
|
77
82
|
[[1], [2], [3]]
|
78
83
|
}
|
79
84
|
expect(expr.evaluate(cmd)).to eq([1, 2, 3])
|
80
|
-
expect(expr.dump).to eq({separator: ":",
|
85
|
+
expect(expr.dump).to eq({separator: ":", tagvalue: "foo"})
|
81
86
|
end
|
82
87
|
|
83
|
-
it "interprets tag with
|
84
|
-
expr = Hotdog::Expression::
|
88
|
+
it "interprets tag with tagvalue without separator" do
|
89
|
+
expr = Hotdog::Expression::StringTagvalueNode.new("foo", nil)
|
85
90
|
q = [
|
86
91
|
"SELECT DISTINCT hosts_tags.host_id FROM hosts_tags",
|
87
92
|
"INNER JOIN hosts ON hosts_tags.host_id = hosts.id",
|
@@ -92,7 +97,7 @@ describe "tag expression" do
|
|
92
97
|
[[1], [2], [3]]
|
93
98
|
}
|
94
99
|
expect(expr.evaluate(cmd)).to eq([1, 2, 3])
|
95
|
-
expect(expr.dump).to eq({
|
100
|
+
expect(expr.dump).to eq({tagvalue: "foo"})
|
96
101
|
end
|
97
102
|
|
98
103
|
it "empty tag" do
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "hotdog/application"
|
3
|
+
require "hotdog/commands"
|
4
|
+
require "hotdog/commands/search"
|
5
|
+
require "parslet"
|
6
|
+
|
7
|
+
describe "binary expression" do
|
8
|
+
it "everything AND x should return x" do
|
9
|
+
expr = Hotdog::Expression::BinaryExpressionNode.new("AND", Hotdog::Expression::EverythingNode.new(), Hotdog::Expression::NothingNode.new())
|
10
|
+
expect(expr.optimize.dump).to eq({
|
11
|
+
query: "SELECT NULL AS host_id WHERE host_id NOT NULL;",
|
12
|
+
values: [],
|
13
|
+
})
|
14
|
+
end
|
15
|
+
|
16
|
+
it "nothing AND x should return nothing" do
|
17
|
+
expr = Hotdog::Expression::BinaryExpressionNode.new("AND", Hotdog::Expression::NothingNode.new(), Hotdog::Expression::EverythingNode.new())
|
18
|
+
expect(expr.optimize.dump).to eq({
|
19
|
+
query: "SELECT NULL AS host_id WHERE host_id NOT NULL;",
|
20
|
+
values: [],
|
21
|
+
})
|
22
|
+
end
|
23
|
+
|
24
|
+
it "everything OR x should return everything" do
|
25
|
+
expr = Hotdog::Expression::BinaryExpressionNode.new("OR", Hotdog::Expression::EverythingNode.new(), Hotdog::Expression::NothingNode.new())
|
26
|
+
expect(expr.optimize.dump).to eq({
|
27
|
+
query: "SELECT id AS host_id FROM hosts;",
|
28
|
+
values: [],
|
29
|
+
})
|
30
|
+
end
|
31
|
+
|
32
|
+
it "nothing OR x should return x" do
|
33
|
+
expr = Hotdog::Expression::BinaryExpressionNode.new("OR", Hotdog::Expression::NothingNode.new(), Hotdog::Expression::EverythingNode.new())
|
34
|
+
expect(expr.optimize.dump).to eq({
|
35
|
+
query: "SELECT id AS host_id FROM hosts;",
|
36
|
+
values: [],
|
37
|
+
})
|
38
|
+
end
|
39
|
+
|
40
|
+
it "everything XOR everything should return nothing" do
|
41
|
+
expr = Hotdog::Expression::BinaryExpressionNode.new("XOR", Hotdog::Expression::EverythingNode.new(), Hotdog::Expression::EverythingNode.new())
|
42
|
+
expect(expr.optimize.dump).to eq({
|
43
|
+
query: "SELECT NULL AS host_id WHERE host_id NOT NULL;",
|
44
|
+
values: [],
|
45
|
+
})
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "hotdog/application"
|
3
|
+
require "hotdog/commands"
|
4
|
+
require "hotdog/commands/search"
|
5
|
+
require "parslet"
|
6
|
+
|
7
|
+
describe "tag glob expression" do
|
8
|
+
it "interprets tag glob with host" do
|
9
|
+
expr = Hotdog::Expression::GlobHostNode.new("foo*", ":")
|
10
|
+
expect(expr.optimize.dump).to eq({
|
11
|
+
tagname_glob: "host",
|
12
|
+
separator: ":",
|
13
|
+
tagvalue_glob: "foo*",
|
14
|
+
fallback: {
|
15
|
+
query: [
|
16
|
+
"SELECT hosts.id AS host_id FROM hosts",
|
17
|
+
"WHERE LOWER(hosts.name) GLOB LOWER(?);",
|
18
|
+
].join(" "),
|
19
|
+
values: ["*foo*"],
|
20
|
+
},
|
21
|
+
})
|
22
|
+
end
|
23
|
+
|
24
|
+
it "interprets tag glob with tagname and tagvalue" do
|
25
|
+
expr = Hotdog::Expression::GlobTagNode.new("foo*", "bar*", ":")
|
26
|
+
expect(expr.optimize.dump).to eq({
|
27
|
+
tagname_glob: "foo*",
|
28
|
+
separator: ":",
|
29
|
+
tagvalue_glob: "bar*",
|
30
|
+
fallback: {
|
31
|
+
query: [
|
32
|
+
"SELECT DISTINCT hosts_tags.host_id FROM hosts_tags",
|
33
|
+
"INNER JOIN tags ON hosts_tags.tag_id = tags.id",
|
34
|
+
"WHERE LOWER(tags.name) GLOB LOWER(?) AND LOWER(tags.value) GLOB LOWER(?);",
|
35
|
+
].join(" "),
|
36
|
+
values: ["*foo*", "*bar*"],
|
37
|
+
},
|
38
|
+
})
|
39
|
+
end
|
40
|
+
|
41
|
+
it "interprets tag glob with tagname with separator" do
|
42
|
+
expr = Hotdog::Expression::GlobTagnameNode.new("foo*", ":")
|
43
|
+
expect(expr.optimize.dump).to eq({
|
44
|
+
tagname_glob: "foo*",
|
45
|
+
separator: ":",
|
46
|
+
fallback: {
|
47
|
+
query: [
|
48
|
+
"SELECT DISTINCT hosts_tags.host_id FROM hosts_tags",
|
49
|
+
"INNER JOIN tags ON hosts_tags.tag_id = tags.id",
|
50
|
+
"WHERE LOWER(tags.name) GLOB LOWER(?);",
|
51
|
+
].join(" "),
|
52
|
+
values: ["*foo*"],
|
53
|
+
},
|
54
|
+
})
|
55
|
+
end
|
56
|
+
|
57
|
+
it "interprets tag glob with tagname without separator" do
|
58
|
+
expr = Hotdog::Expression::GlobHostOrTagNode.new("foo*", nil)
|
59
|
+
expect(expr.optimize.dump).to eq({
|
60
|
+
tagname_glob: "foo*",
|
61
|
+
fallback: {
|
62
|
+
query: [
|
63
|
+
"SELECT DISTINCT hosts_tags.host_id FROM hosts_tags",
|
64
|
+
"INNER JOIN hosts ON hosts_tags.host_id = hosts.id",
|
65
|
+
"INNER JOIN tags ON hosts_tags.tag_id = tags.id",
|
66
|
+
"WHERE LOWER(hosts.name) GLOB LOWER(?) OR LOWER(tags.name) GLOB LOWER(?) OR LOWER(tags.value) GLOB LOWER(?);",
|
67
|
+
].join(" "),
|
68
|
+
values: ["*foo*", "*foo*", "*foo*"],
|
69
|
+
},
|
70
|
+
})
|
71
|
+
end
|
72
|
+
|
73
|
+
it "interprets tag glob with tagvalue with separator" do
|
74
|
+
expr = Hotdog::Expression::GlobTagvalueNode.new("foo*", ":")
|
75
|
+
expect(expr.optimize.dump).to eq({
|
76
|
+
separator: ":",
|
77
|
+
tagvalue_glob: "foo*",
|
78
|
+
fallback: {
|
79
|
+
query: [
|
80
|
+
"SELECT DISTINCT hosts_tags.host_id FROM hosts_tags",
|
81
|
+
"INNER JOIN hosts ON hosts_tags.host_id = hosts.id",
|
82
|
+
"INNER JOIN tags ON hosts_tags.tag_id = tags.id",
|
83
|
+
"WHERE LOWER(hosts.name) GLOB LOWER(?) OR LOWER(tags.value) GLOB LOWER(?);",
|
84
|
+
].join(" "),
|
85
|
+
values: ["*foo*", "*foo*"],
|
86
|
+
},
|
87
|
+
})
|
88
|
+
end
|
89
|
+
|
90
|
+
it "interprets tag glob with tagvalue without separator" do
|
91
|
+
expr = Hotdog::Expression::GlobTagvalueNode.new("foo*", nil)
|
92
|
+
expect(expr.optimize.dump).to eq({
|
93
|
+
tagvalue_glob: "foo*",
|
94
|
+
fallback: {
|
95
|
+
query: [
|
96
|
+
"SELECT DISTINCT hosts_tags.host_id FROM hosts_tags",
|
97
|
+
"INNER JOIN hosts ON hosts_tags.host_id = hosts.id",
|
98
|
+
"INNER JOIN tags ON hosts_tags.tag_id = tags.id",
|
99
|
+
"WHERE LOWER(hosts.name) GLOB LOWER(?) OR LOWER(tags.value) GLOB LOWER(?);",
|
100
|
+
].join(" "),
|
101
|
+
values: ["*foo*", "*foo*"],
|
102
|
+
}
|
103
|
+
})
|
104
|
+
end
|
105
|
+
end
|