activecube 0.1.16 → 0.1.24
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/Gemfile.lock +1 -1
- data/lib/activecube.rb +1 -0
- data/lib/activecube/cube_definition.rb +5 -1
- data/lib/activecube/processor/composer.rb +2 -2
- data/lib/activecube/query/cube_query.rb +29 -6
- data/lib/activecube/query/option.rb +17 -0
- data/lib/activecube/query/selector.rb +4 -4
- data/lib/activecube/query_methods.rb +5 -2
- data/lib/activecube/version.rb +1 -1
- data/lib/activecube/view.rb +34 -0
- data/lib/activecube/view_connection.rb +11 -0
- data/lib/activecube/view_definition.rb +16 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e08b7128492c4b84b982715355728b6506c0eb4dc155875ef1323bc88e9c9777
|
4
|
+
data.tar.gz: 856d25b480a319b11476c9d388f20aa656325f812299018c67df6b44bed322e8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 76d9c60cfba31ac7f65f819dc1e5b8b0d6689aebbb162f8677f45e7388442dfc7d581e2bec945478d058891f61fc2b7b34de5b7e79f40c510bb88c1f21647547
|
7
|
+
data.tar.gz: 880550994778371e8dbd416691bc252a51de37123557ee73ad4c4ac5dcdb273a2a29084787c311b7219629cf42ac782302e664a495e5870deb69e4a6a8323730
|
data/Gemfile.lock
CHANGED
data/lib/activecube.rb
CHANGED
@@ -18,7 +18,7 @@ module Activecube
|
|
18
18
|
|
19
19
|
end
|
20
20
|
|
21
|
-
attr_reader :dimensions, :metrics, :selectors, :models
|
21
|
+
attr_reader :dimensions, :metrics, :selectors, :models, :options
|
22
22
|
|
23
23
|
def inspect
|
24
24
|
name +
|
@@ -46,6 +46,10 @@ module Activecube
|
|
46
46
|
store_definition_array! 'model', (@models ||= []), [*args].flatten.map{|t| t }
|
47
47
|
end
|
48
48
|
|
49
|
+
def option *args
|
50
|
+
store_definition_array! 'option', (@options ||= []), [*args].flatten.map{|t| t }
|
51
|
+
end
|
52
|
+
|
49
53
|
def dim_column column_name
|
50
54
|
Class.new(Activecube::Dimension) do
|
51
55
|
column column_name
|
@@ -7,13 +7,13 @@ require 'activecube/query/measure_nothing'
|
|
7
7
|
module Activecube::Processor
|
8
8
|
class Composer
|
9
9
|
|
10
|
-
attr_reader :cube_query, :models
|
10
|
+
attr_reader :cube_query, :models, :query
|
11
11
|
def initialize cube_query
|
12
12
|
@cube_query = cube_query
|
13
13
|
end
|
14
14
|
|
15
15
|
def build_query
|
16
|
-
compose_queries optimize! ranked_tables
|
16
|
+
@query = compose_queries optimize! ranked_tables
|
17
17
|
end
|
18
18
|
|
19
19
|
def connection
|
@@ -3,6 +3,7 @@ require 'activecube/query/item'
|
|
3
3
|
require 'activecube/query/limit'
|
4
4
|
require 'activecube/query/measure'
|
5
5
|
require 'activecube/query/ordering'
|
6
|
+
require 'activecube/query/option'
|
6
7
|
require 'activecube/query/selector'
|
7
8
|
require 'activecube/query/slice'
|
8
9
|
|
@@ -13,29 +14,44 @@ module Activecube::Query
|
|
13
14
|
|
14
15
|
include ChainAppender
|
15
16
|
|
16
|
-
attr_reader :cube, :slices, :measures, :selectors, :options, :tables
|
17
|
+
attr_reader :cube, :slices, :measures, :selectors, :options, :tables, :sql
|
17
18
|
def initialize cube, slices = [], measures = [], selectors = [], options = [], model_tables = nil
|
18
19
|
@cube = cube
|
19
20
|
@slices = slices
|
20
21
|
@measures = measures
|
21
22
|
@selectors = selectors
|
22
23
|
@options = options
|
23
|
-
|
24
|
+
|
25
|
+
@tables = model_tables || cube.models.map{|m|
|
26
|
+
m < Activecube::View ? m.new : Activecube::Processor::Table.new(m)
|
27
|
+
}
|
28
|
+
|
29
|
+
cube.options && cube.options.each do |option|
|
30
|
+
define_singleton_method option.to_s.underscore do |*args|
|
31
|
+
@options << Option.new(option, *args)
|
32
|
+
self
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
24
36
|
end
|
25
37
|
|
26
38
|
def slice *args
|
39
|
+
clear_sql
|
27
40
|
append *args, @slices, Slice, cube.dimensions
|
28
41
|
end
|
29
42
|
|
30
43
|
def measure *args
|
44
|
+
clear_sql
|
31
45
|
append *args, @measures, Measure, cube.metrics
|
32
46
|
end
|
33
47
|
|
34
48
|
def when *args
|
49
|
+
clear_sql
|
35
50
|
append *args, @selectors, Selector, cube.selectors
|
36
51
|
end
|
37
52
|
|
38
53
|
def desc *args
|
54
|
+
clear_sql
|
39
55
|
args.each{|arg|
|
40
56
|
options << Ordering.new(arg, :desc)
|
41
57
|
}
|
@@ -43,6 +59,7 @@ module Activecube::Query
|
|
43
59
|
end
|
44
60
|
|
45
61
|
def asc *args
|
62
|
+
clear_sql
|
46
63
|
args.each{|arg|
|
47
64
|
options << Ordering.new( arg, :asc)
|
48
65
|
}
|
@@ -50,6 +67,7 @@ module Activecube::Query
|
|
50
67
|
end
|
51
68
|
|
52
69
|
def offset *args
|
70
|
+
clear_sql
|
53
71
|
args.each{|arg|
|
54
72
|
options << Limit.new( arg, :skip)
|
55
73
|
}
|
@@ -57,6 +75,7 @@ module Activecube::Query
|
|
57
75
|
end
|
58
76
|
|
59
77
|
def limit *args
|
78
|
+
clear_sql
|
60
79
|
args.each{|arg|
|
61
80
|
options << Limit.new( arg, :take)
|
62
81
|
}
|
@@ -65,13 +84,12 @@ module Activecube::Query
|
|
65
84
|
|
66
85
|
|
67
86
|
def query
|
68
|
-
|
69
|
-
|
70
|
-
composer.connection.exec_query(sql)
|
87
|
+
sql = to_query.to_sql
|
88
|
+
@composed.connection.exec_query(sql)
|
71
89
|
end
|
72
90
|
|
73
91
|
def to_query
|
74
|
-
Activecube::Processor::Composer.new(self).build_query
|
92
|
+
@composed.try(:query) || (@composed = Activecube::Processor::Composer.new(self)).build_query
|
75
93
|
end
|
76
94
|
|
77
95
|
def to_sql
|
@@ -124,5 +142,10 @@ module Activecube::Query
|
|
124
142
|
options.select{|s| s.kind_of? Ordering}
|
125
143
|
end
|
126
144
|
|
145
|
+
private
|
146
|
+
|
147
|
+
def clear_sql
|
148
|
+
@composed = nil
|
149
|
+
end
|
127
150
|
end
|
128
151
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Activecube
|
2
|
+
module Query
|
3
|
+
class Option
|
4
|
+
|
5
|
+
attr_reader :argument, :value
|
6
|
+
def initialize argument, value
|
7
|
+
@argument = argument
|
8
|
+
@value = value
|
9
|
+
end
|
10
|
+
|
11
|
+
def append_query _model, _cube_query, _table, query
|
12
|
+
query
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -20,13 +20,13 @@ module Activecube::Query
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def to_s
|
23
|
-
"Selector
|
23
|
+
"Selector #{operator.operation}(#{@selectors.map(&:to_s).join(',')})"
|
24
24
|
end
|
25
25
|
|
26
26
|
def expression model, arel_table, cube_query
|
27
27
|
expr = nil
|
28
28
|
@selectors.each do |s|
|
29
|
-
expr = expr ? expr.send(
|
29
|
+
expr = expr ? expr.send( operator.operation, s.expression(model, arel_table, cube_query)) : s.expression(model, arel_table, cube_query)
|
30
30
|
end
|
31
31
|
expr
|
32
32
|
end
|
@@ -137,11 +137,11 @@ module Activecube::Query
|
|
137
137
|
end
|
138
138
|
|
139
139
|
def self.or(selectors)
|
140
|
-
CombineSelector.new(selectors, :or)
|
140
|
+
CombineSelector.new(selectors, Operator.new(:or, nil) )
|
141
141
|
end
|
142
142
|
|
143
143
|
def self.and(selectors)
|
144
|
-
CombineSelector.new(selectors, :and)
|
144
|
+
CombineSelector.new(selectors, Operator.new(:and, nil))
|
145
145
|
end
|
146
146
|
|
147
147
|
end
|
@@ -24,9 +24,12 @@ module Activecube
|
|
24
24
|
|
25
25
|
|
26
26
|
def super_model
|
27
|
-
raise Activecube::InputArgumentError, "No tables specified for cube #{name}"
|
27
|
+
raise Activecube::InputArgumentError, "No tables specified for cube #{name}" unless models && models.count>0
|
28
28
|
|
29
|
-
|
29
|
+
|
30
|
+
models.collect{|m|
|
31
|
+
m < View ? m.models : m
|
32
|
+
}.flatten.uniq.collect{ |t|
|
30
33
|
t.ancestors.select{|c| c < ActiveRecord::Base }
|
31
34
|
}.transpose.select{|c|
|
32
35
|
c.uniq.count==1
|
data/lib/activecube/version.rb
CHANGED
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'activecube/view_definition'
|
2
|
+
require 'activecube/view_connection'
|
3
|
+
|
4
|
+
module Activecube
|
5
|
+
class View
|
6
|
+
extend ViewDefinition
|
7
|
+
extend ViewConnection
|
8
|
+
|
9
|
+
def model
|
10
|
+
self.class
|
11
|
+
end
|
12
|
+
|
13
|
+
def name
|
14
|
+
model.name
|
15
|
+
end
|
16
|
+
|
17
|
+
def matches? query, _measures = query.measures
|
18
|
+
true
|
19
|
+
end
|
20
|
+
|
21
|
+
def measures? measure
|
22
|
+
true
|
23
|
+
end
|
24
|
+
|
25
|
+
def query _cube_query
|
26
|
+
raise "query method have to be implemented in #{name}"
|
27
|
+
end
|
28
|
+
|
29
|
+
def join _cube_query, _left_query, _right_query
|
30
|
+
raise "join method have to be implemented in #{name}"
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'active_support/concern'
|
2
|
+
|
3
|
+
module Activecube::ViewDefinition
|
4
|
+
|
5
|
+
attr_reader :activecube_indexes, :models
|
6
|
+
|
7
|
+
def index index_name, *args
|
8
|
+
(@activecube_indexes ||= []) << Activecube::Processor::Index.new(index_name,*args)
|
9
|
+
end
|
10
|
+
|
11
|
+
def table x
|
12
|
+
(@models ||= []) << x
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activecube
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.24
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aleksey Studnev
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-06-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -111,12 +111,16 @@ files:
|
|
111
111
|
- lib/activecube/query/measure.rb
|
112
112
|
- lib/activecube/query/measure_nothing.rb
|
113
113
|
- lib/activecube/query/modification.rb
|
114
|
+
- lib/activecube/query/option.rb
|
114
115
|
- lib/activecube/query/ordering.rb
|
115
116
|
- lib/activecube/query/selector.rb
|
116
117
|
- lib/activecube/query/slice.rb
|
117
118
|
- lib/activecube/query_methods.rb
|
118
119
|
- lib/activecube/selector.rb
|
119
120
|
- lib/activecube/version.rb
|
121
|
+
- lib/activecube/view.rb
|
122
|
+
- lib/activecube/view_connection.rb
|
123
|
+
- lib/activecube/view_definition.rb
|
120
124
|
homepage: https://github.com/bitquery/activecube
|
121
125
|
licenses:
|
122
126
|
- MIT
|