influxdb-arel 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +22 -0
  3. data/.rspec +3 -0
  4. data/.travis.yml +8 -0
  5. data/Gemfile +6 -0
  6. data/LICENSE.txt +22 -0
  7. data/README.md +350 -0
  8. data/Rakefile +6 -0
  9. data/influxdb-arel.gemspec +24 -0
  10. data/lib/influxdb-arel.rb +1 -0
  11. data/lib/influxdb.rb +4 -0
  12. data/lib/influxdb/arel.rb +38 -0
  13. data/lib/influxdb/arel/alias_predication.rb +9 -0
  14. data/lib/influxdb/arel/attributes.rb +1 -0
  15. data/lib/influxdb/arel/attributes/attribute.rb +74 -0
  16. data/lib/influxdb/arel/core_extensions.rb +49 -0
  17. data/lib/influxdb/arel/expressions.rb +73 -0
  18. data/lib/influxdb/arel/math.rb +21 -0
  19. data/lib/influxdb/arel/nodes.rb +27 -0
  20. data/lib/influxdb/arel/nodes/and.rb +32 -0
  21. data/lib/influxdb/arel/nodes/binary.rb +47 -0
  22. data/lib/influxdb/arel/nodes/duration.rb +30 -0
  23. data/lib/influxdb/arel/nodes/equality.rb +11 -0
  24. data/lib/influxdb/arel/nodes/function.rb +47 -0
  25. data/lib/influxdb/arel/nodes/grouping.rb +11 -0
  26. data/lib/influxdb/arel/nodes/in.rb +8 -0
  27. data/lib/influxdb/arel/nodes/infix_operation.rb +51 -0
  28. data/lib/influxdb/arel/nodes/node.rb +19 -0
  29. data/lib/influxdb/arel/nodes/now.rb +15 -0
  30. data/lib/influxdb/arel/nodes/select_statement.rb +59 -0
  31. data/lib/influxdb/arel/nodes/sql_literal.rb +23 -0
  32. data/lib/influxdb/arel/nodes/table_alias.rb +23 -0
  33. data/lib/influxdb/arel/nodes/time.rb +13 -0
  34. data/lib/influxdb/arel/nodes/unary.rb +35 -0
  35. data/lib/influxdb/arel/predications.rb +137 -0
  36. data/lib/influxdb/arel/select_manager.rb +129 -0
  37. data/lib/influxdb/arel/table.rb +219 -0
  38. data/lib/influxdb/arel/tree_manager.rb +30 -0
  39. data/lib/influxdb/arel/version.rb +5 -0
  40. data/lib/influxdb/arel/visitor.rb +287 -0
  41. data/spec/lib/influxdb/arel/core_extensions_spec.rb +49 -0
  42. data/spec/lib/influxdb/arel/nodes/and_spec.rb +17 -0
  43. data/spec/lib/influxdb/arel/nodes/binary_spec.rb +49 -0
  44. data/spec/lib/influxdb/arel/nodes/duration_spec.rb +72 -0
  45. data/spec/lib/influxdb/arel/nodes/equality_spec.rb +5 -0
  46. data/spec/lib/influxdb/arel/nodes/function_spec.rb +69 -0
  47. data/spec/lib/influxdb/arel/nodes/grouping_spec.rb +10 -0
  48. data/spec/lib/influxdb/arel/nodes/in_spec.rb +13 -0
  49. data/spec/lib/influxdb/arel/nodes/now_spec.rb +8 -0
  50. data/spec/lib/influxdb/arel/nodes/sql_literal_spec.rb +28 -0
  51. data/spec/lib/influxdb/arel/nodes/table_alias_spec.rb +36 -0
  52. data/spec/lib/influxdb/arel/nodes/time_spec.rb +5 -0
  53. data/spec/lib/influxdb/arel/nodes/unary_spec.rb +25 -0
  54. data/spec/lib/influxdb/arel/select_manager_spec.rb +459 -0
  55. data/spec/lib/influxdb/arel/table_spec.rb +193 -0
  56. data/spec/lib/influxdb/arel_spec.rb +11 -0
  57. data/spec/spec_helper.rb +20 -0
  58. data/spec/support/examples/binary_node.rb +10 -0
  59. data/spec/support/examples/function_node.rb +14 -0
  60. data/spec/support/examples/node_as.rb +8 -0
  61. data/spec/support/examples/node_expressions.rb +145 -0
  62. data/spec/support/examples/node_math.rb +29 -0
  63. data/spec/support/examples/node_predications.rb +248 -0
  64. data/spec/support/examples/node_to_sql.rb +5 -0
  65. data/spec/support/examples/unary_node.rb +10 -0
  66. data/spec/support/fabrics.rb +21 -0
  67. metadata +177 -0
