influxdb-arel 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -0
- data/Gemfile +1 -0
- data/README.md +218 -124
- data/lib/influxdb/arel.rb +25 -16
- data/lib/influxdb/arel/builder.rb +209 -0
- data/lib/influxdb/arel/clauses.rb +6 -0
- data/lib/influxdb/arel/clauses/base.rb +34 -0
- data/lib/influxdb/arel/clauses/expressions.rb +75 -0
- data/lib/influxdb/arel/clauses/from_clause.rb +45 -0
- data/lib/influxdb/arel/clauses/group_clause.rb +34 -0
- data/lib/influxdb/arel/clauses/select_clause.rb +37 -0
- data/lib/influxdb/arel/clauses/where_clause.rb +102 -0
- data/lib/influxdb/arel/core_extensions.rb +5 -21
- data/lib/influxdb/arel/delete_manager.rb +50 -0
- data/lib/influxdb/arel/extensions.rb +6 -0
- data/lib/influxdb/arel/extensions/alias_predication.rb +11 -0
- data/lib/influxdb/arel/extensions/boolean_predications.rb +15 -0
- data/lib/influxdb/arel/extensions/expressions.rb +75 -0
- data/lib/influxdb/arel/extensions/joining_merging.rb +21 -0
- data/lib/influxdb/arel/extensions/math.rb +23 -0
- data/lib/influxdb/arel/extensions/predications.rb +144 -0
- data/lib/influxdb/arel/nodes.rb +7 -14
- data/lib/influxdb/arel/nodes/attribute.rb +20 -0
- data/lib/influxdb/arel/nodes/binary.rb +4 -3
- data/lib/influxdb/arel/nodes/delete_statement.rb +37 -0
- data/lib/influxdb/arel/nodes/duration.rb +3 -3
- data/lib/influxdb/arel/nodes/function.rb +2 -2
- data/lib/influxdb/arel/nodes/grouping.rb +3 -3
- data/lib/influxdb/arel/nodes/infix_operation.rb +11 -4
- data/lib/influxdb/arel/nodes/merge.rb +13 -0
- data/lib/influxdb/arel/nodes/node.rb +18 -6
- data/lib/influxdb/arel/nodes/now.rb +1 -1
- data/lib/influxdb/arel/nodes/ordering.rb +15 -0
- data/lib/influxdb/arel/nodes/select_statement.rb +10 -8
- data/lib/influxdb/arel/nodes/sql_literal.rb +5 -8
- data/lib/influxdb/arel/nodes/table.rb +19 -0
- data/lib/influxdb/arel/nodes/table_alias.rb +2 -4
- data/lib/influxdb/arel/nodes/unary.rb +6 -1
- data/lib/influxdb/arel/quoter.rb +85 -0
- data/lib/influxdb/arel/select_manager.rb +111 -64
- data/lib/influxdb/arel/tree_manager.rb +15 -5
- data/lib/influxdb/arel/version.rb +1 -1
- data/lib/influxdb/arel/visitor.rb +96 -126
- data/lib/influxdb/arel/visitor/delete_statement.rb +32 -0
- data/lib/influxdb/arel/visitor/select_statement.rb +59 -0
- data/lib/influxdb/arel/visitor/where_statement.rb +14 -0
- data/spec/lib/influxdb/arel/builder_spec.rb +173 -0
- data/spec/lib/influxdb/arel/core_extensions_spec.rb +0 -21
- data/spec/lib/influxdb/arel/nodes/and_spec.rb +6 -9
- data/spec/lib/influxdb/arel/nodes/attribute_spec.rb +21 -0
- data/spec/lib/influxdb/arel/nodes/binary_spec.rb +0 -4
- data/spec/lib/influxdb/arel/nodes/duration_spec.rb +1 -0
- data/spec/lib/influxdb/arel/nodes/in_spec.rb +1 -0
- data/spec/lib/influxdb/arel/nodes/infix_operation_spec.rb +17 -0
- data/spec/lib/influxdb/arel/nodes/merge_spec.rb +25 -0
- data/spec/lib/influxdb/arel/nodes/now_spec.rb +1 -0
- data/spec/lib/influxdb/arel/nodes/ordering_spec.rb +19 -0
- data/spec/lib/influxdb/arel/nodes/sql_literal_spec.rb +1 -5
- data/spec/lib/influxdb/arel/nodes/table_alias_spec.rb +3 -10
- data/spec/lib/influxdb/arel/nodes/table_spec.rb +8 -0
- data/spec/lib/influxdb/arel/nodes/unary_spec.rb +0 -4
- data/spec/lib/influxdb/arel/quoter/repository_spec.rb +10 -0
- data/spec/lib/influxdb/arel/quoter_spec.rb +33 -0
- data/spec/lib/influxdb/arel/select_manager_spec.rb +356 -156
- data/spec/lib/influxdb/arel_spec.rb +22 -0
- data/spec/spec_helper.rb +15 -0
- data/spec/support/examples/binary_node.rb +1 -0
- data/spec/support/examples/function_node.rb +1 -0
- data/spec/support/examples/infix_operation_node.rb +15 -0
- data/spec/support/examples/node_boolean_predications.rb +21 -0
- data/spec/support/examples/node_joining_merging.rb +53 -0
- data/spec/support/examples/unary_node.rb +1 -0
- data/spec/support/fabrics.rb +3 -3
- metadata +49 -11
- data/lib/influxdb/arel/alias_predication.rb +0 -9
- data/lib/influxdb/arel/attributes.rb +0 -1
- data/lib/influxdb/arel/attributes/attribute.rb +0 -74
- data/lib/influxdb/arel/expressions.rb +0 -73
- data/lib/influxdb/arel/math.rb +0 -21
- data/lib/influxdb/arel/predications.rb +0 -137
- data/lib/influxdb/arel/table.rb +0 -219
- data/spec/lib/influxdb/arel/table_spec.rb +0 -193
data/lib/influxdb/arel/math.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
module Influxdb
|
2
|
-
module Arel
|
3
|
-
module Math
|
4
|
-
def *(other)
|
5
|
-
Nodes::Multiplication.new(self, other)
|
6
|
-
end
|
7
|
-
|
8
|
-
def +(other)
|
9
|
-
Nodes::Grouping.new(Nodes::Addition.new(self, other))
|
10
|
-
end
|
11
|
-
|
12
|
-
def -(other)
|
13
|
-
Nodes::Grouping.new(Nodes::Subtraction.new(self, other))
|
14
|
-
end
|
15
|
-
|
16
|
-
def /(other)
|
17
|
-
Nodes::Division.new(self, other)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1,137 +0,0 @@
|
|
1
|
-
module Influxdb
|
2
|
-
module Arel
|
3
|
-
module Predications
|
4
|
-
def not_eq(other)
|
5
|
-
Nodes::NotEqual.new(self, other)
|
6
|
-
end
|
7
|
-
|
8
|
-
def not_eq_any(others)
|
9
|
-
grouping_any(:not_eq, others)
|
10
|
-
end
|
11
|
-
|
12
|
-
def not_eq_all(others)
|
13
|
-
grouping_all(:not_eq, others)
|
14
|
-
end
|
15
|
-
|
16
|
-
def eq(other)
|
17
|
-
Nodes::Equality.new(self, other)
|
18
|
-
end
|
19
|
-
|
20
|
-
def eq_any(others)
|
21
|
-
grouping_any(:eq, others)
|
22
|
-
end
|
23
|
-
|
24
|
-
def eq_all(others)
|
25
|
-
grouping_all(:eq, others)
|
26
|
-
end
|
27
|
-
|
28
|
-
def in(other)
|
29
|
-
case other
|
30
|
-
when Range
|
31
|
-
if other.begin == -Float::INFINITY && other.end == Float::INFINITY
|
32
|
-
Nodes::Equality.new(1, 1)
|
33
|
-
elsif other.end == Float::INFINITY
|
34
|
-
Nodes::GreaterThanOrEqual.new(self, other.begin)
|
35
|
-
elsif other.begin == -Float::INFINITY && other.exclude_end?
|
36
|
-
Nodes::LessThan.new(self, other.end)
|
37
|
-
elsif other.begin == -Float::INFINITY
|
38
|
-
Nodes::LessThanOrEqual.new(self, other.end)
|
39
|
-
elsif other.exclude_end?
|
40
|
-
left = Nodes::GreaterThanOrEqual.new(self, other.begin)
|
41
|
-
right = Nodes::LessThan.new(self, other.end)
|
42
|
-
Nodes::And.new([left, right])
|
43
|
-
else
|
44
|
-
left = Nodes::GreaterThanOrEqual.new(self, other.begin)
|
45
|
-
right = Nodes::LessThanOrEqual.new(self, other.end)
|
46
|
-
Nodes::And.new([left, right])
|
47
|
-
end
|
48
|
-
else
|
49
|
-
Nodes::In.new(self, other)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
def matches(other)
|
54
|
-
Nodes::Matches.new(self, other)
|
55
|
-
end
|
56
|
-
|
57
|
-
def matches_any(others)
|
58
|
-
grouping_any(:matches, others)
|
59
|
-
end
|
60
|
-
|
61
|
-
def matches_all(others)
|
62
|
-
grouping_all(:matches, others)
|
63
|
-
end
|
64
|
-
|
65
|
-
def does_not_match(other)
|
66
|
-
Nodes::DoesNotMatch.new(self, other)
|
67
|
-
end
|
68
|
-
|
69
|
-
def does_not_match_any(others)
|
70
|
-
grouping_any(:does_not_match, others)
|
71
|
-
end
|
72
|
-
|
73
|
-
def does_not_match_all(others)
|
74
|
-
grouping_all(:does_not_match, others)
|
75
|
-
end
|
76
|
-
|
77
|
-
def gteq(right)
|
78
|
-
Nodes::GreaterThanOrEqual.new(self, right)
|
79
|
-
end
|
80
|
-
|
81
|
-
def gteq_any(others)
|
82
|
-
grouping_any(:gteq, others)
|
83
|
-
end
|
84
|
-
|
85
|
-
def gteq_all(others)
|
86
|
-
grouping_all(:gteq, others)
|
87
|
-
end
|
88
|
-
|
89
|
-
def gt(right)
|
90
|
-
Nodes::GreaterThan.new(self, right)
|
91
|
-
end
|
92
|
-
|
93
|
-
def gt_any(others)
|
94
|
-
grouping_any(:gt, others)
|
95
|
-
end
|
96
|
-
|
97
|
-
def gt_all(others)
|
98
|
-
grouping_all(:gt, others)
|
99
|
-
end
|
100
|
-
|
101
|
-
def lt(right)
|
102
|
-
Nodes::LessThan.new(self, right)
|
103
|
-
end
|
104
|
-
|
105
|
-
def lt_any(others)
|
106
|
-
grouping_any(:lt, others)
|
107
|
-
end
|
108
|
-
|
109
|
-
def lt_all(others)
|
110
|
-
grouping_all(:lt, others)
|
111
|
-
end
|
112
|
-
|
113
|
-
def lteq(right)
|
114
|
-
Nodes::LessThanOrEqual.new(self, right)
|
115
|
-
end
|
116
|
-
|
117
|
-
def lteq_any(others)
|
118
|
-
grouping_any(:lteq, others)
|
119
|
-
end
|
120
|
-
|
121
|
-
def lteq_all(others)
|
122
|
-
grouping_all(:lteq, others)
|
123
|
-
end
|
124
|
-
|
125
|
-
private
|
126
|
-
|
127
|
-
def grouping_any(method_id, others)
|
128
|
-
nodes = others.map{|expr| send(method_id, expr) }
|
129
|
-
Nodes::Grouping.new(nodes.inject{|result, node| Nodes::Or.new(result, node) })
|
130
|
-
end
|
131
|
-
|
132
|
-
def grouping_all(method_id, others)
|
133
|
-
Nodes::Grouping.new(Nodes::And.new(others.map{|expr| send(method_id, expr) }))
|
134
|
-
end
|
135
|
-
end
|
136
|
-
end
|
137
|
-
end
|
data/lib/influxdb/arel/table.rb
DELETED
@@ -1,219 +0,0 @@
|
|
1
|
-
module Influxdb
|
2
|
-
module Arel
|
3
|
-
class Table
|
4
|
-
class << self
|
5
|
-
def comparable_classes
|
6
|
-
[Influxdb::Arel::Table, Influxdb::Arel::Nodes::SqlLiteral]
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
attr_accessor :name
|
11
|
-
|
12
|
-
alias :table_name :name
|
13
|
-
|
14
|
-
def initialize(name)
|
15
|
-
@name = name.to_s
|
16
|
-
end
|
17
|
-
|
18
|
-
# Specify alias for table
|
19
|
-
# Example:
|
20
|
-
#
|
21
|
-
# Influxdb::Arel::Table.new('table').as('alias_table').to_sql
|
22
|
-
# => table AS alias_table
|
23
|
-
#
|
24
|
-
def alias(name)
|
25
|
-
Nodes::TableAlias.new(self, name)
|
26
|
-
end
|
27
|
-
|
28
|
-
alias :as :alias
|
29
|
-
|
30
|
-
def from(*tables)
|
31
|
-
SelectManager.new(*tables)
|
32
|
-
end
|
33
|
-
|
34
|
-
# Merging of two series into one.
|
35
|
-
#
|
36
|
-
# If <tt>table</tt> is nil it will merge two first tables from tables list.
|
37
|
-
#
|
38
|
-
# table = Influxdb::Arel::Table.new('table')
|
39
|
-
# table.from('table1', 'table2').merge.to_sql
|
40
|
-
# => SELECT * FROM table1 MERGE table2
|
41
|
-
#
|
42
|
-
# If <tt>table</tt> is nil and tables list contains only one table it will change nothing.
|
43
|
-
#
|
44
|
-
# table.merge.to_sql
|
45
|
-
# => SELECT * FROM table
|
46
|
-
#
|
47
|
-
# If <tt>table</tt> exists it will merge first table from tables list with given table.
|
48
|
-
#
|
49
|
-
# table.merge('table2').to_sql
|
50
|
-
# => SELECT * FROM table MERGE table2
|
51
|
-
#
|
52
|
-
# table.from('table1', 'table2').merge('table3').to_sql
|
53
|
-
# => SELECT * FROM table1 MERGE table3
|
54
|
-
#
|
55
|
-
def merge(table = nil)
|
56
|
-
from(self).merge(table)
|
57
|
-
end
|
58
|
-
|
59
|
-
# Joining of two series.
|
60
|
-
#
|
61
|
-
# If <tt>table</tt> is nil it will join two first tables from tables list.
|
62
|
-
#
|
63
|
-
# table = Influxdb::Arel::Table.new('table')
|
64
|
-
# table.from('table1', 'table2').join.to_sql
|
65
|
-
# => SELECT * FROM table1 INNER JOIN table2
|
66
|
-
#
|
67
|
-
# If <tt>table</tt> is nil and tables list contains only one table it will change nothing.
|
68
|
-
#
|
69
|
-
# table.join.to_sql
|
70
|
-
# => SELECT * FROM table
|
71
|
-
#
|
72
|
-
# If <tt>table</tt> exists it will join first table from tables list with given table.
|
73
|
-
#
|
74
|
-
# table.join('table2').to_sql
|
75
|
-
# => SELECT * FROM table INNER JOIN table2
|
76
|
-
#
|
77
|
-
# table.from('table1', 'table2').join('table3').to_sql
|
78
|
-
# => SELECT * FROM table1 INNER JOIN table3
|
79
|
-
#
|
80
|
-
# Aliases.
|
81
|
-
# You can define alias for each joined table. It would be usefull for self joining table.
|
82
|
-
#
|
83
|
-
# table.from(table.as(:table_one)).join(table.as(:table_two)).to_sql
|
84
|
-
# => SELECT * FROM table AS table_one INNER JOIN table AS table_two
|
85
|
-
#
|
86
|
-
def join(table = nil)
|
87
|
-
from(self).join(table)
|
88
|
-
end
|
89
|
-
|
90
|
-
# Grouping results by specified columns or expressions, such as <tt>time(10m)</tt>
|
91
|
-
#
|
92
|
-
# table = Influxdb::Arel::Table.new('table')
|
93
|
-
# table.group(table.time(10.m), table[:host]).to_sql
|
94
|
-
# => SELECT * FROM table GROUP BY time(10m), host
|
95
|
-
#
|
96
|
-
# If you want to fill intervals with no data you shoult call <tt>fill</tt> method after:
|
97
|
-
#
|
98
|
-
# table.group(10.m.time, table[:host]).fill(0).to_sql
|
99
|
-
# => SELECT * FROM table GROUP BY time(10m), host fill(0)
|
100
|
-
#
|
101
|
-
def group(*columns)
|
102
|
-
from(self).group(*columns)
|
103
|
-
end
|
104
|
-
|
105
|
-
# Set the ordering of results
|
106
|
-
# Possible values:
|
107
|
-
#
|
108
|
-
# * <tt>:asc</tt>
|
109
|
-
# Default value. Results will be sorted by ascending order.
|
110
|
-
#
|
111
|
-
# * <tt>:desc</tt>
|
112
|
-
# Default value. Results will be sorted by descending order.
|
113
|
-
#
|
114
|
-
# Example:
|
115
|
-
#
|
116
|
-
# table = Influxdb::Arel::Table.new('table')
|
117
|
-
# table.order(:desc).to_sql
|
118
|
-
# table.order('desc').to_sql
|
119
|
-
# => SELECT * FROM table ORDER DESC
|
120
|
-
#
|
121
|
-
# table.order(:asc).to_sql
|
122
|
-
# table.order('asc').to_sql
|
123
|
-
# => SELECT * FROM table ORDER ASC
|
124
|
-
#
|
125
|
-
def order(expr)
|
126
|
-
from(self).order(expr)
|
127
|
-
end
|
128
|
-
|
129
|
-
# Specify conditions for selection or deletion query
|
130
|
-
# Example:
|
131
|
-
#
|
132
|
-
# table = Influxdb::Arel::Table.new('table')
|
133
|
-
# table.where(table[:name].eq('Undr')).to_sql
|
134
|
-
# => SELECT * FROM table WHERE name = 'Undr'
|
135
|
-
#
|
136
|
-
# table.where(table[:name].eq('Undr')).where(table[:time].lt(10.h.ago).to_sql
|
137
|
-
# => SELECT * FROM table WHERE name = 'Undr' AND time < (now() - 10h)
|
138
|
-
#
|
139
|
-
# table.where(table[:name].eq('Undr').or(table[:name].eq('Andrei'))).to_sql
|
140
|
-
# => SELECT * FROM table WHERE name = 'Undr' OR name = 'Andrei'
|
141
|
-
#
|
142
|
-
def where(condition)
|
143
|
-
from(self).where(condition)
|
144
|
-
end
|
145
|
-
|
146
|
-
# Specify columns or expressions for select.
|
147
|
-
# Example:
|
148
|
-
#
|
149
|
-
# table = Influxdb::Arel::Table.new('cpu_load')
|
150
|
-
# table.to_sql
|
151
|
-
# => SELECT * FROM cpu_load
|
152
|
-
#
|
153
|
-
# table.column((table[:system] + table[:user]).as(:sum)).to_sql
|
154
|
-
# => SELECT (system + user) AS sum FROM cpu_load
|
155
|
-
#
|
156
|
-
# table.column(table[:idle].mean.as(:idle_mean), table[:user].mean.as(:user_mean)).to_sql
|
157
|
-
# => SELECT MEAN(idle) AS idle_mean, MEAN(user) AS user_mean FROM cpu_load
|
158
|
-
#
|
159
|
-
def column(*things)
|
160
|
-
from(self).column(*things)
|
161
|
-
end
|
162
|
-
|
163
|
-
# Set limit for result's points
|
164
|
-
# Example:
|
165
|
-
#
|
166
|
-
# table = Influxdb::Arel::Table.new('cpu_load')
|
167
|
-
# table.take(100).to_sql
|
168
|
-
# => SELECT * FROM table LIMIT 100
|
169
|
-
#
|
170
|
-
def take(amount)
|
171
|
-
from(self).take(amount)
|
172
|
-
end
|
173
|
-
|
174
|
-
# Get attribute
|
175
|
-
#
|
176
|
-
def [](name)
|
177
|
-
Attribute.new(self, name)
|
178
|
-
end
|
179
|
-
|
180
|
-
def select_manager
|
181
|
-
SelectManager.new
|
182
|
-
end
|
183
|
-
|
184
|
-
def hash
|
185
|
-
@name.hash
|
186
|
-
end
|
187
|
-
|
188
|
-
def eql?(other)
|
189
|
-
self.class.comparable_classes.include?(self.class) && self.name == other.name
|
190
|
-
end
|
191
|
-
|
192
|
-
alias :== :eql?
|
193
|
-
|
194
|
-
def table_alias
|
195
|
-
nil
|
196
|
-
end
|
197
|
-
|
198
|
-
def unalias
|
199
|
-
self
|
200
|
-
end
|
201
|
-
|
202
|
-
def sql(raw_sql)
|
203
|
-
Arel.sql(raw_sql)
|
204
|
-
end
|
205
|
-
|
206
|
-
def star
|
207
|
-
Arel.star
|
208
|
-
end
|
209
|
-
|
210
|
-
def now
|
211
|
-
Arel.now
|
212
|
-
end
|
213
|
-
|
214
|
-
def time(duration)
|
215
|
-
Arel.time(duration)
|
216
|
-
end
|
217
|
-
end
|
218
|
-
end
|
219
|
-
end
|
@@ -1,193 +0,0 @@
|
|
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
|