activecube 0.1.17 → 0.1.25
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 +3 -3
- data/lib/activecube/processor/optimizer.rb +4 -4
- data/lib/activecube/query/cube_query.rb +29 -6
- data/lib/activecube/query/option.rb +17 -0
- 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: 94f1e4575a041108004194789f85b9c030c6f7f94083677dee253de3cc878966
|
4
|
+
data.tar.gz: b182640a584166cefc17b7b26e7add652600b0c937f08b83689a02f819bb2bb9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ab68fd59fdbffe5e0b3d4b8f0523d351b5a6c2840090328af0e78ed10c7fc23e402335f99f05d114da175c57d0b12f0d4fa02195a89ab52108af451b2dae0445
|
7
|
+
data.tar.gz: ace9d8f215cb59e930cf66249211405408c2bce905166fbe59370708dea17502d40d2416611297a1d6c06d0f6930ee3e73460775cfe1ad32895030db22a49c65
|
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
|
@@ -41,7 +41,7 @@ module Activecube::Processor
|
|
41
41
|
end
|
42
42
|
after = total_cost measure_tables
|
43
43
|
|
44
|
-
raise "Optimizer made it
|
44
|
+
raise "Optimizer made it worse #{before} -> #{after} for #{cost_matrix}" unless after <= before
|
45
45
|
measure_tables
|
46
46
|
|
47
47
|
end
|
@@ -27,8 +27,8 @@ module Activecube::Processor
|
|
27
27
|
|
28
28
|
private
|
29
29
|
|
30
|
-
|
31
30
|
def do_optimize
|
31
|
+
|
32
32
|
@tables_by_metrics = []
|
33
33
|
|
34
34
|
# sort metrics from low min cost to higher min costs ( by all applicable tables )
|
@@ -91,13 +91,13 @@ module Activecube::Processor
|
|
91
91
|
else
|
92
92
|
# table to unused table if
|
93
93
|
# cost now > new cost + max other cost in table now
|
94
|
-
old_cost > new_cost + ( prev_step.select.with_index{|c,i| c==c_i && i!=m_i }.max || UNLIM_COST )
|
94
|
+
old_cost > new_cost + ( prev_step.select.with_index{|c,i| c==c_i && i!=m_i }.map{|c| cost_matrix[m_i][c]}.max || UNLIM_COST )
|
95
95
|
end
|
96
96
|
else
|
97
97
|
if new_table_included_times>0
|
98
98
|
# unused table to table if
|
99
99
|
# new cost < cost now + max other cost in new table
|
100
|
-
old_cost > new_cost - ( prev_step.select{|c| c==c_n }.max || UNLIM_COST )
|
100
|
+
old_cost > new_cost - ( prev_step.select{|c| c==c_n }.map{|c| cost_matrix[m_i][c]}.max || UNLIM_COST )
|
101
101
|
else
|
102
102
|
# unused to unused
|
103
103
|
# cost now > new cost
|
@@ -107,7 +107,7 @@ module Activecube::Processor
|
|
107
107
|
|
108
108
|
}
|
109
109
|
|
110
|
-
step <<
|
110
|
+
step << (new_c_i || c_i)
|
111
111
|
|
112
112
|
}
|
113
113
|
|
@@ -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
|
@@ -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.25
|
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-07-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
|