@@ -0,0 +1,193 @@
1
+ require 'spec_helper'
2
+
3
+ describe Influxdb::Arel::Table do
4
+ describe '#sql' do
5
+ specify{ expect(table('events').sql('time(1s)')).to eq(sql('time(1s)')) }
6
+ end
7
+
8
+ describe '#star' do
9
+ specify{ expect(table('events').star).to eq(sql('*')) }
10
+ end
11
+
12
+ describe '#alias' do
13
+ subject{ table('events').alias('events1') }
14
+ specify{ expect(subject).to eq(node(:TableAlias, table('events'), 'events1')) }
15
+ specify{ expect(subject.to_sql).to eq('events AS events1') }
16
+ end
17
+
18
+ describe '#from' do
19
+ subject{ table('events').from('table') }
20
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
21
+ specify{ expect(subject.ast.series).to eq([sql('table')]) }
22
+ specify{ expect(subject.to_sql).to eq('SELECT * FROM table') }
23
+ end
24
+
25
+ describe '#merge' do
26
+ subject{ table('events').merge('errors') }
27
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
28
+ specify{ expect(subject.ast.merge).to eq(node(:Merge, table('events'), sql('errors'))) }
29
+ specify{ expect(subject.to_sql).to eq('SELECT * FROM events MERGE errors') }
30
+
31
+ context 'when table as argument' do
32
+ subject{ table('events').merge(table('errors')) }
33
+
34
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
35
+ specify{ expect(subject.ast.merge).to eq(node(:Merge, table('events'), table('errors'))) }
36
+ specify{ expect(subject.to_sql).to eq('SELECT * FROM events MERGE errors') }
37
+ end
38
+
39
+ context 'when alias as argument' do
40
+ let(:table_alias){ table('errors').as('fatal_errors') }
41
+
42
+ subject{ table('events').merge(table_alias) }
43
+
44
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
45
+ specify{ expect(subject.ast.merge).to eq(node(:Merge, table('events'), table('errors'))) }
46
+ specify{ expect(subject.to_sql).to eq('SELECT * FROM events MERGE errors') }
47
+ end
48
+
49
+ context 'without argument' do
50
+ subject{ table('events').merge }
51
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
52
+ specify{ expect(subject.ast.merge).to be_nil }
53
+ specify{ expect(subject.to_sql).to eq('SELECT * FROM events') }
54
+ end
55
+
56
+ context 'without argument with many series' do
57
+ subject{ table('events').from('user_events', 'errors').merge }
58
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
59
+ specify{ expect(subject.ast.merge).to eq(node(:Merge, sql('user_events'), sql('errors'))) }
60
+ specify{ expect(subject.to_sql).to eq('SELECT * FROM user_events MERGE errors') }
61
+ end
62
+ end
63
+
64
+ describe '#join' do
65
+ subject{ table('events').join('errors') }
66
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
67
+ specify{ expect(subject.ast.join).to eq(node(:Join, table('events'), sql('errors'))) }
68
+ specify{ expect(subject.to_sql).to eq('SELECT * FROM events INNER JOIN errors') }
69
+
70
+ context 'when table as argument' do
71
+ subject{ table('events').join(table('errors')) }
72
+
73
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
74
+ specify{ expect(subject.ast.join).to eq(node(:Join, table('events'), table('errors'))) }
75
+ specify{ expect(subject.to_sql).to eq('SELECT * FROM events INNER JOIN errors') }
76
+ end
77
+
78
+ context 'when alias as argument' do
79
+ let(:table_alias){ table('errors').as('fatal_errors') }
80
+
81
+ subject{ table('events').join(table_alias) }
82
+
83
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
84
+ specify{ expect(subject.ast.join).to eq(node(:Join, table('events'), table_alias)) }
85
+ specify{ expect(subject.to_sql).to eq('SELECT * FROM events INNER JOIN errors AS fatal_errors') }
86
+ end
87
+
88
+ context 'without argument' do
89
+ subject{ table('events').join }
90
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
91
+ specify{ expect(subject.ast.join).to be_nil }
92
+ specify{ expect(subject.to_sql).to eq('SELECT * FROM events') }
93
+ end
94
+
95
+ context 'without argument with many series' do
96
+ subject{ table('events').from('user_events', 'errors').join }
97
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
98
+ specify{ expect(subject.ast.join).to eq(node(:Join, sql('user_events'), sql('errors'))) }
99
+ specify{ expect(subject.to_sql).to eq('SELECT * FROM user_events INNER JOIN errors') }
100
+ end
101
+ end
102
+
103
+ describe '#order' do
104
+ context 'when sort by ascending order' do
105
+ subject{ table('events').order(:asc) }
106
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
107
+ specify{ expect(subject.ordering).to eq(node(:Ordering, 'asc')) }
108
+ specify{ expect(subject.to_sql).to eq('SELECT * FROM events ORDER ASC') }
109
+ end
110
+
111
+ context 'when sort by ascending order' do
112
+ subject{ table('events').order('asc') }
113
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
114
+ specify{ expect(subject.ordering).to eq(node(:Ordering, 'asc')) }
115
+ specify{ expect(subject.to_sql).to eq('SELECT * FROM events ORDER ASC') }
116
+ end
117
+
118
+ context 'when sort by descending order' do
119
+ subject{ table('events').order(:desc) }
120
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
121
+ specify{ expect(subject.ordering).to eq(node(:Ordering, 'desc')) }
122
+ specify{ expect(subject.to_sql).to eq('SELECT * FROM events ORDER DESC') }
123
+ end
124
+
125
+ context 'when sort by descending order' do
126
+ subject{ table('events').order('desc') }
127
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
128
+ specify{ expect(subject.ordering).to eq(node(:Ordering, 'desc')) }
129
+ specify{ expect(subject.to_sql).to eq('SELECT * FROM events ORDER DESC') }
130
+ end
131
+ end
132
+
133
+ describe '#take' do
134
+ subject{ table('events').take(100) }
135
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
136
+ specify{ expect(subject.taken).to eq(node(:Limit, 100)) }
137
+ specify{ expect(subject.to_sql).to eq('SELECT * FROM events LIMIT 100') }
138
+ end
139
+
140
+ describe '#group' do
141
+ subject{ table('events').group('time(1s)', 'name', :type) }
142
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
143
+ specify{ expect(subject.ast.groups).to eq([
144
+ node(:Group, sql('time(1s)')), node(:Group, sql('name')), node(:Group, sql('type'))
145
+ ]) }
146
+ specify{ expect(subject.to_sql).to eq('SELECT * FROM events GROUP BY time(1s), name, type') }
147
+
148
+ context 'chaining' do
149
+ subject{ table('events').group('time(1s)').group('name', :type) }
150
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
151
+ specify{ expect(subject.ast.groups).to eq([
152
+ node(:Group, sql('time(1s)')), node(:Group, sql('name')), node(:Group, sql('type'))
153
+ ]) }
154
+ specify{ expect(subject.to_sql).to eq('SELECT * FROM events GROUP BY time(1s), name, type') }
155
+ end
156
+ end
157
+
158
+ describe '#where' do
159
+ subject{ table('events').where(sql("name = 'Undr'")) }
160
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
161
+ specify{ expect(subject.wheres).to eq([sql("name = 'Undr'")]) }
162
+ specify{ expect(subject.to_sql).to eq("SELECT * FROM events WHERE name = 'Undr'") }
163
+
164
+ context 'chaining' do
165
+ subject{ table('events').where(sql("name = 'Undr'")).where(sql("email = 'undr@gmail.com'")) }
166
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
167
+ specify{ expect(subject.wheres).to eq([sql("name = 'Undr'"), sql("email = 'undr@gmail.com'")]) }
168
+ specify{ expect(subject.to_sql).to eq("SELECT * FROM events WHERE name = 'Undr' AND email = 'undr@gmail.com'") }
169
+ end
170
+ end
171
+
172
+ describe '#column' do
173
+ subject{ table('events').column(table('events')[:time], 'name', :type) }
174
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
175
+ specify{ expect(subject.ast.columns).to eq([table('events')[:time], sql('name'), sql('type')]) }
176
+ specify{ expect(subject.to_sql).to eq('SELECT time, name, type FROM events') }
177
+
178
+ context 'chaining' do
179
+ subject{ table('events').column(table('events')[:time]).column('name', :type) }
180
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::SelectManager) }
181
+ specify{ expect(subject.ast.columns).to eq([table('events')[:time], sql('name'), sql('type')]) }
182
+ specify{ expect(subject.to_sql).to eq('SELECT time, name, type FROM events') }
183
+ end
184
+ end
185
+
186
+ describe '#table_alias' do
187
+ specify{ expect(table('events').table_alias).to be_nil }
188
+ end
189
+
190
+ describe '#unalias' do
191
+ specify{ expect(table('events').unalias).to eq(table('events')) }
192
+ end
193
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe Influxdb::Arel do
4
+ describe '.sql' do
5
+ specify{ expect(subject.sql('time(1s)')).to eq(sql('time(1s)')) }
6
+ end
7
+
8
+ describe '.star' do
9
+ specify{ expect(subject.star).to eq(sql('*')) }
10
+ end
11
+ end
@@ -0,0 +1,20 @@
1
+ require 'bundler'
2
+ Bundler.require(:default, :test)
3
+
4
+ Dir["./spec/support/**/*.rb"].each { |f| require f }
5
+
6
+ RSpec.configure do |config|
7
+ config.mock_with :rspec
8
+
9
+ config.include Influxdb::Arel::RspecHelper
10
+
11
+ config.around :each, time_freeze: ->(v){ v.is_a?(Date) || v.is_a?(Time) || v.is_a?(String) } do |example|
12
+ datetime = if example.metadata[:time_freeze].is_a?(String)
13
+ DateTime.parse(example.metadata[:time_freeze])
14
+ else
15
+ example.metadata[:time_freeze]
16
+ end
17
+
18
+ Timecop.freeze(datetime){ example.run }
19
+ end
20
+ end
@@ -0,0 +1,10 @@
1
+ shared_examples_for :binary_node do |klass, node_sql = nil|
2
+ let(:described_node){ node(klass, sql('left'), sql('right')) }
3
+
4
+ it_should_behave_like :node_to_sql, node_sql if node_sql
5
+
6
+ describe '#eql?' do
7
+ specify{ expect(described_node.eql?(node(klass, sql('left'), sql('right')))).to be_truthy }
8
+ specify{ expect(described_node.eql?(node(klass, sql('right'), sql('left')))).to be_falsy }
9
+ end
10
+ end
@@ -0,0 +1,14 @@
1
+ shared_examples_for :function_node do |klass, node_sql, args = []|
2
+ let(:expressions){ args.dup.unshift(sql('expression')) }
3
+ let(:other_expressions){ args.dup.unshift(sql('another_expression')) }
4
+ let(:described_node){ node(klass, expressions) }
5
+
6
+ it_should_behave_like :node_to_sql, node_sql
7
+ it_should_behave_like :node_as, node_sql
8
+ it_should_behave_like :node_math, node_sql
9
+
10
+ describe '#eql?' do
11
+ specify{ expect(described_node.eql?(node(klass, expressions))).to be_truthy }
12
+ specify{ expect(described_node.eql?(node(klass, other_expressions))).to be_falsy }
13
+ end
14
+ end
@@ -0,0 +1,8 @@
1
+ shared_examples_for :node_as do |node_sql|
2
+ describe '#as' do
3
+ subject{ described_node.as('alias') }
4
+
5
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::Nodes::As) }
6
+ specify{ expect(subject.to_sql).to eq("#{node_sql} AS alias") }
7
+ end
8
+ end
@@ -0,0 +1,145 @@
1
+ shared_examples_for :node_expressions do |node_sql|
2
+ describe '#count' do
3
+ subject{ described_node.count }
4
+
5
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::Nodes::Count) }
6
+ specify{ expect(subject.expressions).to eq([described_node]) }
7
+ specify{ expect(subject.to_sql).to eq("COUNT(#{node_sql})") }
8
+ end
9
+
10
+ describe '#sun' do
11
+ subject{ described_node.sum }
12
+
13
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::Nodes::Sum) }
14
+ specify{ expect(subject.expressions).to eq([described_node]) }
15
+ specify{ expect(subject.to_sql).to eq("SUM(#{node_sql})") }
16
+ end
17
+
18
+ describe '#max' do
19
+ subject{ described_node.max }
20
+
21
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::Nodes::Max) }
22
+ specify{ expect(subject.expressions).to eq([described_node]) }
23
+ specify{ expect(subject.to_sql).to eq("MAX(#{node_sql})") }
24
+ end
25
+
26
+ describe '#min' do
27
+ subject{ described_node.min }
28
+
29
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::Nodes::Min) }
30
+ specify{ expect(subject.expressions).to eq([described_node]) }
31
+ specify{ expect(subject.to_sql).to eq("MIN(#{node_sql})") }
32
+ end
33
+
34
+ describe '#mean' do
35
+ subject{ described_node.mean }
36
+
37
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::Nodes::Mean) }
38
+ specify{ expect(subject.expressions).to eq([described_node]) }
39
+ specify{ expect(subject.to_sql).to eq("MEAN(#{node_sql})") }
40
+ end
41
+
42
+ describe '#mode' do
43
+ subject{ described_node.mode }
44
+
45
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::Nodes::Mode) }
46
+ specify{ expect(subject.expressions).to eq([described_node]) }
47
+ specify{ expect(subject.to_sql).to eq("MODE(#{node_sql})") }
48
+ end
49
+
50
+ describe '#median' do
51
+ subject{ described_node.median }
52
+
53
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::Nodes::Median) }
54
+ specify{ expect(subject.expressions).to eq([described_node]) }
55
+ specify{ expect(subject.to_sql).to eq("MEDIAN(#{node_sql})") }
56
+ end
57
+
58
+ describe '#mode' do
59
+ subject{ described_node.mode }
60
+
61
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::Nodes::Mode) }
62
+ specify{ expect(subject.expressions).to eq([described_node]) }
63
+ specify{ expect(subject.to_sql).to eq("MODE(#{node_sql})") }
64
+ end
65
+
66
+ describe '#distinct' do
67
+ subject{ described_node.distinct }
68
+
69
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::Nodes::Distinct) }
70
+ specify{ expect(subject.expressions).to eq([described_node]) }
71
+ specify{ expect(subject.to_sql).to eq("DISTINCT(#{node_sql})") }
72
+ end
73
+
74
+ describe '#percentile' do
75
+ subject{ described_node.percentile(95) }
76
+
77
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::Nodes::Percentile) }
78
+ specify{ expect(subject.expressions).to eq([described_node, 95]) }
79
+ specify{ expect(subject.to_sql).to eq("PERCENTILE(#{node_sql}, 95)") }
80
+ end
81
+
82
+ describe '#histogram' do
83
+ subject{ described_node.histogram(2) }
84
+
85
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::Nodes::Histogram) }
86
+ specify{ expect(subject.expressions).to eq([described_node, 2]) }
87
+ specify{ expect(subject.to_sql).to eq("HISTOGRAM(#{node_sql}, 2)") }
88
+ end
89
+
90
+ describe '#derivative' do
91
+ subject{ described_node.derivative }
92
+
93
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::Nodes::Derivative) }
94
+ specify{ expect(subject.expressions).to eq([described_node]) }
95
+ specify{ expect(subject.to_sql).to eq("DERIVATIVE(#{node_sql})") }
96
+ end
97
+
98
+ describe '#stddev' do
99
+ subject{ described_node.stddev }
100
+
101
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::Nodes::Stddev) }
102
+ specify{ expect(subject.expressions).to eq([described_node]) }
103
+ specify{ expect(subject.to_sql).to eq("STDDEV(#{node_sql})") }
104
+ end
105
+
106
+ describe '#first' do
107
+ subject{ described_node.first }
108
+
109
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::Nodes::First) }
110
+ specify{ expect(subject.expressions).to eq([described_node]) }
111
+ specify{ expect(subject.to_sql).to eq("FIRST(#{node_sql})") }
112
+ end
113
+
114
+ describe '#last' do
115
+ subject{ described_node.last }
116
+
117
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::Nodes::Last) }
118
+ specify{ expect(subject.expressions).to eq([described_node]) }
119
+ specify{ expect(subject.to_sql).to eq("LAST(#{node_sql})") }
120
+ end
121
+
122
+ describe '#difference' do
123
+ subject{ described_node.difference }
124
+
125
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::Nodes::Difference) }
126
+ specify{ expect(subject.expressions).to eq([described_node]) }
127
+ specify{ expect(subject.to_sql).to eq("DIFFERENCE(#{node_sql})") }
128
+ end
129
+
130
+ describe '#top' do
131
+ subject{ described_node.top(10) }
132
+
133
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::Nodes::Top) }
134
+ specify{ expect(subject.expressions).to eq([described_node, 10]) }
135
+ specify{ expect(subject.to_sql).to eq("TOP(#{node_sql}, 10)") }
136
+ end
137
+
138
+ describe '#bottom' do
139
+ subject{ described_node.bottom(10) }
140
+
141
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::Nodes::Bottom) }
142
+ specify{ expect(subject.expressions).to eq([described_node, 10]) }
143
+ specify{ expect(subject.to_sql).to eq("BOTTOM(#{node_sql}, 10)") }
144
+ end
145
+ end
@@ -0,0 +1,29 @@
1
+ shared_examples_for :node_math do |node_sql|
2
+ describe '#+' do
3
+ subject{ described_node + 10 }
4
+
5
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::Nodes::Grouping) }
6
+ specify{ expect(subject.to_sql).to eq("(#{node_sql} + 10)") }
7
+ end
8
+
9
+ describe '#-' do
10
+ subject{ described_node - 10 }
11
+
12
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::Nodes::Grouping) }
13
+ specify{ expect(subject.to_sql).to eq("(#{node_sql} - 10)") }
14
+ end
15
+
16
+ describe '#/' do
17
+ subject{ described_node / 10 }
18
+
19
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::Nodes::Division) }
20
+ specify{ expect(subject.to_sql).to eq("#{node_sql} / 10") }
21
+ end
22
+
23
+ describe '#*' do
24
+ subject{ described_node * 10 }
25
+
26
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::Nodes::Multiplication) }
27
+ specify{ expect(subject.to_sql).to eq("#{node_sql} * 10") }
28
+ end
29
+ end
@@ -0,0 +1,248 @@
1
+ shared_examples_for :node_predications do |node_sql|
2
+ describe '#not_eq' do
3
+ subject{ described_node.not_eq(1) }
4
+
5
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::Nodes::NotEqual) }
6
+ specify{ expect(subject.left).to eq(described_node) }
7
+ specify{ expect(subject.right).to eq(1) }
8
+ specify{ expect(subject.to_sql).to eq("#{node_sql} <> 1") }
9
+ end
10
+
11
+ describe '#not_eq_any' do
12
+ subject{ described_node.not_eq_any([1, 2]) }
13
+
14
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::Nodes::Grouping) }
15
+ specify{ expect(subject.to_sql).to eq("(#{node_sql} <> 1 OR #{node_sql} <> 2)") }
16
+ end
17
+
18
+ describe '#not_eq_all' do
19
+ subject{ described_node.not_eq_all([1, 2]) }
20
+
21
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::Nodes::Grouping) }
22
+ specify{ expect(subject.to_sql).to eq("(#{node_sql} <> 1 AND #{node_sql} <> 2)") }
23
+ end
24
+
25
+ describe '#eq' do
26
+ subject{ described_node.eq(1) }
27
+
28
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::Nodes::Equality) }
29
+ specify{ expect(subject.left).to eq(described_node) }
30
+ specify{ expect(subject.right).to eq(1) }
31
+ specify{ expect(subject.to_sql).to eq("#{node_sql} = 1") }
32
+ end
33
+
34
+ describe '#eq_any' do
35
+ subject{ described_node.eq_any([1, 2]) }
36
+
37
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::Nodes::Grouping) }
38
+ specify{ expect(subject.to_sql).to eq("(#{node_sql} = 1 OR #{node_sql} = 2)") }
39
+ end
40
+
41
+ describe '#eq_all' do
42
+ subject{ described_node.eq_all([1, 2]) }
43
+
44
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::Nodes::Grouping) }
45
+ specify{ expect(subject.to_sql).to eq("(#{node_sql} = 1 AND #{node_sql} = 2)") }
46
+ end
47
+
48
+ describe '#matches' do
49
+ subject{ described_node.matches(/.*/) }
50
+
51
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::Nodes::Matches) }
52
+ specify{ expect(subject.left).to eq(described_node) }
53
+ specify{ expect(subject.right).to eq(/.*/) }
54
+ specify{ expect(subject.to_sql).to eq("#{node_sql} =~ /.*/") }
55
+ end
56
+
57
+ describe '#matches_any' do
58
+ subject{ described_node.matches_any([/\w*/, /\d*/]) }
59
+
60
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::Nodes::Grouping) }
61
+ specify{ expect(subject.to_sql).to eq("(#{node_sql} =~ /\\w*/ OR #{node_sql} =~ /\\d*/)") }
62
+ end
63
+
64
+ describe '#matches_all' do
65
+ subject{ described_node.matches_all([/\w*/, /\d*/]) }
66
+
67
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::Nodes::Grouping) }
68
+ specify{ expect(subject.to_sql).to eq("(#{node_sql} =~ /\\w*/ AND #{node_sql} =~ /\\d*/)") }
69
+ end
70
+
71
+ describe '#does_not_match' do
72
+ subject{ described_node.does_not_match(/.*/) }
73
+
74
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::Nodes::DoesNotMatch) }
75
+ specify{ expect(subject.left).to eq(described_node) }
76
+ specify{ expect(subject.right).to eq(/.*/) }
77
+ specify{ expect(subject.to_sql).to eq("#{node_sql} !~ /.*/") }
78
+ end
79
+
80
+ describe '#does_not_match_any' do
81
+ subject{ described_node.does_not_match_any([/\w*/, /\d*/]) }
82
+
83
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::Nodes::Grouping) }
84
+ specify{ expect(subject.to_sql).to eq("(#{node_sql} !~ /\\w*/ OR #{node_sql} !~ /\\d*/)") }
85
+ end
86
+
87
+ describe '#does_not_match_all' do
88
+ subject{ described_node.does_not_match_all([/\w*/, /\d*/]) }
89
+
90
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::Nodes::Grouping) }
91
+ specify{ expect(subject.to_sql).to eq("(#{node_sql} !~ /\\w*/ AND #{node_sql} !~ /\\d*/)") }
92
+ end
93
+
94
+ describe '#gteq' do
95
+ subject{ described_node.gteq(1) }
96
+
97
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::Nodes::GreaterThanOrEqual) }
98
+ specify{ expect(subject.left).to eq(described_node) }
99
+ specify{ expect(subject.right).to eq(1) }
100
+ specify{ expect(subject.to_sql).to eq("#{node_sql} >= 1") }
101
+ end
102
+
103
+ describe '#gteq_any' do
104
+ subject{ described_node.gteq_any([1, 2]) }
105
+
106
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::Nodes::Grouping) }
107
+ specify{ expect(subject.to_sql).to eq("(#{node_sql} >= 1 OR #{node_sql} >= 2)") }
108
+ end
109
+
110
+ describe '#gteq_all' do
111
+ subject{ described_node.gteq_all([1, 2]) }
112
+
113
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::Nodes::Grouping) }
114
+ specify{ expect(subject.to_sql).to eq("(#{node_sql} >= 1 AND #{node_sql} >= 2)") }
115
+ end
116
+
117
+ describe '#gt' do
118
+ subject{ described_node.gt(1) }
119
+
120
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::Nodes::GreaterThan) }
121
+ specify{ expect(subject.left).to eq(described_node) }
122
+ specify{ expect(subject.right).to eq(1) }
123
+ specify{ expect(subject.to_sql).to eq("#{node_sql} > 1") }
124
+ end
125
+
126
+ describe '#gt_any' do
127
+ subject{ described_node.gt_any([1, 2]) }
128
+
129
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::Nodes::Grouping) }
130
+ specify{ expect(subject.to_sql).to eq("(#{node_sql} > 1 OR #{node_sql} > 2)") }
131
+ end
132
+
133
+ describe '#gt_all' do
134
+ subject{ described_node.gt_all([1, 2]) }
135
+
136
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::Nodes::Grouping) }
137
+ specify{ expect(subject.to_sql).to eq("(#{node_sql} > 1 AND #{node_sql} > 2)") }
138
+ end
139
+
140
+ describe '#lt' do
141
+ subject{ described_node.lt(1) }
142
+
143
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::Nodes::LessThan) }
144
+ specify{ expect(subject.left).to eq(described_node) }
145
+ specify{ expect(subject.right).to eq(1) }
146
+ specify{ expect(subject.to_sql).to eq("#{node_sql} < 1") }
147
+ end
148
+
149
+ describe '#lt_any' do
150
+ subject{ described_node.lt_any([1, 2]) }
151
+
152
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::Nodes::Grouping) }
153
+ specify{ expect(subject.to_sql).to eq("(#{node_sql} < 1 OR #{node_sql} < 2)") }
154
+ end
155
+
156
+ describe '#lt_all' do
157
+ subject{ described_node.lt_all([1, 2]) }
158
+
159
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::Nodes::Grouping) }
160
+ specify{ expect(subject.to_sql).to eq("(#{node_sql} < 1 AND #{node_sql} < 2)") }
161
+ end
162
+
163
+ describe '#lteq' do
164
+ subject{ described_node.lteq(1) }
165
+
166
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::Nodes::LessThanOrEqual) }
167
+ specify{ expect(subject.left).to eq(described_node) }
168
+ specify{ expect(subject.right).to eq(1) }
169
+ specify{ expect(subject.to_sql).to eq("#{node_sql} <= 1") }
170
+ end
171
+
172
+ describe '#lteq_any' do
173
+ subject{ described_node.lteq_any([1, 2]) }
174
+
175
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::Nodes::Grouping) }
176
+ specify{ expect(subject.to_sql).to eq("(#{node_sql} <= 1 OR #{node_sql} <= 2)") }
177
+ end
178
+
179
+ describe '#lteq_all' do
180
+ subject{ described_node.lteq_all([1, 2]) }
181
+
182
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::Nodes::Grouping) }
183
+ specify{ expect(subject.to_sql).to eq("(#{node_sql} <= 1 AND #{node_sql} <= 2)") }
184
+ end
185
+
186
+ describe '#in' do
187
+ subject{ described_node.in(expr) }
188
+
189
+ context 'with infinity range' do
190
+ let(:expr){ -Float::INFINITY..Float::INFINITY }
191
+
192
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::Nodes::Equality) }
193
+ specify{ expect(subject.left).to eq(1) }
194
+ specify{ expect(subject.right).to eq(1) }
195
+ specify{ expect(subject.to_sql).to eq("1 = 1") }
196
+ end
197
+
198
+ context 'with endless range' do
199
+ let(:expr){ 1..Float::INFINITY }
200
+
201
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::Nodes::GreaterThanOrEqual) }
202
+ specify{ expect(subject.left).to eq(described_node) }
203
+ specify{ expect(subject.right).to eq(1) }
204
+ specify{ expect(subject.to_sql).to eq("#{node_sql} >= 1") }
205
+ end
206
+
207
+ context 'with startless range' do
208
+ let(:expr){ -Float::INFINITY..1 }
209
+
210
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::Nodes::LessThanOrEqual) }
211
+ specify{ expect(subject.left).to eq(described_node) }
212
+ specify{ expect(subject.right).to eq(1) }
213
+ specify{ expect(subject.to_sql).to eq("#{node_sql} <= 1") }
214
+ end
215
+
216
+ context 'with startless range with exclided end' do
217
+ let(:expr){ -Float::INFINITY...1 }
218
+
219
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::Nodes::LessThan) }
220
+ specify{ expect(subject.left).to eq(described_node) }
221
+ specify{ expect(subject.right).to eq(1) }
222
+ specify{ expect(subject.to_sql).to eq("#{node_sql} < 1") }
223
+ end
224
+
225
+ context 'with range' do
226
+ let(:expr){ -1..1 }
227
+
228
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::Nodes::And) }
229
+ specify{ expect(subject.to_sql).to eq("#{node_sql} >= -1 AND #{node_sql} <= 1") }
230
+ end
231
+
232
+ context 'with range with exclided end' do
233
+ let(:expr){ -1...1 }
234
+
235
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::Nodes::And) }
236
+ specify{ expect(subject.to_sql).to eq("#{node_sql} >= -1 AND #{node_sql} < 1") }
237
+ end
238
+
239
+ context 'with array' do
240
+ subject{ described_node.in([1, 2]) }
241
+
242
+ specify{ expect(subject).to be_instance_of(Influxdb::Arel::Nodes::In) }
243
+ specify{ expect(subject.left).to eq(described_node) }
244
+ specify{ expect(subject.right).to eq([1, 2]) }
245
+ specify{ expect(subject.to_sql).to eq("#{node_sql} IN (1, 2)") }
246
+ end
247
+ end
248
+ end